Lockfile
Architecture notes for @ucdjs/lockfile
@ucdjs/lockfile owns the persistent metadata format for mirrored UCD stores.
Role
- Validates
.ucd-store.lockand per-versionsnapshot.jsonfiles. - Encodes the contract between
ucd-store, writable backends, and store-serving apps. - Separates metadata integrity checks from the higher-level store lifecycle.
Related Docs
Public Package Docs
User-facing overview of lockfile helpers and snapshot parsing.
UCD Store
See where lockfile reads, writes, and conflict resolution happen.
FS Backend
Lockfile persistence depends on backend `write` and `mkdir` support.
Store App
The hosted store app serves lockfile and snapshot data over HTTP.
Mental Model
The package has two data shapes:
- lockfile: store-level metadata for resolved versions and filters
- snapshot: version-level file manifest with hashes and sizes
And two usage modes:
- strict parsing APIs that throw typed errors
- permissive
OrUndefinedAPIs for best-effort reads
Method Flows
readLockfile()
writeLockfile()
Snapshot lifecycle
Design Notes
canUseLockfile()is a capability check, not a backend-type check.- Invalid content is normalized into
LockfileInvalidErrorso higher-level code can present consistent errors. - Parsing helpers exist both for filesystem-backed reads and raw string content from HTTP or memory.
- Snapshot paths are version-derived, which keeps store metadata deterministic.
Testing Use
- strict vs permissive parse helpers
- invalid JSON and invalid schema branches
- write skipping on read-only backends
- directory creation on first write
- parity between raw-content parse helpers and filesystem-backed reads