# `PhoenixReplay.Catalog`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/catalog.ex#L1)

Reads and deletes recordings across the live buffer and storage.

A recording is in exactly one place: `PhoenixReplay.Session.Buffer`
while its session runs and until it is saved, storage afterwards.
Changes are broadcast on `PhoenixReplay.PubSub` so the dashboard can
refresh without polling.

Stored recordings were redacted when they were saved. Sessions still in
the buffer are redacted here, with their session's `PhoenixReplay.Redactor`,
so everything read through this module shows the same values.

# `activity`

```elixir
@type activity() :: %{
  from: integer(),
  to: integer(),
  size: pos_integer(),
  buckets: [PhoenixReplay.Recording.Filter.bucket() | {integer(), 0, 0}]
}
```

How many sessions started in each stretch of a time range, for a chart:
`buckets` are `{start, sessions, with_errors}`, every `size`
milliseconds from `from` to `to`, empty ones included.

# `activity`

```elixir
@spec activity(
  PhoenixReplay.Config.t(),
  PhoenixReplay.Recording.Filter.t(),
  keyword()
) :: activity()
```

Counts the buffered and stored sessions matching `filter` by when they
started, over the stretch of time it covers; see
`PhoenixReplay.Recording.Filter.time_range/2`. Takes `:now` and
`:allow` as `query/3` does, and `:utc_offset`, how far the viewer's
time zone is ahead of UTC in milliseconds, so stretches begin at its
midnights and hours.

# `broadcast_change`

```elixir
@spec broadcast_change() :: :ok
```

Notifies subscribers that the set of recordings changed.

# `clear`

```elixir
@spec clear(PhoenixReplay.Config.t()) :: :ok | {:error, term()}
```

Deletes every stored recording.

# `delete`

```elixir
@spec delete(PhoenixReplay.Config.t(), PhoenixReplay.Recording.id()) ::
  :ok | {:error, term()}
```

Deletes a stored recording.

# `fetch`

```elixir
@spec fetch(PhoenixReplay.Config.t(), PhoenixReplay.Recording.id(), keyword()) ::
  {:ok, PhoenixReplay.Recording.t()} | {:error, term()}
```

Fetches a recording from the buffer or storage.

A buffered session is redacted first, which can take a while with a
detecting `PhoenixReplay.Redactor`. Pass `progress: fun` to be called
with the number of events redacted so far and the total.

# `list`

```elixir
@spec list(PhoenixReplay.Config.t()) :: [PhoenixReplay.Recording.Summary.t()]
```

Lists buffered then stored recordings, each most recent first.

# `live`

```elixir
@spec live(PhoenixReplay.Recording.Filter.t(), integer()) :: [
  PhoenixReplay.Recording.Summary.t()
]
```

Summaries of the sessions still recording that match `filter`, most recent first.

# `live?`

```elixir
@spec live?(PhoenixReplay.Recording.id()) :: boolean()
```

Returns true while the session `id` is in the buffer and has not been saved.

# `query`

```elixir
@spec query(PhoenixReplay.Config.t(), PhoenixReplay.Recording.Filter.t(), keyword()) ::
  {[PhoenixReplay.Recording.Summary.t()], non_neg_integer()}
```

Reads a page of stored recordings matching `filter`, most recent first,
and counts every match. See `t:PhoenixReplay.Recording.Filter.page_opts/0`.

Storage pages the recordings itself, unless `:allow` is given: a function
that decides which summaries the reader may see. Every summary is then
read and checked, so the count stays exact.

# `subscribe`

```elixir
@spec subscribe() :: :ok | {:error, term()}
```

Subscribes the caller to `:recordings_changed` messages.

# `values`

```elixir
@spec values(
  PhoenixReplay.Config.t(),
  PhoenixReplay.Recording.Filter.field(),
  PhoenixReplay.Recording.Filter.t(),
  keyword()
) :: [{String.t(), pos_integer()}]
```

The values of a filter's `field` among buffered and stored recordings
matching the rest of `filter`, with how many recordings have each, the
most common first, for suggesting filter values. Takes `:now`, `:limit`
and `:allow` as `query/3` does.

---

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