#![forbid(unsafe_code)]
#[cfg(feature = "fixture-wire")]
pub mod fixture_wire;
#[cfg(feature = "host")]
pub mod host;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ConsolePage {
pub page: DisplayPage,
pub examined: u32,
pub fetched: u32,
pub output_bytes: u32,
}
#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
pub struct PayloadFilters {
pub minimum: Option<Vec<u8>>,
pub maximum: Option<Vec<u8>>,
pub prefix: Option<Vec<u8>>,
pub suffix: Option<Vec<u8>>,
pub contains: Option<Vec<u8>>,
}
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "console", derive(clap::Args))]
pub struct EntityFilters {
#[cfg_attr(feature = "console", arg(long = "min"))]
pub minimum: Option<u64>,
#[cfg_attr(feature = "console", arg(long))]
pub category: Option<u64>,
#[cfg_attr(feature = "console", arg(long))]
pub entry_id: Option<u64>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryRequest {
pub entity: String,
pub cursor: Option<Vec<u8>>,
pub limit: u32,
pub entity_filters: EntityFilters,
pub order: Vec<String>,
pub descending: bool,
pub work: u32,
pub bytes: u32,
pub select: String,
pub options: QueryOptions,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryOptions {
pub distinct: bool,
pub group_bounds: (Option<String>, Option<String>),
pub group_order: Option<String>,
pub filters: RowFilters,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Status {
pub schema: [u8; 32],
pub incarnation: [u8; 16],
pub revision: u64,
pub pages: u64,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SchemaResponse {
pub status: Status,
pub entities: Vec<EntityView>,
pub types: Vec<TypeView>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct EntityView {
pub name: String,
pub id: u32,
pub primary: String,
pub fields: Vec<FieldView>,
pub indexes: Vec<IndexView>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct FieldView {
pub name: String,
pub kind: String,
pub optional: bool,
pub info: String,
pub reference: Option<(String, String)>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct IndexView {
pub name: String,
pub fields: Vec<String>,
pub unique: bool,
pub present_only: bool,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct TypeView {
pub name: String,
pub kind: String,
pub members: Vec<TypeMemberView>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct TypeMemberView {
pub name: String,
#[serde(rename = "type")]
pub kind: String,
pub optional: bool,
pub info: String,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
pub enum FilterComparison {
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
StartsWith,
EndsWith,
Contains,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct ComparisonFilter<T> {
pub field: String,
pub op: FilterComparison,
pub operand: T,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct FieldRange {
pub field: String,
pub lower: String,
pub upper: String,
}
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct RowFilters {
pub payload: PayloadFilters,
pub compare: Option<ComparisonFilter<String>>,
pub length: Option<ComparisonFilter<u32>>,
pub present: Option<String>,
pub absent: Option<String>,
pub text: Option<ComparisonFilter<String>>,
pub boolean: Option<(String, bool)>,
pub between_fields: Option<FieldRange>,
pub not_between_fields: Option<FieldRange>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct RetainedSelection {
pub entity: String,
pub select: String,
pub entity_filters: EntityFilters,
pub limit: u32,
pub group_bounds: (Option<String>, Option<String>),
pub group_order: Option<String>,
pub filters: RowFilters,
pub order: (Vec<String>, bool),
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct RetainedResume {
pub selection: RetainedSelection,
pub handle: Vec<u8>,
pub sequence: u64,
pub work: u32,
pub bytes: u32,
pub page_size: u32,
pub after: Option<Vec<u8>>,
}
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct DisplayPage {
pub columns: Vec<String>,
pub rows: Vec<Vec<String>>,
pub next: Option<Vec<u8>>,
}
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct RetainedProgress {
pub sequence: u64,
pub examined: u64,
pub input_bytes: u64,
pub output_bytes: u64,
pub phase: RetainedPhase,
}
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum RetainedPhase {
Running,
Complete(DisplayPage),
Invalidated,
Expired,
}
impl RetainedPhase {
#[must_use]
pub const fn label(&self) -> &'static str {
match self {
Self::Running => "Running",
Self::Complete(_) => "Complete",
Self::Invalidated => "Invalidated",
Self::Expired => "Expired",
}
}
}
#[must_use]
pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
const DIGITS: &[u8; 16] = b"0123456789abcdef";
let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
output.push_str(prefix);
for &byte in bytes {
output.push(char::from(DIGITS[usize::from(byte >> 4)]));
output.push(char::from(DIGITS[usize::from(byte & 15)]));
}
output
}