-module(go_over@hex@hex). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/go_over/hex/hex.gleam"). -export([decode_latest_stable_version_and_licenses/1, get_hex_info/6]). -export_type([hex_info/0, hex_warning_source/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(false). -type hex_info() :: {hex_info, gleam@option:option(binary()), list(binary())}. -type hex_warning_source() :: {rejected_license, binary()} | {outdated, binary()}. -file("src/go_over/hex/hex.gleam", 22). ?DOC(false). -spec pull_hex_info( go_over@hex@puller:puller(), go_over@packages:package(), boolean(), boolean() ) -> nil. pull_hex_info(Puller, Pkg, Verbose, Global) -> go_over@util@print:progress( Verbose, <<<<"Checking latest version: "/utf8, (erlang:element(2, Pkg))/binary>>/binary, " From hex.pm"/utf8>> ), Pkg_path = go_over@hex@core:hex_info_path(Pkg, Global), Pkg_path_fail = go_over@hex@core:pkg_pull_error(Pkg, Pkg_path), _ = simplifile_erl:delete(Pkg_path), _pipe = simplifile:create_directory_all(Pkg_path), gxyz@cli:hard_fail_with_msg(_pipe, Pkg_path_fail), Resp = go_over@hex@core:do_pull_hex( Puller, Pkg, go_over@hex@core:package_url(Pkg) ), _pipe@1 = Pkg, _pipe@2 = go_over@hex@core:hex_info_filename(_pipe@1, Global), _pipe@3 = simplifile:write(_pipe@2, Resp), gxyz@cli:hard_fail_with_msg(_pipe@3, Pkg_path_fail). -file("src/go_over/hex/hex.gleam", 47). ?DOC(false). -spec decode_latest_stable_version_and_licenses(binary()) -> {ok, hex_info()} | {error, gleam@json:decode_error()}. decode_latest_stable_version_and_licenses(Data) -> Decoder = begin gleam@dynamic@decode:field( <<"latest_stable_version"/utf8>>, gleam@dynamic@decode:optional( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Latest_stable_version) -> gleam@dynamic@decode:subfield( [<<"meta"/utf8>>, <<"licenses"/utf8>>], gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ), fun(Licenses) -> gleam@dynamic@decode:success( {hex_info, Latest_stable_version, Licenses} ) end ) end ) end, gleam@json:parse(Data, Decoder). -file("src/go_over/hex/hex.gleam", 65). ?DOC(false). -spec pull( go_over@hex@puller:puller(), go_over@packages:package(), boolean(), boolean(), boolean() ) -> hex_info(). pull(Puller, Pkg, Force_pull, Verbose, Global) -> _pipe = Pkg, _pipe@1 = go_over@hex@core:hex_info_path(_pipe, Global), go_over@util@cache:pull_if_not_cached( _pipe@1, 3600, Force_pull, Verbose, gxyz@function:freeze4(fun pull_hex_info/4, Puller, Pkg, Verbose, Global), <<(erlang:element(2, Pkg))/binary, ": latest stable version"/utf8>> ), Cached_file_name = go_over@hex@core:hex_info_filename(Pkg, Global), Resp = begin _pipe@2 = Cached_file_name, _pipe@3 = simplifile:read(_pipe@2), gxyz@cli:hard_fail_with_msg( _pipe@3, <<"failed to read "/utf8, Cached_file_name/binary>> ) end, gxyz@cli:hard_fail_with_msg( decode_latest_stable_version_and_licenses(Resp), <<"failed to parse "/utf8, Cached_file_name/binary>> ). -file("src/go_over/hex/hex.gleam", 95). ?DOC(false). -spec check_outdated(binary(), go_over@packages:package(), binary()) -> gleam@option:option(binary()). check_outdated(Latest_version, Pkg, Cached_file_name) -> Latest_semver = begin _pipe = gleamsver:parse(Latest_version), gxyz@cli:hard_fail_with_msg( _pipe, <<"failed to parse: "/utf8, Cached_file_name/binary>> ) end, case gleamsver:compare(Latest_semver, erlang:element(3, Pkg)) of gt -> {some, Latest_version}; _ -> none end. -file("src/go_over/hex/hex.gleam", 115). ?DOC(false). -spec get_hex_info( go_over@hex@puller:puller(), go_over@packages:package(), boolean(), boolean(), boolean(), list(binary()) ) -> list(hex_warning_source()). get_hex_info(Puller, Pkg, Force_pull, Verbose, Global, Allowed_licenses) -> Info = pull(Puller, Pkg, Force_pull, Verbose, Global), Cached_file_name = go_over@hex@core:hex_info_filename(Pkg, Global), Outdated = begin _pipe = erlang:element(2, Info), _pipe@1 = gleam@option:map( _pipe, fun(_capture) -> check_outdated(_capture, Pkg, Cached_file_name) end ), _pipe@2 = gleam@option:flatten(_pipe@1), gleam@option:map(_pipe@2, fun(Field@0) -> {outdated, Field@0} end) end, Rejected_licenses = begin _pipe@3 = gxyz@list:reject_contains( erlang:element(3, Info), Allowed_licenses ), gleam@list:map(_pipe@3, fun(Field@0) -> {rejected_license, Field@0} end) end, case Outdated of none -> Rejected_licenses; {some, Outdated@1} -> [Outdated@1 | Rejected_licenses] end.