107 lines
2.1 KiB
Rust
107 lines
2.1 KiB
Rust
use serde::Deserialize;
|
|
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
|
|
|
|
mod post;
|
|
pub use post::*;
|
|
|
|
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>,
|
|
|
|
/// How to post-process this field
|
|
#[serde(default)]
|
|
pub post: Vec<FieldSpecPost>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
#[serde(tag = "type")]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum Source {
|
|
/// A directory files
|
|
Filesystem {
|
|
/// The directories to scan.
|
|
/// Must be relative.
|
|
#[serde(alias = "paths")]
|
|
path: OneOrMany<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,
|
|
},
|
|
}
|
|
|
|
//
|
|
// 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: OneOrMany<ObjectPath>,
|
|
|
|
/// How to post-process this field
|
|
#[serde(default)]
|
|
pub post: Vec<FieldSpecPost>,
|
|
}
|
|
|
|
#[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,
|
|
}
|