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: Vec<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 pub member: Option<String>,
249}
250
251#[derive(Debug, serde::Deserialize, serde::Serialize)]
256pub struct IndexView {
257 pub reference: Option<String>,
259 pub name: String,
261 pub fields: Vec<String>,
263 pub unique: bool,
265 pub present_only: bool,
267 pub filter: Option<(String, bool)>,
269}
270
271#[derive(Debug, serde::Deserialize, serde::Serialize)]
276pub struct TypeView {
277 pub name: String,
279 pub kind: String,
281 pub members: Vec<TypeMemberView>,
283}
284
285#[derive(Debug, serde::Deserialize, serde::Serialize)]
290pub struct TypeMemberView {
291 pub name: String,
293 #[serde(rename = "type")]
295 pub kind: String,
296 pub optional: bool,
298 pub info: String,
300}
301
302#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
307#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
308pub enum FilterComparison {
309 Eq,
311 Ne,
313 Lt,
315 Le,
317 Gt,
319 Ge,
321 StartsWith,
323 EndsWith,
325 Contains,
327}
328
329#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
334pub struct ComparisonFilter<T> {
335 pub field: String,
337 pub op: FilterComparison,
339 pub operand: T,
341}
342
343#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
348pub struct FieldRange {
349 pub field: String,
351 pub lower: String,
353 pub upper: String,
355}
356
357#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
359pub struct RowFilters {
360 pub payload: PayloadFilters,
362 pub compare: Option<ComparisonFilter<String>>,
364 pub length: Option<ComparisonFilter<u32>>,
366 pub present: Option<String>,
368 pub absent: Option<String>,
370 pub text: Option<ComparisonFilter<String>>,
372 pub boolean: Option<(String, bool)>,
374 pub between_fields: Option<FieldRange>,
376 pub not_between_fields: Option<FieldRange>,
378}
379
380#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
382pub struct RetainedSelection {
383 pub entity: String,
385 pub select: String,
387 pub entity_filters: EntityFilters,
389 pub limit: u32,
391 pub group_bounds: GroupBounds,
393 pub group_order: Option<FixtureGroupOrder>,
395 pub filters: RowFilters,
397 pub order: (Vec<String>, bool),
399}
400
401#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
403pub struct RetainedResume {
404 pub selection: RetainedSelection,
406 pub handle: Vec<u8>,
408 pub sequence: u64,
410 pub work: u32,
412 pub bytes: u32,
414 pub page_size: u32,
416 pub after: Option<Vec<u8>>,
418}
419
420#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
422pub struct DisplayPage {
423 pub columns: Vec<String>,
425 pub rows: Vec<Vec<String>>,
427 pub next: Option<Vec<u8>>,
429}
430
431#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
433pub struct RetainedProgress {
434 pub sequence: u64,
436 pub examined: u64,
438 pub input_bytes: u64,
440 pub output_bytes: u64,
442 pub phase: RetainedPhase,
444}
445
446#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
448pub enum RetainedPhase {
449 Running,
451 Complete(DisplayPage),
453 Invalidated,
455 Expired,
457}
458
459impl RetainedPhase {
460 #[must_use]
462 pub const fn label(&self) -> &'static str {
463 match self {
464 Self::Running => "Running",
465 Self::Complete(_) => "Complete",
466 Self::Invalidated => "Invalidated",
467 Self::Expired => "Expired",
468 }
469 }
470}
471
472#[must_use]
474pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
475 const DIGITS: &[u8; 16] = b"0123456789abcdef";
476 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
477 output.push_str(prefix);
478 for &byte in bytes {
479 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
480 output.push(char::from(DIGITS[usize::from(byte & 15)]));
481 }
482 output
483}