pub struct SchemaConfig {
pub table: String,
pub title: Option<String>,
pub description: Option<String>,
pub fields: Vec<FieldDef>,
pub dump: Option<DumpConfig>,
}Expand description
The parsed contents of a schema.yaml file.
This struct is the runtime representation of the schema and acts as the
single source of truth for all validation decisions. It is created once at
daemon startup via load_from_path and passed to every CRUD operation.
§Fields
table: the SQLite table name (also used as a human-readable label).title: optional human-readable title for the table (short summary).description: optional long-form description for the table.fields: ordered list of field definitions.dump: optional write-only file-materialization configuration.
Fields§
§table: StringThe logical table name declared in schema.yaml.
title: Option<String>Optional human-readable title for the table (short summary, plain string).
description: Option<String>Optional long-form description for the table. Plain string; CommonMark MAY be used by render tools (server stores it verbatim).
fields: Vec<FieldDef>All field definitions, in declaration order.
dump: Option<DumpConfig>Optional dump / file-materialization configuration.
When absent from schema.yaml, the field deserializes to None and
the dump feature is disabled entirely (backward-compatible default).
Implementations§
Source§impl SchemaConfig
impl SchemaConfig
Sourcepub async fn write_to_path(&self, path: &Path) -> Result<(), MiniAppError>
pub async fn write_to_path(&self, path: &Path) -> Result<(), MiniAppError>
Writes this schema to a YAML file using an atomic tmp+rename strategy.
The write is performed inside tokio::task::spawn_blocking to avoid
blocking the async executor (K-110). The rename is performed with
std::fs::rename, which is atomic on the same filesystem on Linux/macOS
(POSIX rename(2) guarantee).
§Algorithm
- Serialise
selfto a YAML string viaserde_yaml_bw::to_string. - Write to
<path>.tmp(same directory, so same filesystem). - Atomically rename
<path>.tmpto<path>.
§Arguments
path: destination path forschema.yaml(the final file, not.tmp).
§Returns
Ok(()) on success.
§Errors
MiniAppError::Schemaif serialisation fails.MiniAppError::Ioif the write or rename fails.MiniAppError::Backupif thespawn_blockingtask panics.
Sourcepub fn validate(&self, value: &Value) -> Result<(), MiniAppError>
pub fn validate(&self, value: &Value) -> Result<(), MiniAppError>
Validates a JSON object against this schema.
Rules (applied in order, iterating over [self.fields]):
- If
field.requiredistrueand the key is absent fromvalue(or its value isnull), returnMiniAppError::Validationwithreason = "required field missing". - If the key is present and non-null but its JSON type does not match
field.ty, returnMiniAppError::Validationwith a descriptivereason. - Unknown keys (present in
valuebut not inself.fields) are silently accepted — Agent-First extensibility.
§Arguments
value: the JSON object to validate. Must be aserde_json::Value::Object; if it is not, aValidationerror is returned immediately.
§Errors
Returns MiniAppError::Validation on the first validation failure
encountered.
Trait Implementations§
Source§impl Clone for SchemaConfig
impl Clone for SchemaConfig
Source§fn clone(&self) -> SchemaConfig
fn clone(&self) -> SchemaConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more