Packages
The shared sans-io core of the gleam-atproto client packages: XRPC error vocabulary and response handling, plus the OAuth effect kernel.
Current section
Files
Jump to
Current section
Files
src/atproto_core@identity.erl
-module(atproto_core@identity).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/atproto_core/identity.gleam").
-export([mini_doc_url/2, mini_doc_decoder/0, resolve_mini_doc/2]).
-export_type([mini_doc/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" The Slingshot-compatible `com.bad-example.identity.resolveMiniDoc`\n"
" lookup, shared by every client package: URL shape, decoder, default\n"
" resolver, and an `Effect`-based resolve for the OAuth flow.\n"
).
-type mini_doc() :: {mini_doc, binary(), binary()}.
-file("src/atproto_core/identity.gleam", 17).
?DOC(" The XRPC URL for `resolveMiniDoc` on `resolver`.\n").
-spec mini_doc_url(binary(), binary()) -> binary().
mini_doc_url(Resolver, Identifier) ->
<<<<Resolver/binary, "/xrpc/com.bad-example.identity.resolveMiniDoc?"/utf8>>/binary,
(gleam@uri:query_to_string([{<<"identifier"/utf8>>, Identifier}]))/binary>>.
-file("src/atproto_core/identity.gleam", 23).
-spec mini_doc_decoder() -> gleam@dynamic@decode:decoder(mini_doc()).
mini_doc_decoder() ->
gleam@dynamic@decode:field(
<<"did"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Did) ->
gleam@dynamic@decode:field(
<<"pds"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Pds) ->
gleam@dynamic@decode:success({mini_doc, Did, Pds})
end
)
end
).
-file("src/atproto_core/identity.gleam", 31).
?DOC(
" Resolve as an `Effect`; sync and async clients make the same request\n"
" with their own `Client`s via `mini_doc_url`/`mini_doc_decoder`.\n"
).
-spec resolve_mini_doc(binary(), binary()) -> atproto_core@oauth@effect:effect({ok,
mini_doc()} |
{error, atproto_core@xrpc:xrpc_error()}).
resolve_mini_doc(Resolver, Identifier) ->
atproto_core@oauth@effect:'try'(
atproto_core@oauth@effect:get_checked(
mini_doc_url(Resolver, Identifier)
),
fun(Resp) ->
atproto_core@oauth@effect:done(
atproto_core@xrpc:parse(
erlang:element(4, Resp),
mini_doc_decoder()
)
)
end
).