UCD.js Docs

UCD Store

Architecture notes for @ucdjs/ucd-store

@ucdjs/ucd-store is the high-level storage coordination layer for UCD.js.

Role

  • Coordinates file access, mirroring, sync, verification, and reporting.
  • Works across different backend types through @ucdjs/fs-backend.
  • Bridges store metadata, local state, and remote file access behavior.

Notes

Use this page for mode boundaries, metadata authority, and store-lifecycle notes.

Method Flows

The diagrams below focus on the runtime behavior of the main store entrypoints. They are intentionally close to the current implementation so they can be used as both design docs and test-planning references.

createUCDStore()

verify()LockfileFilesystem backendUCD clientEndpoint discoverycreateUCDStore()verify()LockfileFilesystem backendUCD clientEndpoint discoverycreateUCDStore()alt[no endpointConfig and no client]alt[no client provided]alt[user provided versions][no user versions]alt[requireExistingStore][initialize automatically]alt[no versions resolved]alt[writable backend with existing lockfile][writable backend without lockfile][read-only backend]alt[invalid versions]opt[verify enabled and versions resolved]CallercreateUCDStore(options)normalize defaults + build path filterdiscoverEndpointsFromConfig(baseUrl)endpoint config or default configcreateUCDClientWithConfig(...)client instancecreate backend from fs factorydetect lockfile support + pathversions.list() for early validationavailable versionsreadLockfileOrUndefined()lockfile versionshandleVersionConflict(strategy)resolved versionsuse lockfile/config versionsthrow missing lockfile errorinitLockfile()empty/new lockfile writtenresolve versions from input or configthrow read-only backend errorverify(context)validation resultthrow verification errorstore with files/get/list/tree + mirror/sync/analyze/compareCaller

files.get()

UCD client files.get()Filesystem backendPath filterfiles.get()UCD client files.get()Filesystem backendPath filterfiles.get()alt[version missing]alt[filtered out]alt[local read succeeds][local read fails and allowApi is false]alt[local file exists]alt[API error][API returns no data][API succeeds]alt[local file missing or unreadable and allowApi is true][local file missing and allowApi is false]Callerfiles.get(version, filePath, options)validate version is resolvedUCDStoreVersionNotFoundErrormatch global + per-call filtersblockedUCDStoreFilterErrorexists(version/filePath)read(version/filePath)file content{ data, error: null }UCDStoreGenericErrorget(version/ucd/filePath)errorUCDStoreApiFallbackErrornullUCDStoreApiFallbackErrorstring or JSON content{ data, error: null }UCDStoreGenericErrorCaller

mirror()

Lockfile writerSnapshot writerFilesystem backendTree filterUCD clientmirror()Lockfile writerSnapshot writerFilesystem backendTree filterUCD clientmirror()alt[no versions selected]loop[each version]alt[file exists and not force][download file]par[queued files with concurrency limit]loop[each mirrored version]Callermirror({ versions, filters, force, concurrency })validate fs supports mkdir + writeempty MirrorReportversions.getFileTree(version)file treenormalize + filter treefile paths to mirrorqueue directories + filescreate missing directoriesexists(localPath)skipfiles.get(remotePath)file contentswrite(localPath, content)read mirrored fileswriteSnapshot(version, hashes + sizes)snapshot writtenwriteLockfile(updated versions + filters)lockfile updatedMirrorReportCaller

sync()

listFiles()Filesystem backendmirror()LockfileUCD clientsync()listFiles()Filesystem backendmirror()LockfileUCD clientsync()alt[no versions need mirroring][versions need mirroring]alt[snapshot exists][no snapshot]loop[each synced version]opt[cleanOrphaned]Callersync({ versions, force, removeUnavailable, cleanOrphaned })validate fs supports mkdir + writeversions.list()available API versionsreadLockfileOrUndefined()current lockfile statecompute added / removed / unchanged / finalVersionswrite updated lockfilelockfile persistedcompute versionsToSyncSyncResult with empty MirrorReportmirror({ versions: versionsToSync, ... })MirrorReportreadSnapshot(version)versions.getManifest(version)listFiles(version, { allowApi: false })actual local filesremove orphaned filesSyncResultCaller

Testing Use

These sequence diagrams are also the right place to derive scenario matrices:

  • initialization mode matrix: writable, read-only, lockfile present, lockfile absent
  • file read matrix: local hit, filtered, local miss, API fallback success, API fallback failure
  • mirror matrix: empty version set, skips, force re-download, API/tree failure, snapshot update
  • sync matrix: add/remove versions, force mirror, remove unavailable, orphan cleanup

On this page