126 lines
2.5 KiB
Rust
126 lines
2.5 KiB
Rust
use serde::Deserialize;
|
|
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
|
|
|
|
mod misc;
|
|
pub use misc::*;
|
|
|
|
use crate::objectpath::ObjectPath;
|
|
|
|
pub mod objectpath;
|
|
|
|
pub static INIT_DB_TOML: &str = include_str!("./config.toml");
|
|
|
|
fn default_true() -> bool {
|
|
true
|
|
}
|
|
|
|
#[test]
|
|
#[expect(clippy::expect_used)]
|
|
fn init_db_toml_valid() {
|
|
toml::from_str::<ConfigToml>(INIT_DB_TOML).expect("INIT_DB_TOML should be valid TOML");
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct ConfigToml {
|
|
pub dataset: DatasetConfig,
|
|
pub schema: HashMap<Label, FieldSpec>,
|
|
pub fts: Option<DatasetFts>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct DatasetConfig {
|
|
/// Must be unique
|
|
pub name: Label,
|
|
|
|
/// Root dir for indices
|
|
pub working_dir: Option<PathBuf>,
|
|
|
|
/// Where to find this field
|
|
pub source: HashMap<Label, Source>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct S3Credentials {
|
|
pub access_key_id: String,
|
|
pub secret_access_key: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
#[serde(tag = "type")]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum Source {
|
|
/// A directory of files
|
|
Filesystem {
|
|
/// If false, ignore this dataset
|
|
#[serde(default = "default_true")]
|
|
enabled: bool,
|
|
|
|
/// The directories to scan.
|
|
/// Must be relative.
|
|
path: PathBuf,
|
|
|
|
/// If true, all toml files are ignored.
|
|
/// Metadata can be added to any file using a {filename}.toml.
|
|
///
|
|
/// If false, toml files are treated as regular files
|
|
/// and sidecar metadata is disabled.
|
|
#[serde(default = "default_true")]
|
|
sidecars: bool,
|
|
},
|
|
|
|
/// An S3-compatible object store bucket
|
|
S3 {
|
|
/// If false, ignore this dataset
|
|
#[serde(default = "default_true")]
|
|
enabled: bool,
|
|
|
|
bucket: String,
|
|
prefix: Option<String>,
|
|
|
|
/// Custom endpoint URL (for MinIO, etc.)
|
|
endpoint: Option<String>,
|
|
|
|
region: String,
|
|
|
|
credentials: S3Credentials,
|
|
|
|
/// If true, all .toml objects are treated as sidecar metadata files.
|
|
#[serde(default = "default_true")]
|
|
sidecars: bool,
|
|
},
|
|
}
|
|
|
|
//
|
|
// MARK: schema
|
|
//
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct FieldSpec {
|
|
/// The type of this field
|
|
pub r#type: FieldType,
|
|
|
|
/// How to find this field in a data entry
|
|
pub path: Vec<ObjectPath>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum FieldType {
|
|
Text,
|
|
}
|
|
|
|
//
|
|
// MARK: fts
|
|
//
|
|
|
|
#[derive(Debug, Clone, Deserialize, Default)]
|
|
pub struct DatasetFts {
|
|
#[serde(alias = "field")]
|
|
pub fields: HashMap<Label, FtsIndexField>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct FtsIndexField {
|
|
pub tokenize: bool,
|
|
}
|