An Elixir toolkit for the AT Protocol. hexdocs.pm/atex
elixir bluesky atproto decentralization
25
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add sigils for AtURI and TID

+71
+2
CHANGELOG.md
··· 26 26 [publication and resolution spec](https://atproto.com/specs/lexicon#lexicon-publication-and-resolution). 27 27 - `mix atex.lexicons.resolve` task for resolving one or more lexicons by NSID 28 28 and writing to a JSON file. 29 + - Sigils for `Atex.AtURI` and `Atex.TID`, `~AT"at://..."` and `~TID"..."` 30 + respectively. 29 31 30 32 ## [0.8.0] - 2026-03-29 31 33
+34
lib/atex/aturi.ex
··· 140 140 |> String.trim_trailing("/") 141 141 end 142 142 143 + @doc """ 144 + Sigil for constructing an `Atex.AtURI` struct from a string literal. 145 + Raises `ArgumentError` if the string is not a valid `at://` URI. 146 + 147 + ## Examples 148 + 149 + iex> import Atex.AtURI 150 + iex> ~AT"at://did:plc:44ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk26" 151 + ~AT"at://did:plc:44ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk26" 152 + 153 + """ 154 + defmacro sigil_AT({:<<>>, _meta, [value]}, _modifiers) when is_binary(value) do 155 + case Atex.AtURI.new(value) do 156 + {:ok, uri} -> 157 + Macro.escape(uri) 158 + 159 + :error -> 160 + raise ArgumentError, "invalid at:// URI: #{inspect(value)}" 161 + end 162 + end 163 + 164 + defmacro sigil_AT({:<<>>, _meta, _parts} = ast, _modifiers) do 165 + quote do 166 + case Atex.AtURI.new(unquote(ast)) do 167 + {:ok, uri} -> uri 168 + :error -> raise ArgumentError, "invalid at:// URI: #{inspect(unquote(ast))}" 169 + end 170 + end 171 + end 172 + 143 173 defp from_named_captures(%{"authority" => authority, "collection" => "", "rkey" => ""}), 144 174 do: %__MODULE__{authority: authority} 145 175 ··· 157 187 defimpl String.Chars, for: Atex.AtURI do 158 188 def to_string(uri), do: Atex.AtURI.to_string(uri) 159 189 end 190 + 191 + defimpl Inspect, for: Atex.AtURI do 192 + def inspect(uri, _opts), do: ~s(~AT"#{Atex.AtURI.to_string(uri)}") 193 + end
+35
lib/atex/tid.ex
··· 182 182 """ 183 183 @spec match?(String.t()) :: boolean() 184 184 def match?(value), do: Regex.match?(@re, value) 185 + 186 + @doc """ 187 + Sigil for constructing a `Atex.TID` struct from a string literal at 188 + compile-time or runtime. Raises `ArgumentError` if the string is not a valid 189 + TID. 190 + 191 + ## Examples 192 + 193 + iex> import Atex.TID 194 + iex> ~TID"3jzfcijpj2z2a" 195 + ~TID"3jzfcijpj2z2a" 196 + 197 + """ 198 + defmacro sigil_TID({:<<>>, _meta, [value]}, _modifiers) when is_binary(value) do 199 + case Atex.TID.decode(value) do 200 + {:ok, tid} -> 201 + Macro.escape(tid) 202 + 203 + :error -> 204 + raise ArgumentError, "invalid TID: #{inspect(value)}" 205 + end 206 + end 207 + 208 + defmacro sigil_TID({:<<>>, _meta, _parts} = ast, _modifiers) do 209 + quote do 210 + case Atex.TID.decode(unquote(ast)) do 211 + {:ok, tid} -> tid 212 + :error -> raise ArgumentError, "invalid TID: #{inspect(unquote(ast))}" 213 + end 214 + end 215 + end 185 216 end 186 217 187 218 defimpl String.Chars, for: Atex.TID do 188 219 def to_string(tid), do: Atex.TID.encode(tid) 189 220 end 221 + 222 + defimpl Inspect, for: Atex.TID do 223 + def inspect(tid, _opts), do: ~s(~TID"#{Atex.TID.encode(tid)}") 224 + end