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

feat: add `skip_cache` option for identity resolver

ovyerus.com 8a11da83 a63a6a07

verified
+14 -5
+2 -1
.gitignore
··· 23 /tmp/ 24 25 .envrc 26 - .direnv
··· 23 /tmp/ 24 25 .envrc 26 + .direnv 27 + .vscode/
+3
.vscode/settings.json
···
··· 1 + { 2 + "git.enabled": false 3 + }
+9 -2
lib/atex/identity_resolver.ex
··· 2 alias Atex.IdentityResolver.{Cache, DID, DIDDocument, Handle, Identity} 3 4 @handle_strategy Application.compile_env(:atex, :handle_resolver_strategy, :dns_first) 5 6 # TODO: simplify errors 7 8 - def resolve(identifier) do 9 # If cache fetch succeeds, then the ok tuple will be retuned by the default `with` behaviour 10 - with {:error, :not_found} <- Cache.get(identifier), 11 {:ok, identity} <- do_resolve(identifier), 12 identity <- Cache.insert(identity) do 13 {:ok, identity}
··· 2 alias Atex.IdentityResolver.{Cache, DID, DIDDocument, Handle, Identity} 3 4 @handle_strategy Application.compile_env(:atex, :handle_resolver_strategy, :dns_first) 5 + @type options() :: {:skip_cache, boolean()} 6 7 # TODO: simplify errors 8 9 + @spec resolve(String.t(), list(options())) :: {:ok, Identity.t()} | {:error, any()} 10 + def resolve(identifier, opts \\ []) do 11 + opts = Keyword.validate!(opts, skip_cache: false) 12 + skip_cache = Keyword.get(opts, :skip_cache) 13 + 14 + cache_result = if skip_cache, do: {:error, :not_found}, else: Cache.get(identifier) 15 + 16 # If cache fetch succeeds, then the ok tuple will be retuned by the default `with` behaviour 17 + with {:error, :not_found} <- cache_result, 18 {:ok, identity} <- do_resolve(identifier), 19 identity <- Cache.insert(identity) do 20 {:ok, identity}
-2
lib/atex/identity_resolver/did_document.ex
··· 68 @spec from_json(map()) :: {:ok, t()} | {:error, Peri.Error.t()} 69 def from_json(%{} = map) do 70 map 71 - # TODO: `atomize_keys` instead? Peri doesn't convert nested schemas to atoms but does for the base schema. 72 - # Smells like a PR if I've ever smelt one... 73 |> Recase.Enumerable.convert_keys(&Recase.to_snake/1) 74 |> schema() 75 |> case do
··· 68 @spec from_json(map()) :: {:ok, t()} | {:error, Peri.Error.t()} 69 def from_json(%{} = map) do 70 map 71 |> Recase.Enumerable.convert_keys(&Recase.to_snake/1) 72 |> schema() 73 |> case do