Validate label names

This commit is contained in:
2026-02-21 13:53:30 -08:00
parent 70d9dfc173
commit 8ab4ea53ec
11 changed files with 318 additions and 63 deletions

View File

@@ -1,56 +1,36 @@
use serde::Deserialize;
use std::{collections::HashMap, fmt::Debug, path::PathBuf, slice};
pub static INIT_DB_TOML: &str = include_str!("./config.toml");
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
mod post;
pub use post::*;
mod misc;
pub use misc::*;
pub static INIT_DB_TOML: &str = include_str!("./config.toml");
#[test]
fn init_db_toml_valid() {
toml::from_str::<ConfigToml>(INIT_DB_TOML).unwrap();
}
#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum OneOrMany<T: Debug + Clone> {
One(T),
Many(Vec<T>),
}
impl<T: Debug + Clone> OneOrMany<T> {
pub fn to_vec(self) -> Vec<T> {
match self {
Self::One(x) => vec![x],
Self::Many(x) => x,
}
}
pub fn as_slice(&self) -> &[T] {
match self {
Self::One(x) => slice::from_ref(&x),
Self::Many(x) => &x[..],
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ConfigToml {
pub dataset: DatasetConfig,
pub schema: HashMap<String, FieldSpec>,
pub schema: HashMap<Label, FieldSpec>,
pub fts: Option<DatasetFts>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DatasetConfig {
/// Must be unique
pub name: String,
pub name: Label,
/// Root dir for indices
pub working_dir: Option<PathBuf>,
/// Where to find this field
pub source: HashMap<String, Source>,
pub source: HashMap<Label, Source>,
/// How to post-process this field
#[serde(default)]
@@ -95,7 +75,7 @@ pub enum FieldType {
#[derive(Debug, Clone, Deserialize, Default)]
pub struct DatasetFts {
#[serde(alias = "field")]
pub fields: HashMap<String, FtsIndexField>,
pub fields: HashMap<Label, FtsIndexField>,
}
#[derive(Debug, Clone, Deserialize)]