# `Arcadic.Server`
[🔗](https://github.com/baselabs/arcadic/blob/baselabs_arcadic-v4.0.1/lib/arcadic/server.ex#L5)

Server-level admin: create/drop/list databases, existence, readiness. Every
identifier is allowlist-validated BEFORE any request reaches the wire (fixes the
interpolation surface a hand-written `create database <name>` would open). Returns
are tagged tuples — a transport failure is never swallowed into a bare boolean.
Not delegated from the `Arcadic` facade: destructive admin stays namespaced.

# `align_database`

```elixir
@spec align_database(Arcadic.Conn.t(), String.t()) ::
  {:ok, map()} | {:error, atom() | Exception.t()}
```

Cluster-realign a database. **CLUSTER-ONLY** — a single-server node returns a server error
(`java.lang.UnsupportedOperationException`, surfaced as `{:error, %Arcadic.Error{reason: :server_error}}`).
Validates `name`.

# `align_database!`

```elixir
@spec align_database!(Arcadic.Conn.t(), String.t()) :: map()
```

# `check_database`

```elixir
@spec check_database(Arcadic.Conn.t(), keyword()) ::
  {:ok, map()} | {:error, Exception.t()}
```

Run `CHECK DATABASE [FIX]` on `conn.database`. `fix: true` repairs. Returns the integrity map.

# `check_database!`

```elixir
@spec check_database!(Arcadic.Conn.t(), keyword()) :: map()
```

# `close_database`

```elixir
@spec close_database(Arcadic.Conn.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Close an open database on the server. Validates `name`.

# `close_database!`

```elixir
@spec close_database!(Arcadic.Conn.t(), String.t()) :: :ok
```

# `create_database`

```elixir
@spec create_database(Arcadic.Conn.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Create a database. Validates `name`.

# `create_database!`

```elixir
@spec create_database!(Arcadic.Conn.t(), String.t()) :: :ok
```

Create a database, raising on error.

# `database_exists?`

```elixir
@spec database_exists?(Arcadic.Conn.t(), String.t()) ::
  {:ok, boolean()} | {:error, atom() | Exception.t()}
```

Whether a database exists.

# `database_info`

```elixir
@spec database_info(Arcadic.Conn.t()) ::
  {:ok, map()} | {:error, atom() | Exception.t()}
```

Database-level info for `conn.database` — `%{database, type, records, classes, size_bytes}`. Fields a
transport can't cheaply provide are `nil` (HTTP gives name/size; gRPC gives all). `:not_supported` on
a transport without the callback (e.g. Bolt).

# `drop_database`

```elixir
@spec drop_database(Arcadic.Conn.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Drop a database. Validates `name`.

# `drop_database!`

```elixir
@spec drop_database!(Arcadic.Conn.t(), String.t()) :: :ok
```

Drop a database, raising on error.

# `events`

```elixir
@spec events(Arcadic.Conn.t()) :: {:ok, map()} | {:error, Exception.t()}
```

Server event log map (`%{"events" => [...], "files" => [...]}`).

# `events!`

```elixir
@spec events!(Arcadic.Conn.t()) :: map()
```

# `health?`

```elixir
@spec health?(Arcadic.Conn.t()) :: {:ok, boolean()} | {:error, Exception.t()}
```

Liveness probe (`GET /api/v1/health` → 204).

# `info`

```elixir
@spec info(Arcadic.Conn.t(), keyword()) :: {:ok, map()} | {:error, Exception.t()}
```

Server info map. `:mode` ∈ [:basic, :default, :cluster] (default `:basic`); `:default`/`:cluster` add metrics/settings.

# `info!`

```elixir
@spec info!(Arcadic.Conn.t(), keyword()) :: map()
```

# `list_databases`

```elixir
@spec list_databases(Arcadic.Conn.t()) ::
  {:ok, [String.t()]} | {:error, Exception.t()}
```

List all databases.

# `metrics`

```elixir
@spec metrics(Arcadic.Conn.t()) :: {:ok, map()} | {:error, Exception.t()}
```

The server metrics map (`info(conn, mode: :default)["metrics"]`).

# `metrics!`

```elixir
@spec metrics!(Arcadic.Conn.t()) :: map()
```

# `open_database`

```elixir
@spec open_database(Arcadic.Conn.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Open a closed database on the server. Validates `name`.

# `open_database!`

```elixir
@spec open_database!(Arcadic.Conn.t(), String.t()) :: :ok
```

# `profiler`

```elixir
@spec profiler(Arcadic.Conn.t(), atom()) :: {:ok, map()} | {:error, Exception.t()}
```

Control the server profiler. `action` ∈ [:results, :start, :stop, :reset].

# `profiler!`

```elixir
@spec profiler!(Arcadic.Conn.t(), atom()) :: map()
```

# `ready?`

```elixir
@spec ready?(Arcadic.Conn.t()) :: {:ok, boolean()} | {:error, Exception.t()}
```

Server readiness.

# `set_database_setting`

```elixir
@spec set_database_setting(Arcadic.Conn.t(), String.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Set a setting on `conn.database` (`` set database setting <db> `k` `v` ``). Guards as `set_server_setting/3`.

# `set_database_setting!`

```elixir
@spec set_database_setting!(Arcadic.Conn.t(), String.t(), String.t()) :: :ok
```

# `set_server_setting`

```elixir
@spec set_server_setting(Arcadic.Conn.t(), String.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Set a server-level setting (`` set server setting `k` `v` ``). `key` is allowlist-validated
(dotted); `value` must not contain a backtick, backslash, or control character (the backtick-quoting
and escape context) — non-ASCII printable values are allowed. Both are rejected value-free
(`{:error, :invalid_setting_key | :invalid_setting_value}`).

# `set_server_setting!`

```elixir
@spec set_server_setting!(Arcadic.Conn.t(), String.t(), String.t()) :: :ok
```

# `shutdown`

```elixir
@spec shutdown(Arcadic.Conn.t()) :: :ok | {:error, Exception.t()}
```

Stops the server. A successful shutdown can close the connection before
Arcadic receives a confirmation. If the call returns a transport error
with reason `:closed`, verify the server state before retrying.

# `shutdown!`

```elixir
@spec shutdown!(Arcadic.Conn.t()) :: :ok
```

---

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