Skip to main content

Module schema

Module schema 

Source
Expand description

Schema inference and validation. infer_schema walks records to discover field types and cardinalities; validate_record checks a record against a schema; schema_to_yaml renders a schema to YAML for persistence.

Structs§

CollectionSchema
Schema for a single collection (a folder + optional filter).
FieldSchema
Schema for a single field.
VaultSchema
Top-level schema file structure.
Violation
A single validation violation.

Constants§

DEFAULT_EXPRS
Recognised values for FieldSchema::default_expr. Any other value is rejected at schema load time. Resolution to a concrete Value happens in resolve_default_expr below; CreateBuilder calls it at the moment a record is created.
SCHEMA_FILENAME
Canonical filename for the persisted schema, relative to the vault root. CLI and MCP both load <vault>/vaultdb-schema.yaml via this constant.

Functions§

infer_schema
Infer a schema from a set of records.
is_valid_date
True if s parses as a calendar date in YYYY-MM-DD form, with the month and day in valid ranges. Does NOT do leap-year validation — 2024-02-30 passes today; a stricter check can come in Phase 8 if the false-negative cost ever materialises.
is_valid_url
True if s parses as an absolute URL (i.e. has a scheme like https, http, mailto, file, …). Relative URLs are rejected on purpose — a vault field declared type: url should be navigable on its own.
is_valid_wikilink
True if s is a syntactically valid wikilink: [[target]], with optional |alias and/or #section. Target must be non-empty and must not contain ]]. Does NOT verify the target exists in the vault — that requires a LinkGraph and is out of scope for v1.
load_schema
Load schema from a file.
resolve_default_expr
Resolve a default_expr keyword to a concrete Value using wall-clock now. Returns SchemaError for unknown keywords (defence-in-depth — load_schema rejects these earlier, but the helper stays safe to call from any code path).
schema_path
Resolve the schema file path for a vault root.
schema_to_yaml
Serialize a schema to YAML string.
validate_record
Validate a record’s fields against a collection schema.
validate_schema_consistency
Cross-collection consistency checks. Runs after validate_schema_defaults at schema load. Rejects schemas where two folder-overlapping collections (one folder is == or an ancestor of the other) declare the same field name in mutually unsatisfiable ways:
validate_schema_defaults
Walk every field in every collection and check that any declared defaults are well-formed. Exposed publicly so consumers that build a VaultSchema in code (not by loading a file) can run the same check.