rlsbl.lib.schema_loader

Load config schema from on-disk declaration files.

Reads .rlsbl/config-schema.json and migration files from .rlsbl/migrations/ to build a schema dict suitable for ConfigMigrator.

Functions

load_schema

def load_schema(base_dir: str | Path) -> dict[str, Any] | None

Load config schema from .rlsbl/config-schema.json and migration files.

.rlsbl/config-schema.json format: { "schema_version_key": "_schema_version", "files": [ { "path": "config.json", "defaults_path": "defaults/config.json", "merge_strategy": "deep_recursive" }, { "path": "segments.json", "defaults_path": "defaults/segments.json", "merge_strategy": "list_by_key", "match_field": "key" } ] }

Migrations live in .rlsbl/migrations/ as numbered Python files:

Each must define: version (int), description (str), apply(configs: dict) -> None

Args: base_dir: Root directory containing .rlsbl/ folder.

Returns: A schema dict ready for ConfigMigrator, or None if no schema file exists.

Raises: SchemaLoadError: If schema file is malformed, defaults are missing, or a migration file lacks required attributes.

_load_file_entries

def _load_file_entries(base_dir: Path, file_declarations: list[dict[str, Any]]) -> list[dict[str, Any]]

Resolve defaults_path references into actual default values.

Each file declaration has a defaults_path relative to base_dir. We load that JSON file and inline the contents as "defaults".

_load_migrations

def _load_migrations(migrations_dir: Path) -> list[dict[str, Any]]

Discover and load migration files from a directory.

Migration files must be named with a numeric prefix (e.g. 001_add_field.py) and define: version (int), description (str), apply(configs) -> None.

_import_migration

def _import_migration(filepath: Path) -> Any

Dynamically import a migration file and validate its exports.

Raises SchemaLoadError if required attributes are missing.

Classes

SchemaLoadError

Raised when a schema or migration file is malformed.