# `PgRest.Registry.Snapshot`
[🔗](https://github.com/agoodway/pgrest/blob/v0.2.0/lib/pg_rest/registry/snapshot.ex#L1)

The immutable schema cache a `PgRest.Registry` publishes: its resources keyed by
`{schema, table}`, the exposed schemas (the first is the default) and the relationship
graph.

`graph` spans every schema. Embedding follows PostgREST and only reaches tables in the
request's schema, so requests resolve embeds through `graph/2`, the graph restricted to one
schema (precomputed per exposed schema).

`functions` maps `{schema, name}` to its overloads (`PgRest.Function`), declared or
introspected. `introspection` is `nil` without `introspect:`, otherwise what `PgRest.Plug`
cross-checks on every request: `%{mode: :app | :rls, as_role: [String.t()] | nil,
authorization: module() | nil, filtered?: boolean()}` (`filtered?` when `only:` or `except:`
was given).

`generation` is unique per built snapshot, so a reload is a new generation.

`scrub_rpc_details?` is whether any resource is scoped or restricts columns
(`PgRest.Write.scrub_details?/2`): a function may touch any table, so its database errors
then lose their details.

# `introspection`

```elixir
@type introspection() :: %{
  mode: :app | :rls,
  as_role: [String.t()] | nil,
  authorization: module() | nil,
  filtered?: boolean()
}
```

# `t`

```elixir
@type t() :: %PgRest.Registry.Snapshot{
  by_module: %{required(module()) =&gt; map()},
  default_schema: String.t(),
  functions: %{required({String.t(), String.t()}) =&gt; [PgRest.Function.t()]},
  generation: pos_integer(),
  graph: PgRest.SchemaGraph.t(),
  graphs: %{required(String.t()) =&gt; PgRest.SchemaGraph.t()},
  introspection: introspection() | nil,
  name: atom(),
  resources: %{required({String.t(), String.t()}) =&gt; map()},
  schemas: [String.t()],
  scrub_rpc_details?: boolean()
}
```

# `build`

```elixir
@spec build(atom(), [String.t()], [map()], keyword()) :: t()
```

Builds the snapshot of `configs` (resource configs, already validated) exposing `schemas`.
`opts` may carry `functions:` (a list of `PgRest.Function`, grouped here by schema and name)
and `introspection:`.

# `fetch_resource`

```elixir
@spec fetch_resource(t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, PgRest.Error.t()}
```

The resource registered for `schema.table`, or PostgREST's 404 `PGRST205`, with a
"Perhaps you meant" hint naming the closest table of that schema.

# `functions`

```elixir
@spec functions(t(), String.t(), String.t()) :: [PgRest.Function.t()]
```

The overloads of function `schema.name` (empty when none is registered).

# `graph`

```elixir
@spec graph(t(), String.t()) :: PgRest.SchemaGraph.t()
```

The relationship graph a request against `schema` embeds through.

# `schema_functions`

```elixir
@spec schema_functions(t(), String.t()) :: [PgRest.Function.t()]
```

Every function registered in `schema` (the candidates of an RPC name hint).

---

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