# `Alternera.Resource.Host`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_resource_sdk/lib/alternera/resource/host.ex#L1)

What a resource package needs from the proxy at run time, as a behaviour.

A package compiles before the proxy and cannot name its modules, so the
policy checks (`Alternera.Resource.Checks.*`), the version mixin and
the cache change ask the host. The proxy's implementation is
`Alternera.Resources.Host`, set with
`config :alternera_resource_sdk, :host, …`; a package's own tests run
against `Alternera.Resource.Test.Host`.

# `mode`

```elixir
@type mode() :: :read | :write
```

Whether a check is about reading records or changing them.

# `actor_id`

```elixir
@callback actor_id(actor :: term()) :: String.t() | nil
```

The id a version row records for the actor; `nil` for the system.

# `available?`

```elixir
@callback available?() :: boolean()
```

Whether the host serves resources now. While it does not, every policy
but destroy refuses (`Alternera.Resource.Checks.Available`).

# `changed`

```elixir
@callback changed(tenant_id :: String.t(), name :: String.t(), key :: term()) :: :ok
```

A record of resource `name` (`"<package id>.<resource id>"`) was written in
the tenant: drop what is cached for `key` (a lookup key value, the record's
primary key when the resource has no lookup key, or `:all`).

# `role_allows?`

```elixir
@callback role_allows?(actor :: term(), tenant_id :: String.t(), mode()) :: boolean()
```

Whether the actor may read (`:read`) or change (`:write`) records of the tenant.

# `system_actor?`

```elixir
@callback system_actor?(actor :: term()) :: boolean()
```

Whether the actor is the system or a super admin: every check passes.

# `impl`

```elixir
@spec impl() :: module()
```

The configured host module.

---

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