# `Juggernaut.Store`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/store.ex#L1)

The files Juggernaut keeps under `_build/juggernaut/` (design notes §7).

This is the API the views read from:

  * `Juggernaut.Store.Layout` - the directory, its layout version and its paths;
  * `Juggernaut.Store.Runs` - `write/2`, `load/2` and `list/1` of whole runs;
  * `Juggernaut.Store.History` - the append-only `history/runs.ndjson`;
  * `Juggernaut.Store.Lock` - the checkout lock.

Every JSON file carries `"format"`. Whole-file writes go through `write_atomic/2`
(a temporary file in the same directory, then a rename).

# `read_json`

```elixir
@spec read_json(Path.t()) :: {:ok, term()} | {:error, String.t()}
```

Reads and decodes a JSON file (string keys).

# `root`

```elixir
@spec root(Path.t()) :: Path.t()
```

The store root of the project at `project_root`.

# `write_atomic`

```elixir
@spec write_atomic(Path.t(), iodata(), keyword()) :: :ok | {:error, File.posix()}
```

Writes `contents` to `path` atomically: a temporary file in the same directory, then
`File.rename/2`. Parent directories are created.

With `mode: mode` the temporary file is created empty and given `mode` before
`contents` are written to it, so the contents are never readable with wider
permissions, at the temporary path or the final one (for secrets such as the server's
token).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
