Packages

Gleam dynamic decoders for the API of Hex, the package manager for the BEAM ecosystem.

Current section

Files

Jump to
gleam_hexpm src gleam@hexpm.erl
Raw

src/gleam@hexpm.erl

-module(gleam@hexpm).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([retirement_reason_decoder/0, retirement_reason_to_string/1, package_decoder/0, release_decoder/0]).
-export_type([package/0, package_meta/0, package_release/0, package_owner/0, release/0, release_meta/0, release_retirement/0, retirement_reason/0]).
-type package() :: {package,
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
package_meta(),
gleam@dict:dict(binary(), integer()),
gleam@option:option(list(package_owner())),
list(package_release()),
gleam@time@timestamp:timestamp(),
gleam@time@timestamp:timestamp()}.
-type package_meta() :: {package_meta,
gleam@dict:dict(binary(), binary()),
list(binary()),
gleam@option:option(binary())}.
-type package_release() :: {package_release,
binary(),
binary(),
gleam@time@timestamp:timestamp()}.
-type package_owner() :: {package_owner,
binary(),
gleam@option:option(binary()),
binary()}.
-type release() :: {release,
binary(),
binary(),
binary(),
integer(),
gleam@option:option(package_owner()),
release_meta(),
gleam@option:option(release_retirement()),
gleam@time@timestamp:timestamp(),
gleam@time@timestamp:timestamp()}.
-type release_meta() :: {release_meta,
gleam@option:option(binary()),
list(binary())}.
-type release_retirement() :: {release_retirement,
retirement_reason(),
gleam@option:option(binary())}.
-type retirement_reason() :: other_reason |
invalid |
security |
deprecated |
renamed.
-file("src/gleam/hexpm.gleam", 77).
-spec timestamp_decoder() -> gleam@dynamic@decode:decoder(gleam@time@timestamp:timestamp()).
timestamp_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(String) -> case gleam@time@timestamp:parse_rfc3339(String) of
{ok, Timestamp} ->
gleam@dynamic@decode:success(Timestamp);
{error, _} ->
gleam@dynamic@decode:failure(
gleam@time@timestamp:from_unix_seconds(0),
<<"Timestamp"/utf8>>
)
end end
).
-file("src/gleam/hexpm.gleam", 118).
-spec retirement_reason_decoder() -> gleam@dynamic@decode:decoder(retirement_reason()).
retirement_reason_decoder() ->
gleam@dynamic@decode:then(
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(String) -> case String of
<<"invalid"/utf8>> ->
gleam@dynamic@decode:success(invalid);
<<"security"/utf8>> ->
gleam@dynamic@decode:success(security);
<<"deprecated"/utf8>> ->
gleam@dynamic@decode:success(deprecated);
<<"renamed"/utf8>> ->
gleam@dynamic@decode:success(renamed);
_ ->
gleam@dynamic@decode:success(other_reason)
end end
).
-file("src/gleam/hexpm.gleam", 129).
-spec retirement_reason_to_string(retirement_reason()) -> binary().
retirement_reason_to_string(Reason) ->
case Reason of
other_reason ->
<<"other"/utf8>>;
invalid ->
<<"invalid"/utf8>>;
security ->
<<"security"/utf8>>;
deprecated ->
<<"deprecated"/utf8>>;
renamed ->
<<"renamed"/utf8>>
end.
-file("src/gleam/hexpm.gleam", 176).
-spec package_owner_decoder() -> gleam@dynamic@decode:decoder(package_owner()).
package_owner_decoder() ->
gleam@dynamic@decode:field(
<<"username"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Username) ->
gleam@dynamic@decode:optional_field(
<<"email"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Email) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:success(
{package_owner, Username, Email, Url}
)
end
)
end
)
end
).
-file("src/gleam/hexpm.gleam", 37).
-spec package_decoder() -> gleam@dynamic@decode:decoder(package()).
package_decoder() ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:field(
<<"html_url"/utf8>>,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Html_url) ->
gleam@dynamic@decode:field(
<<"docs_html_url"/utf8>>,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Docs_html_url) ->
gleam@dynamic@decode:field(
<<"meta"/utf8>>,
begin
gleam@dynamic@decode:field(
<<"links"/utf8>>,
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Links) ->
gleam@dynamic@decode:field(
<<"licenses"/utf8>>,
gleam@dynamic@decode:list(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Licenses) ->
gleam@dynamic@decode:field(
<<"description"/utf8>>,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Description) ->
gleam@dynamic@decode:success(
{package_meta,
Links,
Licenses,
Description}
)
end
)
end
)
end
)
end,
fun(Meta) ->
gleam@dynamic@decode:field(
<<"downloads"/utf8>>,
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(Downloads) ->
gleam@dynamic@decode:optional_field(
<<"owners"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:list(
package_owner_decoder()
)
),
fun(Owners) ->
gleam@dynamic@decode:field(
<<"releases"/utf8>>,
gleam@dynamic@decode:list(
begin
gleam@dynamic@decode:field(
<<"version"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Version) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Url
) ->
gleam@dynamic@decode:field(
<<"inserted_at"/utf8>>,
timestamp_decoder(
),
fun(
Inserted_at
) ->
gleam@dynamic@decode:success(
{package_release,
Version,
Url,
Inserted_at}
)
end
)
end
)
end
)
end
),
fun(Releases) ->
gleam@dynamic@decode:field(
<<"inserted_at"/utf8>>,
timestamp_decoder(
),
fun(
Inserted_at@1
) ->
gleam@dynamic@decode:field(
<<"updated_at"/utf8>>,
timestamp_decoder(
),
fun(
Updated_at
) ->
gleam@dynamic@decode:success(
{package,
Name,
Html_url,
Docs_html_url,
Meta,
Downloads,
Owners,
Releases,
Inserted_at@1,
Updated_at}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/gleam/hexpm.gleam", 139).
-spec release_decoder() -> gleam@dynamic@decode:decoder(release()).
release_decoder() ->
gleam@dynamic@decode:field(
<<"version"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Version) ->
gleam@dynamic@decode:field(
<<"url"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Url) ->
gleam@dynamic@decode:field(
<<"checksum"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Checksum) ->
gleam@dynamic@decode:field(
<<"downloads"/utf8>>,
gleam@dynamic@decode:one_of(
{decoder,
fun gleam@dynamic@decode:decode_int/1},
[gleam@dynamic@decode:success(0)]
),
fun(Downloads) ->
gleam@dynamic@decode:field(
<<"publisher"/utf8>>,
gleam@dynamic@decode:optional(
package_owner_decoder()
),
fun(Publisher) ->
gleam@dynamic@decode:field(
<<"meta"/utf8>>,
begin
gleam@dynamic@decode:optional_field(
<<"app"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(App) ->
gleam@dynamic@decode:field(
<<"build_tools"/utf8>>,
gleam@dynamic@decode:list(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Build_tools) ->
gleam@dynamic@decode:success(
{release_meta,
App,
Build_tools}
)
end
)
end
)
end,
fun(Meta) ->
gleam@dynamic@decode:optional_field(
<<"retirement"/utf8>>,
none,
gleam@dynamic@decode:optional(
begin
gleam@dynamic@decode:field(
<<"reason"/utf8>>,
retirement_reason_decoder(
),
fun(Reason) ->
gleam@dynamic@decode:field(
<<"message"/utf8>>,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(
Message
) ->
gleam@dynamic@decode:success(
{release_retirement,
Reason,
Message}
)
end
)
end
)
end
),
fun(Retirement) ->
gleam@dynamic@decode:field(
<<"inserted_at"/utf8>>,
timestamp_decoder(
),
fun(Inserted_at) ->
gleam@dynamic@decode:field(
<<"updated_at"/utf8>>,
timestamp_decoder(
),
fun(
Updated_at
) ->
gleam@dynamic@decode:success(
{release,
Version,
Url,
Checksum,
Downloads,
Publisher,
Meta,
Retirement,
Inserted_at,
Updated_at}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
).