Tama.Dex.Profile (tama_dex v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

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

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

Functions

json_schema()

@spec json_schema() :: map()

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

limits()

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

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

profile()

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

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

validate(document, opts \\ [])

@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.

  1. 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.