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 23 /tmp/ 24 24 25 25 .envrc 26 - .direnv 26 + .direnv 27 + .vscode/
+3
.vscode/settings.json
··· 1 + { 2 + "git.enabled": false 3 + }
+9 -2
lib/atex/identity_resolver.ex
··· 2 2 alias Atex.IdentityResolver.{Cache, DID, DIDDocument, Handle, Identity} 3 3 4 4 @handle_strategy Application.compile_env(:atex, :handle_resolver_strategy, :dns_first) 5 + @type options() :: {:skip_cache, boolean()} 5 6 6 7 # TODO: simplify errors 7 8 8 - def resolve(identifier) do 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 + 9 16 # If cache fetch succeeds, then the ok tuple will be retuned by the default `with` behaviour 10 - with {:error, :not_found} <- Cache.get(identifier), 17 + with {:error, :not_found} <- cache_result, 11 18 {:ok, identity} <- do_resolve(identifier), 12 19 identity <- Cache.insert(identity) do 13 20 {:ok, identity}
-2
lib/atex/identity_resolver/did_document.ex
··· 68 68 @spec from_json(map()) :: {:ok, t()} | {:error, Peri.Error.t()} 69 69 def from_json(%{} = map) do 70 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 71 |> Recase.Enumerable.convert_keys(&Recase.to_snake/1) 74 72 |> schema() 75 73 |> case do