Skip to main content

Module loader

Module loader 

Source
Expand description

§Page Loader

Runtime file-loading pipeline for v2 JSON-UI specs (Phase 119).

This module exposes load_cached, a cache-aware loader that:

  1. Canonicalizes the input path (fs::canonicalize) — used as the cache key.
  2. Reads the file contents (fs::read_to_string).
  3. Parses into a Spec via Spec::from_json (structural validation).
  4. Validates against global_catalog().validate(&spec) (component + envelope).
  5. Inserts (Arc<Spec>, mtime) into a process-level OnceLock<RwLock<HashMap>>.

In production (reload_if_changed = false), entries are never evicted after first load. In development (reload_if_changed = true), each request performs a single fs::metadata(path).modified() syscall — if the mtime has advanced past the cached mtime, the entry is reloaded. No background thread, no notify crate (119-CONTEXT D-03).

Errors are returned as LoadError with three variants: Io (read or canonicalize), Parse (structural), Catalog (component schema).

The cache follows the same OnceLock<RwLock<...>> pattern used by crate::catalog::global_catalog and crate::layout::global_registry.

Enums§

LoadError
Errors returned by load_cached and related loader entry points.

Functions§

load_cached
Load a spec from path, using the process-level cache.