# `Tama.Dex.Profile`
[🔗](https://github.com/kritama/tama-dex/blob/v0.1.0/lib/tama/dex/profile.ex#L1)

Validates documents in the Tama operations profile, `tama-operations/1`.

The profile is defined in `docs/tama-operations-profile.md`, and its
document shape is published as JSON Schema 2020-12 in
`priv/profile/tama-operations-1.schema.json`.

`validate/1` is pure: it starts no process and reads no file or network
resource. Producers can use it as a test-only dependency to check their
documents.

# `json_schema`

```elixir
@spec json_schema() :: map()
```

The profile's published JSON Schema, as decoded JSON.

# `limits`

```elixir
@spec limits() :: keyword(pos_integer())
```

The profile's limits: `max_document_bytes` (4 MiB), `max_operations`
(1024) and `max_schema_bytes` (256 KiB).

# `profile`

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

The profile version this module validates, `tama-operations/1`.

# `validate`

```elixir
@spec validate(term(), keyword()) ::
  {:ok, Tama.Dex.Document.t()} | {:error, [Tama.Dex.Profile.Issue.t()]}
```

Validates a profile document given as decoded JSON (a map with string keys).

Returns `{:ok, document}` with the normalized `Tama.Dex.Document`, or
`{:error, issues}` listing every issue found, ordered by pointer. See
`Tama.Dex.Profile.Issue` for the codes.

Checks run in this order, and each of the first four stops validation when
it fails:

1. The document is JSON data.
2. `x-tama-profile` is `tama-operations/1`. Otherwise the only issue is
   `:unsupported_profile`, and no operation is read.
3. The serialized document is at most 4 MiB and holds at most 1024
   operations. Otherwise no schema is compiled.

The `:limits` option lowers the profile's limits, as a keyword list of
`:max_document_bytes`, `:max_operations` and `:max_schema_bytes`. Limits
above the profile's raise `ArgumentError`.
4. The document's shape matches the profile's JSON Schema, and the
   semantic rules hold: path suffixes, unique IDs, confirmation and
   identity fields, references, sizes and schema compilation. Every issue
   from this step is reported together.

---

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