# `AshBackendDrivenOptimisticUi.Snapshot`
[🔗](https://github.com/Undeadlol1/ash_backend_driven_optimistic_ui/blob/v0.1.0/lib/ash_backend_driven_optimistic_ui/snapshot.ex#L1)

The committed copy of every rule, one pretty-printed JSON file per
rule at `<dir>/<type>.<action>.json`, keys sorted so a diff shows only real
changes. `AshBackendDrivenOptimisticUi.Test` compares against it, `mix optimistic_ui.snapshot`
rewrites it.

# `dir`

```elixir
@spec dir(keyword()) :: Path.t()
```

The snapshot directory: the `:snapshot_dir` option, else `test/optimistic_ui/__snapshots__`.

# `drift`

```elixir
@spec drift(%{required(String.t()) =&gt; term()}, Path.t()) :: %{
  missing: [String.t()],
  changed: [String.t()],
  stale: [String.t()]
}
```

How `dir` differs from `rules`: rules without a file, files whose content differs, files without a rule.

# `keys_on_disk`

```elixir
@spec keys_on_disk(Path.t()) :: [String.t()]
```

The rule keys that have a file in `dir`, sorted.

# `path`

```elixir
@spec path(Path.t(), String.t()) :: Path.t()
```

The file holding rule `key` (`"<type>.<action>"`) in `dir`.

# `render`

```elixir
@spec render(term()) :: String.t()
```

The file content for `rule`: key-sorted pretty JSON with a trailing newline.

# `write`

```elixir
@spec write(%{required(String.t()) =&gt; term()}, Path.t()) :: %{
  written: [String.t()],
  removed: [String.t()]
}
```

Writes every rule to `dir` and deletes files with no rule; returns the keys written and removed.

---

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