1#![forbid(unsafe_code)]
3
4pub mod browse;
5#[cfg(feature = "fixture-codec")]
6pub mod fixture_codec;
7#[cfg(feature = "schema-inspection")]
8pub mod inspection;
9#[cfg(feature = "fixture-codec")]
10pub mod relations;
11
12#[cfg(feature = "host")]
13pub mod host;
14
15#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
17pub struct ConsolePage {
18 pub page: DisplayPage,
20 pub examined: u32,
22 pub fetched: u32,
24 pub output_bytes: u32,
26}
27
28#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
30pub struct PayloadFilters {
31 pub minimum: Option<Vec<u8>>,
33 pub maximum: Option<Vec<u8>>,
35 pub prefix: Option<Vec<u8>>,
37 pub suffix: Option<Vec<u8>>,
39 pub contains: Option<Vec<u8>>,
41}
42
43#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
45#[cfg_attr(feature = "console", derive(clap::Args))]
46pub struct EntityFilters {
47 #[cfg_attr(feature = "console", arg(long = "min"))]
49 pub minimum: Option<u64>,
50 #[cfg_attr(feature = "console", arg(long))]
52 pub category: Option<u64>,
53 #[cfg_attr(feature = "console", arg(long))]
55 pub entry_id: Option<u64>,
56}
57
58#[derive(Debug, serde::Deserialize, serde::Serialize)]
60pub struct QueryRequest {
61 pub entity: String,
63 pub cursor: Option<Vec<u8>>,
65 pub limit: u32,
67 pub entity_filters: EntityFilters,
69 pub order: Vec<String>,
71 pub descending: bool,
73 pub work: u32,
75 pub bytes: u32,
77 pub select: String,
79 pub options: QueryOptions,
81}
82
83#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
85#[cfg_attr(feature = "console", derive(clap::Args))]
86pub struct GroupBounds {
87 #[cfg_attr(feature = "console", arg(long, allow_hyphen_values = true))]
93 pub group_min: Option<String>,
94 #[cfg_attr(feature = "console", arg(long, allow_hyphen_values = true))]
97 pub group_max: Option<String>,
98}
99
100#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
102#[serde(from = "u8")]
103pub enum MigrationAction {
104 Seed,
106 Freeze,
108 Copy,
110 Validate,
112 Publish,
114 Cleanup,
116 ReadTarget,
118 ReadSource,
120 Unknown,
122}
123
124impl From<u8> for MigrationAction {
127 fn from(value: u8) -> Self {
128 [
129 Self::Seed,
130 Self::Freeze,
131 Self::Copy,
132 Self::Validate,
133 Self::Publish,
134 Self::Cleanup,
135 Self::ReadTarget,
136 Self::ReadSource,
137 ]
138 .get(usize::from(value))
139 .copied()
140 .unwrap_or(Self::Unknown)
141 }
142}
143
144#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
146#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
147pub enum FixtureGroupOrder {
148 Key,
150 KeyDesc,
152 First,
154 Asc,
156 Desc,
158 #[cfg_attr(feature = "console", value(name = "count:asc"))]
160 CountAsc,
161 #[cfg_attr(feature = "console", value(name = "count:desc"))]
163 CountDesc,
164 #[cfg_attr(feature = "console", value(name = "sum:asc"))]
166 SumAsc,
167 #[cfg_attr(feature = "console", value(name = "sum:desc"))]
169 SumDesc,
170 #[cfg_attr(feature = "console", value(name = "avg:asc"))]
172 AvgAsc,
173 #[cfg_attr(feature = "console", value(name = "avg:desc"))]
175 AvgDesc,
176}
177
178#[derive(Debug, serde::Deserialize, serde::Serialize)]
180pub struct QueryOptions {
181 pub distinct: bool,
183 pub group_bounds: GroupBounds,
185 pub group_order: Option<FixtureGroupOrder>,
187 pub filters: RowFilters,
189}
190
191#[derive(Debug, serde::Deserialize, serde::Serialize)]
193pub struct Status {
194 pub schema: [u8; 32],
196 pub incarnation: [u8; 16],
198 pub revision: u64,
200 pub pages: u64,
202}
203
204#[derive(Debug, serde::Deserialize, serde::Serialize)]
206pub struct SchemaResponse {
207 pub status: Status,
209 pub entities: Vec<EntityView>,
211 pub types: Vec<TypeView>,
213}
214
215#[derive(Debug, serde::Deserialize, serde::Serialize)]
217pub struct EntityView {
218 pub name: String,
220 #[serde(rename = "primary_key")]
222 pub primary: Vec<String>,
223 pub fields: Vec<FieldView>,
225 pub indexes: Vec<IndexView>,
227}
228
229#[derive(Debug, serde::Deserialize, serde::Serialize)]
231pub struct FieldView {
232 pub name: String,
234 #[serde(rename = "type")]
236 pub kind: String,
237 pub optional: bool,
239 pub info: String,
241 pub reference: Option<ReferenceView>,
243}
244
245#[derive(Debug, serde::Deserialize, serde::Serialize)]
247pub struct ReferenceView {
248 pub target_entity: String,
250 pub target_field: String,
252 pub index: Option<String>,
254 pub weak_store: Option<String>,
256 pub member: Option<String>,
258}
259
260#[derive(Debug, serde::Deserialize, serde::Serialize)]
265pub struct IndexView {
266 pub reference: Option<String>,
268 pub name: String,
270 pub fields: Vec<String>,
272 pub unique: bool,
274 pub present_only: bool,
276 pub filter: Option<(String, bool)>,
278}
279
280#[derive(Debug, serde::Deserialize, serde::Serialize)]
285pub struct TypeView {
286 pub name: String,
288 pub kind: String,
290 pub members: Vec<TypeMemberView>,
292}
293
294#[derive(Debug, serde::Deserialize, serde::Serialize)]
299pub struct TypeMemberView {
300 pub name: String,
302 #[serde(rename = "type")]
304 pub kind: String,
305 pub optional: bool,
307 pub info: String,
309}
310
311#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
316#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
317pub enum FilterComparison {
318 Eq,
320 Ne,
322 Lt,
324 Le,
326 Gt,
328 Ge,
330 StartsWith,
332 EndsWith,
334 Contains,
336}
337
338#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
343pub struct ComparisonFilter<T> {
344 pub field: String,
346 pub op: FilterComparison,
348 pub operand: T,
350}
351
352#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
357pub struct FieldRange {
358 pub field: String,
360 pub lower: String,
362 pub upper: String,
364}
365
366#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
368pub struct RowFilters {
369 pub payload: PayloadFilters,
371 pub compare: Option<ComparisonFilter<String>>,
373 pub length: Option<ComparisonFilter<u32>>,
375 pub present: Option<String>,
377 pub absent: Option<String>,
379 pub text: Option<ComparisonFilter<String>>,
381 pub boolean: Option<(String, bool)>,
383 pub between_fields: Option<FieldRange>,
385 pub not_between_fields: Option<FieldRange>,
387}
388
389#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
391pub struct RetainedSelection {
392 pub entity: String,
394 pub select: String,
396 pub entity_filters: EntityFilters,
398 pub limit: u32,
400 pub group_bounds: GroupBounds,
402 pub group_order: Option<FixtureGroupOrder>,
404 pub filters: RowFilters,
406 pub order: (Vec<String>, bool),
408}
409
410#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
412pub struct RetainedResume {
413 pub selection: RetainedSelection,
415 pub handle: Vec<u8>,
417 pub sequence: u64,
419 pub work: u32,
421 pub bytes: u32,
423 pub page_size: u32,
425 pub after: Option<Vec<u8>>,
427}
428
429#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
431pub struct DisplayPage {
432 pub columns: Vec<String>,
434 pub rows: Vec<Vec<String>>,
436 pub next: Option<Vec<u8>>,
438}
439
440#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
442pub struct RetainedProgress {
443 pub sequence: u64,
445 pub examined: u64,
447 pub input_bytes: u64,
449 pub output_bytes: u64,
451 pub phase: RetainedPhase,
453}
454
455#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
457pub enum RetainedPhase {
458 Running,
460 Complete(DisplayPage),
462 Invalidated,
464 Expired,
466}
467
468impl RetainedPhase {
469 #[must_use]
471 pub const fn label(&self) -> &'static str {
472 match self {
473 Self::Running => "Running",
474 Self::Complete(_) => "Complete",
475 Self::Invalidated => "Invalidated",
476 Self::Expired => "Expired",
477 }
478 }
479}
480
481#[must_use]
483pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
484 const DIGITS: &[u8; 16] = b"0123456789abcdef";
485 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
486 output.push_str(prefix);
487 for &byte in bytes {
488 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
489 output.push(char::from(DIGITS[usize::from(byte & 15)]));
490 }
491 output
492}