Exosphere.ATProto (Exosphere v0.5.0)

Copy Markdown View Source

Lower-level, spec-aligned AT Protocol (ATProto) building blocks.

This namespace is intended to stay close to the AT Protocol specifications (see atproto.com): one submodule per spec domain (NSID, RecordKey, AtUri, TID, CBOR, CID, CAR, MST, DataModel, …), with Identity and Repo grouping their own submodules.

The namespace root is the protocol's front door: it composes the submodules into protocol-level entry points without implementing anything itself. validate/2 dispatches to the spec-aligned validators so callers don't need to know which submodule owns which grammar:

:ok = Exosphere.ATProto.validate(:nsid, "app.bsky.feed.post")
:ok = Exosphere.ATProto.validate(:record, %{"$type" => "com.example.post"})

For higher-level, end-user APIs (XRPC clients, firehose, etc.), prefer the Exosphere.* facade modules, which compose these building blocks.

Summary

Functions

Validate a value against an AT Protocol grammar or data model.

Types

validation_kind()

@type validation_kind() ::
  :nsid | :rkey | :at_uri | :tid | :did | :handle | :cid | :mst_key | :record

Functions

validate(kind, value)

@spec validate(term(), term()) :: :ok | {:error, term()}

Validate a value against an AT Protocol grammar or data model.

Dispatches to the submodule validator that owns each kind, normalizing their boolean/{:error, _} returns into :ok | {:error, reason}:

KindValidatesOwner
:nsidNSID syntaxNSID
:rkeyrecord key syntaxRecordKey
:at_uriat:// URI syntax (errors carry the parse reason, e.g. :invalid_authority or :invalid_rkey)AtUri
:tidTID syntaxTID
:didDID syntaxIdentity.DID
:handlehandle syntaxIdentity.Handle
:cidCID string (blessed atproto format)CID
:mst_keyMST record path (nsid/rkey)MST
:recordatproto data-model recordDataModel

Examples

iex> Exosphere.ATProto.validate(:nsid, "app.bsky.feed.post")
:ok

iex> Exosphere.ATProto.validate(:tid, "not-a-tid")
{:error, :invalid_tid}

iex> Exosphere.ATProto.validate(:at_uri, "https://example.com")
{:error, :invalid_scheme}

iex> Exosphere.ATProto.validate(:record, %{"a" => 1.5})
{:error, {"a", :non_integral_float}}

iex> Exosphere.ATProto.validate("nsid", "app.bsky.feed.post")
{:error, {:unknown_validation_kind, "nsid"}}