A set of utilities for working with the AT Protocol in Elixir.

feat: add `skip_cache` option for identity resolver

ovyerus.com 8a11da83 a63a6a07

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