reduct-base 1.19.8

Base crate for ReductStore
Documentation
use std::collections::HashMap;
// Copyright 2021-2026 ReductSoftware UG
// Licensed under the Apache License, Version 2.0
use crate::msg::status::ResourceStatus;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Stats of entry
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct EntryInfo {
    /// Entry name
    pub name: String,
    /// Size of entry in bytes
    pub size: u64,
    /// Number of records in entry
    pub record_count: u64,
    /// Number of blocks in entry
    pub block_count: u64,
    /// Oldest record in entry
    pub oldest_record: u64,
    /// Latest record in entry
    pub latest_record: u64,
    /// Status of the entry
    #[serde(default)]
    pub status: ResourceStatus,
}

/// Query Info
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct QueryInfo {
    /// Unique query name
    pub id: u64,
}

/// Remove Query Info
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct RemoveQueryInfo {
    /// Unique query name
    pub removed_records: u64,
}

/// Rename Entry
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct RenameEntry {
    /// New entry name
    pub new_name: String,
}

#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub enum QueryType {
    /// Query records in entry
    #[default]
    #[serde(rename = "QUERY")]
    Query = 0,
    /// Remove records in entry
    #[serde(rename = "REMOVE")]
    Remove = 1,
}

/// Query records in entry
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
pub struct QueryEntry {
    pub query_type: QueryType,

    /// Specific entries to query (used for Batch Protocol v2)
    pub entries: Option<Vec<String>>,

    /// Start query from (Unix timestamp in microseconds)
    pub start: Option<u64>,
    /// Stop query at (Unix timestamp in microseconds)
    pub stop: Option<u64>,

    /// Include records with label
    pub include: Option<HashMap<String, String>>,
    /// Exclude records with label
    pub exclude: Option<HashMap<String, String>>,
    /// Return a record every S seconds
    pub each_s: Option<f64>,
    /// Return a record every N records
    pub each_n: Option<u64>,
    /// Limit the number of records returned
    pub limit: Option<u64>,

    /// TTL of query in seconds
    pub ttl: Option<u64>,
    /// Retrieve only metadata
    pub only_metadata: Option<bool>,
    /// Continuous query, it doesn't stop until the TTL is reached
    pub continuous: Option<bool>,

    /// Conditional query
    pub when: Option<Value>,
    /// Strict conditional query
    /// If true, the query returns an error if any condition cannot be evaluated
    pub strict: Option<bool>,
    /// Extension
    /// use nested objects to pass additional information to extensions
    ///
    /// Example:
    /// ```json
    /// {
    ///    "ext": {
    ///         "img_ext": {
    ///            "scale_width": 100,
    ///           "scale_height": 100
    ///       }
    ///  }
    pub ext: Option<Value>,
}