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(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
97#[serde(from = "u8")]
98pub enum MigrationAction {
99 Seed,
101 Freeze,
103 Copy,
105 Validate,
107 Publish,
109 Cleanup,
111 ReadTarget,
113 ReadSource,
115 Unknown,
117}
118
119impl From<u8> for MigrationAction {
122 fn from(value: u8) -> Self {
123 [
124 Self::Seed,
125 Self::Freeze,
126 Self::Copy,
127 Self::Validate,
128 Self::Publish,
129 Self::Cleanup,
130 Self::ReadTarget,
131 Self::ReadSource,
132 ]
133 .get(usize::from(value))
134 .copied()
135 .unwrap_or(Self::Unknown)
136 }
137}
138
139#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
141#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
142pub enum FixtureGroupOrder {
143 Key,
145 KeyDesc,
147 First,
149 Asc,
151 Desc,
153 #[cfg_attr(feature = "console", value(name = "count:asc"))]
155 CountAsc,
156 #[cfg_attr(feature = "console", value(name = "count:desc"))]
158 CountDesc,
159 #[cfg_attr(feature = "console", value(name = "sum:asc"))]
161 SumAsc,
162 #[cfg_attr(feature = "console", value(name = "sum:desc"))]
164 SumDesc,
165 #[cfg_attr(feature = "console", value(name = "avg:asc"))]
167 AvgAsc,
168 #[cfg_attr(feature = "console", value(name = "avg:desc"))]
170 AvgDesc,
171}
172
173#[derive(Debug, serde::Deserialize, serde::Serialize)]
175pub struct QueryOptions {
176 pub distinct: bool,
178 pub group_bounds: GroupBounds,
180 pub group_order: Option<FixtureGroupOrder>,
182 pub filters: RowFilters,
184}
185
186#[derive(Debug, serde::Deserialize, serde::Serialize)]
188pub struct Status {
189 pub schema: [u8; 32],
191 pub incarnation: [u8; 16],
193 pub revision: u64,
195 pub pages: u64,
197}
198
199#[derive(Debug, serde::Deserialize, serde::Serialize)]
201pub struct SchemaResponse {
202 pub status: Status,
204 pub entities: Vec<EntityView>,
206 pub types: Vec<TypeView>,
208}
209
210#[derive(Debug, serde::Deserialize, serde::Serialize)]
212pub struct EntityView {
213 pub name: String,
215 #[serde(rename = "primary_key")]
217 pub primary: String,
218 pub fields: Vec<FieldView>,
220 pub indexes: Vec<IndexView>,
222}
223
224#[derive(Debug, serde::Deserialize, serde::Serialize)]
226pub struct FieldView {
227 pub name: String,
229 #[serde(rename = "type")]
231 pub kind: String,
232 pub optional: bool,
234 pub info: String,
236 pub reference: Option<ReferenceView>,
238}
239
240#[derive(Debug, serde::Deserialize, serde::Serialize)]
242pub struct ReferenceView {
243 pub target: String,
245 pub index: String,
247}
248
249#[derive(Debug, serde::Deserialize, serde::Serialize)]
254pub struct IndexView {
255 pub name: String,
257 pub fields: Vec<String>,
259 pub unique: bool,
261 pub present_only: bool,
263}
264
265#[derive(Debug, serde::Deserialize, serde::Serialize)]
270pub struct TypeView {
271 pub name: String,
273 pub kind: String,
275 pub members: Vec<TypeMemberView>,
277}
278
279#[derive(Debug, serde::Deserialize, serde::Serialize)]
284pub struct TypeMemberView {
285 pub name: String,
287 #[serde(rename = "type")]
289 pub kind: String,
290 pub optional: bool,
292 pub info: String,
294}
295
296#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
301#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
302pub enum FilterComparison {
303 Eq,
305 Ne,
307 Lt,
309 Le,
311 Gt,
313 Ge,
315 StartsWith,
317 EndsWith,
319 Contains,
321}
322
323#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
328pub struct ComparisonFilter<T> {
329 pub field: String,
331 pub op: FilterComparison,
333 pub operand: T,
335}
336
337#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
342pub struct FieldRange {
343 pub field: String,
345 pub lower: String,
347 pub upper: String,
349}
350
351#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
353pub struct RowFilters {
354 pub payload: PayloadFilters,
356 pub compare: Option<ComparisonFilter<String>>,
358 pub length: Option<ComparisonFilter<u32>>,
360 pub present: Option<String>,
362 pub absent: Option<String>,
364 pub text: Option<ComparisonFilter<String>>,
366 pub boolean: Option<(String, bool)>,
368 pub between_fields: Option<FieldRange>,
370 pub not_between_fields: Option<FieldRange>,
372}
373
374#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
376pub struct RetainedSelection {
377 pub entity: String,
379 pub select: String,
381 pub entity_filters: EntityFilters,
383 pub limit: u32,
385 pub group_bounds: GroupBounds,
387 pub group_order: Option<FixtureGroupOrder>,
389 pub filters: RowFilters,
391 pub order: (Vec<String>, bool),
393}
394
395#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
397pub struct RetainedResume {
398 pub selection: RetainedSelection,
400 pub handle: Vec<u8>,
402 pub sequence: u64,
404 pub work: u32,
406 pub bytes: u32,
408 pub page_size: u32,
410 pub after: Option<Vec<u8>>,
412}
413
414#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
416pub struct DisplayPage {
417 pub columns: Vec<String>,
419 pub rows: Vec<Vec<String>>,
421 pub next: Option<Vec<u8>>,
423}
424
425#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
427pub struct RetainedProgress {
428 pub sequence: u64,
430 pub examined: u64,
432 pub input_bytes: u64,
434 pub output_bytes: u64,
436 pub phase: RetainedPhase,
438}
439
440#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
442pub enum RetainedPhase {
443 Running,
445 Complete(DisplayPage),
447 Invalidated,
449 Expired,
451}
452
453impl RetainedPhase {
454 #[must_use]
456 pub const fn label(&self) -> &'static str {
457 match self {
458 Self::Running => "Running",
459 Self::Complete(_) => "Complete",
460 Self::Invalidated => "Invalidated",
461 Self::Expired => "Expired",
462 }
463 }
464}
465
466#[must_use]
468pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
469 const DIGITS: &[u8; 16] = b"0123456789abcdef";
470 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
471 output.push_str(prefix);
472 for &byte in bytes {
473 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
474 output.push(char::from(DIGITS[usize::from(byte & 15)]));
475 }
476 output
477}