ProtoRune.Lexicon.TypeMapper (proto_rune v0.2.0)

Copy Markdown

Maps ATProto lexicon types to Peri schema types.

This module handles the conversion of AT Protocol type definitions (from lexicon JSON files) to Peri schema definitions that can be used for validation.

Supported ATProto Types

  • Primitives: string, integer, boolean, bytes
  • Complex: object, array, ref, union
  • Special: unknown (maps to :any)
  • Formats: datetime, uri, did, handle, etc.

Examples

iex> TypeMapper.map_type(%{"type" => "string"})
{:ok, :string}

iex> TypeMapper.map_type(%{"type" => "integer"})
{:ok, :integer}

iex> TypeMapper.map_type(%{"type" => "array", "items" => %{"type" => "string"}})
{:ok, {:list, :string}}

iex> TypeMapper.map_type(%{"type" => "ref", "ref" => "com.atproto.repo.strongRef"})
{:ok, {:ref, "com.atproto.repo.strongRef"}}

Summary

Functions

Extracts default value from an ATProto type definition if present.

Maps an object's properties to a Peri schema map.

Maps a lexicon record to a complete Peri schema including all definitions.

Maps an ATProto type definition to a Peri schema type.

Checks if a field is nullable in the ATProto definition.

Types

atproto_type()

@type atproto_type() :: map()

mapping_result()

@type mapping_result() :: {:ok, peri_type()} | {:error, term()}

peri_type()

@type peri_type() :: atom() | tuple()

Functions

extract_default(arg1)

@spec extract_default(atproto_type()) :: {:ok, term()} | :no_default

Extracts default value from an ATProto type definition if present.

map_object_type(arg1)

@spec map_object_type(atproto_type()) :: mapping_result()

Maps an object's properties to a Peri schema map.

map_record(def)

@spec map_record(map()) :: mapping_result()

Maps a lexicon record to a complete Peri schema including all definitions.

map_type(def)

@spec map_type(atproto_type()) :: mapping_result()

Maps an ATProto type definition to a Peri schema type.

Parameters

  • type_def: A map containing the ATProto type definition

Returns

  • {:ok, peri_type} on success
  • {:error, reason} if mapping fails

nullable?(arg1)

@spec nullable?(atproto_type()) :: boolean()

Checks if a field is nullable in the ATProto definition.