ProtoRune. Lexicon. TypeMapper
(proto_rune v0.5.2)
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
Functions
@spec extract_default(atproto_type()) :: {:ok, term()} | :no_default
Extracts default value from an ATProto type definition if present.
@spec map_object_type(atproto_type()) :: mapping_result()
Maps an object's properties to a Peri schema map.
@spec map_record(map()) :: mapping_result()
Maps a lexicon record to a complete Peri schema including all definitions.
@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
@spec nullable?(atproto_type()) :: boolean()
Checks if a field is nullable in the ATProto definition.