# `Arc.Context`
[🔗](https://github.com/Cratis/Arc.Elixir/blob/main/lib/arc/context.ex#L4)

Request-scoped facts handed to every command, query, validator and policy.

Arc has no dependency injection container. Handlers call `Repo`, context modules and
`Chronicle` directly, and receive the caller's facts through this struct. The same values are
set as `Logger` metadata while the artifact runs (`:arc_correlation_id`, `:arc_tenant`).

  * `:application` - the `Arc.Application` module running the artifact
  * `:principal` - the `Arc.Principal` of the caller
  * `:tenant` - the resolved tenant, or `nil`
  * `:correlation_id` / `:causation_id` - tracing identifiers (correlation is echoed on the response)
  * `:metadata` - free-form map; copied to the Chronicle append as causation properties
  * `:deadline` - monotonic millisecond deadline, or `nil`
  * `:provided` - values returned by the command's `provide/2`
  * `:allowed_severity` - the highest non-blocking validation severity the caller accepts
  * `:chronicle` - options passed to every `Chronicle.append/3` (for example `client:`); for a named
    tenant it carries that tenant as the Chronicle `namespace:`
  * `:query` - while a query runs, what the caller asked for: `%{page:, page_size:, sort_by:,
    sort_direction:}` (`sort_by` is the `camelCase` wire name). A query that pages in the database
    reads it, for example `Arc.MongoDB.page/3`

# `t`

```elixir
@type t() :: %Arc.Context{
  allowed_severity: integer(),
  application: module() | nil,
  causation_id: String.t() | nil,
  chronicle: keyword(),
  correlation_id: String.t() | nil,
  deadline: integer() | nil,
  metadata: map(),
  principal: Arc.Principal.t(),
  provided: map(),
  query: map(),
  tenant: String.t() | nil
}
```

# `expired?`

```elixir
@spec expired?(t()) :: boolean()
```

Whether the deadline, if any, has passed.

# `new`

```elixir
@spec new(keyword()) :: t()
```

Builds a context, generating a correlation id when none is given.

# `new_correlation_id`

```elixir
@spec new_correlation_id() :: String.t()
```

Generates a canonical lowercase UUID v4 string.

---

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