pub struct Store<'w> { /* private fields */ }Expand description
File store for one project, rooted at one environment’s tree.
Implementations§
Source§impl<'w> Store<'w>
impl<'w> Store<'w>
pub fn new(project: &'w Project, env: &str) -> Self
pub fn project(&self) -> &Project
pub fn env(&self) -> &str
Sourcepub fn envs_of(project: &Project) -> Vec<String>
pub fn envs_of(project: &Project) -> Vec<String>
List the environments a project participates in: the sorted names of
<project>/envs/* subdirectories. A project with no env dirs yet
participates in none (scaffold/adopt/pull materializes them lazily).
Sourcepub fn path_for(&self, r: &ResourceRef) -> PathBuf
pub fn path_for(&self, r: &ResourceRef) -> PathBuf
Absolute path for a NEW resource file (used on create — the physical
name becomes the filename). Existing resources may live at a
different path when their file stem diverged from the physical name;
use Store::locate to find those.
Sourcepub fn locate(&self, r: &ResourceRef) -> Result<Option<PathBuf>, StoreError>
pub fn locate(&self, r: &ResourceRef) -> Result<Option<PathBuf>, StoreError>
Find the file in this store whose physical name (name field, or the
file stem when absent) equals r.name. Scans the kind directory —
small dirs, correctness over micro-optimization.
Sourcepub fn list(&self) -> Result<Vec<(ResourceRef, PathBuf)>, StoreError>
pub fn list(&self) -> Result<Vec<(ResourceRef, PathBuf)>, StoreError>
Scan this store’s environment tree for resource files, keyed by
PHYSICAL name (the file’s name field, falling back to its stem).
A file with invalid JSON is a HARD error (deliberately): sync operations (push/pull/prune/ownership checks) build their world view from this listing, and silently skipping a broken file would let them act on a partial view — e.g. pruning a resource that still exists locally. Fail loud and name the file instead.
Sourcepub fn read(&self, r: &ResourceRef) -> Result<Value, StoreError>
pub fn read(&self, r: &ResourceRef) -> Result<Value, StoreError>
Read a resource file with sidecars inlined. Locates the file by
physical name; when nothing matches, the error keeps the plain Io
not-found shape callers expect (pointing at the stem-guessed path).
It never falls through to reading a file whose physical name differs
from r.name (a renamed resource occupying the stem).
Sourcepub fn read_path(&self, path: &Path) -> Result<Value, StoreError>
pub fn read_path(&self, path: &Path) -> Result<Value, StoreError>
Read any resource file (must belong to this project) with sidecars inlined.
Sourcepub fn write(&self, r: &ResourceRef, value: &Value) -> Result<bool, StoreError>
pub fn write(&self, r: &ResourceRef, value: &Value) -> Result<bool, StoreError>
Write a resource: normalize for disk, extract sidecars, write only if the semantic content changed. Returns true if the file was (re)written.
Updates the located file when one exists (by physical name). When
none exists (create), the target stem is DISAMBIGUATED, never stolen:
if <name>.json is already occupied by a renamed resource, the new
file lands at <name>-2.json (then -3, …). This keeps sync
operations (pull/adopt capture cloud reality mid-run) robust instead
of failing, while locate keeps lookups correct regardless of stem.
Sourcepub fn write_at(
&self,
stem: &str,
kind: ResourceKind,
value: &Value,
) -> Result<bool, StoreError>
pub fn write_at( &self, stem: &str, kind: ResourceKind, value: &Value, ) -> Result<bool, StoreError>
Write a resource at an explicit STEM rather than its physical name —
used by rigg promote when creating a resource in the target
environment that has no counterpart there yet: the new file must land
at the SOURCE environment’s stem (its logical/correlation id) so the
two trees keep correlating by path, even when the resource’s physical
name differs from that stem (a renamed resource in the source env).
Unlike Store::write (which locates-or-creates by physical name),
this never disambiguates: if <stem>.json already exists and holds a
DIFFERENT physical name than value, that’s a genuine collision (some
other resource already occupies this stem) and it errors rather than
overwriting or guessing a new path. When the existing file’s physical
name matches, it behaves like write (update in place, same
x-rigg-*/write-only carry-over and semantic-no-op short circuit).
Sourcepub fn delete(&self, r: &ResourceRef) -> Result<(), StoreError>
pub fn delete(&self, r: &ResourceRef) -> Result<(), StoreError>
Delete a resource file (and its default sidecars). Only ever removes
the file locate resolves for this physical name — deleting a name
that matches nothing is a no-op (never falls through to a stem-guessed
path that could belong to a renamed resource).