diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_auth.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_auth.erl new file mode 100644 index 0000000000000000000000000000000000000000..6ea59e0813433b35b9054cb21625ed9f7eb19769 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_auth.erl @@ -0,0 +1,20 @@ +%% @doc +%% Hex HTTP API - Authentication. +-module(hex_api_auth). +-export([test/2]). + +%% @doc +%% Test an auth key against a given domain and resource. +%% +%% Examples: +%% +%% ``` +%% 1> Params = #{domain => <<"repository">>, resource => <<"gustafson_motors">>}. +%% 2> hex_api_auth:test_key(hex_core:default_config(), Params). +%% {ok,{204, ..., nil}} +%% ''' +%% @end +-spec test(hex_core:config(), map()) -> hex_api:response(). +test(Config, #{domain := Domain, resource := Resource}) -> + URI = ["auth", "?domain=", Domain, "&resource=", Resource], + hex_api:get(Config, list_to_binary(URI)). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_key.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_key.erl new file mode 100644 index 0000000000000000000000000000000000000000..f16743f4b8ed7a52f0f15f13552b0d08e1082da1 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_key.erl @@ -0,0 +1,156 @@ +%% @doc +%% Hex HTTP API - Keys. +-module(hex_api_key). +-export([ + list/1, + get/2, + add/3, + delete/2, + delete_all/1 +]). + +-export_type([permission/0]). + +-type permission() :: #{binary() := binary()}. + +%% @doc +%% Lists the user's or organization's API and repository keys. +%% +%% Examples: +%% +%% ``` +%% > hex_api_key:list(hex_core:default_config()). +%% {ok, {200, ..., [#{ +%% <<"authing_key">> => true, +%% <<"inserted_at">> => <<"2019-02-27T11:15:32Z">>, +%% <<"last_use">> => +%% #{<<"ip">> => <<"1.2.3.4">>, +%% <<"used_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"user_agent">> => <<"hex_core/0.5.0 (httpc) (OTP/21) (erts/10.2)">>}, +%% <<"name">> => <<"hex_core">>, +%% <<"permissions">> => [#{<<"domain">> => <<"api">>,<<"resource">> => <<"read">>}], +%% <<"revoked_at">> => nil, +%% <<"updated_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"url">> => <<"https://hex.pm/api/keys/test">>}, +%% }]}} +%% ''' +%% @end +-spec list(hex_core:config()) -> hex_api:response(). +list(Config) when is_map(Config) -> + Path = hex_api:build_organization_path(Config, ["keys"]), + hex_api:get(Config, Path). + +%% @doc +%% Gets an API or repository key by name. +%% +%% Examples: +%% +%% ``` +%% > hex_api_key:get(hex_core:default_config(), <<"test">>). +%% {ok, {200, ..., #{ +%% <<"authing_key">> => true, +%% <<"inserted_at">> => <<"2019-02-27T11:15:32Z">>, +%% <<"last_use">> => +%% #{<<"ip">> => <<"1.2.3.4">>, +%% <<"used_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"user_agent">> => <<"hex_core/0.5.0 (httpc) (OTP/21) (erts/10.2)">>}, +%% <<"name">> => <<"hex_core">>, +%% <<"permissions">> => [#{<<"domain">> => <<"api">>,<<"resource">> => <<"read">>}], +%% <<"revoked_at">> => nil, +%% <<"updated_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"url">> => <<"https://hex.pm/api/keys/test">>}, +%% }}} +%% ''' +%% @end +-spec get(hex_core:config(), binary()) -> hex_api:response(). +get(Config, Name) when is_map(Config) and is_binary(Name) -> + Path = hex_api:build_organization_path(Config, ["keys", Name]), + hex_api:get(Config, Path). + +%% @doc +%% Adds a new API or repository key. +%% +%% A permission is a map of `#{<<"domain">> => Domain, <<"resource"> => Resource}'. +%% +%% Valid `Domain' values: `<<"api">> | <<"repository">> | <<"repositories">>'. +%% +%% Valid `Resource' values: `<<"read">> | <<"write">>'. +%% +%% Examples: +%% +%% ``` +%% > hex_api_key:add(hex_core:default_config(), <<"test">>, [...]). +%% {ok, {200, ..., #{ +%% <<"authing_key">> => true, +%% <<"inserted_at">> => <<"2019-02-27T11:15:32Z">>, +%% <<"last_use">> => +%% #{<<"ip">> => <<"1.2.3.4">>, +%% <<"used_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"user_agent">> => <<"hex_core/0.5.0 (httpc) (OTP/21) (erts/10.2)">>}, +%% <<"name">> => <<"hex_core">>, +%% <<"permissions">> => [#{<<"domain">> => <<"api">>,<<"resource">> => <<"read">>}], +%% <<"revoked_at">> => nil, +%% <<"updated_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"url">> => <<"https://hex.pm/api/keys/test">>}, +%% }}} +%% ''' +%% @end +-spec add(hex_core:config(), binary(), [permission()]) -> hex_api:response(). +add(Config, Name, Permissions) when is_map(Config) and is_binary(Name) and is_list(Permissions) -> + Path = hex_api:build_organization_path(Config, ["keys"]), + Params = #{<<"name">> => Name, <<"permissions">> => Permissions}, + hex_api:post(Config, Path, Params). + +%% @doc +%% Deletes an API or repository key. +%% +%% Examples: +%% +%% ``` +%% > hex_api_key:delete(hex_core:default_config(), <<"test">>). +%% {ok, {200, ..., #{ +%% <<"authing_key">> => true, +%% <<"inserted_at">> => <<"2019-02-27T11:15:32Z">>, +%% <<"last_use">> => +%% #{<<"ip">> => <<"1.2.3.4">>, +%% <<"used_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"user_agent">> => <<"hex_core/0.5.0 (httpc) (OTP/21) (erts/10.2)">>}, +%% <<"name">> => <<"hex_core">>, +%% <<"permissions">> => [#{<<"domain">> => <<"api">>,<<"resource">> => <<"read">>}], +%% <<"revoked_at">> => nil, +%% <<"updated_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"url">> => <<"https://hex.pm/api/keys/test">>}, +%% }}} +%% ''' +%% @end +-spec delete(hex_core:config(), binary()) -> hex_api:response(). +delete(Config, Name) when is_map(Config) and is_binary(Name) -> + Path = hex_api:build_organization_path(Config, ["keys", Name]), + hex_api:delete(Config, Path). + +%% @doc +%% Deletes all API and repository keys associated with the account. +%% +%% Examples: +%% +%% ``` +%% > hex_api_key:delete_all(hex_core:default_config()). +%% {ok, {200, ..., [#{ +%% <<"authing_key">> => true, +%% <<"inserted_at">> => <<"2019-02-27T11:15:32Z">>, +%% <<"last_use">> => +%% #{<<"ip">> => <<"1.2.3.4">>, +%% <<"used_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"user_agent">> => <<"hex_core/0.5.0 (httpc) (OTP/21) (erts/10.2)">>}, +%% <<"name">> => <<"hex_core">>, +%% <<"permissions">> => [#{<<"domain">> => <<"api">>,<<"resource">> => <<"read">>}], +%% <<"revoked_at">> => nil, +%% <<"updated_at">> => <<"2019-02-27T14:38:54Z">>, +%% <<"url">> => <<"https://hex.pm/api/keys/test">>}, +%% }]}} +%% ''' +%% @end +-spec delete_all(hex_core:config()) -> hex_api:response(). +delete_all(Config) when is_map(Config) -> + Path = hex_api:build_organization_path(Config, ["keys"]), + hex_api:delete(Config, Path). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization.erl new file mode 100644 index 0000000000000000000000000000000000000000..424ad277720b4e213512624f75f628274741dc2e --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization.erl @@ -0,0 +1,67 @@ +%% @doc +%% Hex HTTP API - Organizations. +-module(hex_api_organization). +-export([ + get/1, + list/1, + update/2 +]). + +%% @doc +%% Lists all organizations you are member of. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization:list(hex_core:default_config()). +%% {ok, {200, ..., [#{ +%% <<"billing_active">> => true, +%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>, +%% <<"name">> => <<"acme">>, +%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>} +%% }]}} +%% ''' +-spec list(hex_core:config()) -> hex_api:response(). +list(Config) when is_map(Config) -> + hex_api:get(Config, ["orgs"]). + +%% @doc +%% Gets an organzation. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization:get(hex_core:default_config()). +%% {ok, {200, ..., #{ +%% <<"billing_active">> => true, +%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>, +%% <<"name">> => <<"acme">>, +%% <<"seats">> => 42, +%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>} +%% }}} +%% ''' +-spec get(hex_core:config()) -> hex_api:response(). +get(Config) when is_map(Config) -> + Path = hex_api:build_organization_path(Config, []), + hex_api:get(Config, Path). + +%% @doc +%% Updates the number of seats in an organzation. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization:get(hex_core:default_config(), 42). +%% {ok, {200, ..., #{ +%% <<"billing_active">> => true, +%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>, +%% <<"name">> => <<"acme">>, +%% <<"seats">> => 42, +%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>} +%% }}} +%% ''' +-spec update(hex_core:config(), pos_integer()) -> hex_api:response(). +update(Config, Seats) when is_map(Config) and is_integer(Seats) -> + Path = hex_api:build_organization_path(Config, []), + Params = #{<<"seats">> => Seats}, + hex_api:post(Config, Path, Params). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization_member.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization_member.erl new file mode 100644 index 0000000000000000000000000000000000000000..b9bce9dc489b0789d5aee3cfa2a8a0a10228fae6 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_organization_member.erl @@ -0,0 +1,113 @@ +%% @doc +%% Hex HTTP API - Organization Members. +-module(hex_api_organization_member). +-export([ + add/3, + delete/2, + get/2, + list/1, + update/3 +]). + +-type role() :: admin | write | read. + +%% @doc +%% Lists the organization's members. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization_member:list(hex_core:default_config(), #{api_organization => <<"acme">>}). +%% {ok, {200, ..., [#{ +%% <<"email">> => <<"user@example.com">>, +%% <<"role">> => <<"admin">>, +%% <<"url">> => <<"https://hex.pm/api/users/user">>, +%% <<"username">> => <<"user">> +%% }]}} +%% ''' +%% @end +-spec list(hex_core:config()) -> hex_api:response(). +list(Config) when is_map(Config) -> + Path = hex_api:build_organization_path(Config, ["members"]), + hex_api:get(Config, Path). + +%% @doc +%% Gets an organization member. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization_member:get(hex_core:default_config(), #{api_organization => <<"acme">>}, <<"user">>). +%% {ok, {200, ..., #{ +%% <<"email">> => <<"user@example.com">>, +%% <<"role">> => <<"admin">>, +%% <<"url">> => <<"https://hex.pm/api/users/user">>, +%% <<"username">> => <<"user">> +%% }}} +%% ''' +%% @end +-spec get(hex_core:config(), binary()) -> hex_api:response(). +get(Config, UsernameOrEmail) when is_map(Config) and is_binary(UsernameOrEmail) -> + Path = hex_api:build_organization_path(Config, ["members", UsernameOrEmail]), + hex_api:get(Config, Path). + +%% @doc +%% Adds an organization member. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization_member:add(hex_core:default_config(), #{api_organization => <<"acme">>}, <<"user">>, write). +%% {ok, {200, ..., #{ +%% <<"email">> => <<"user@example.com">>, +%% <<"role">> => <<"write">>, +%% <<"url">> => <<"https://hex.pm/api/users/user">>, +%% <<"username">> => <<"user">> +%% }}} +%% ''' +%% @end +-spec add(hex_core:config(), binary(), role()) -> hex_api:response(). +add(Config, UsernameOrEmail, Role) when + is_map(Config) and is_binary(UsernameOrEmail) and is_atom(Role) +-> + Path = hex_api:build_organization_path(Config, ["members"]), + Params = #{<<"name">> => UsernameOrEmail, <<"role">> => Role}, + hex_api:post(Config, Path, Params). + +%% @doc +%% Updates an organization member's role. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization_member:update(hex_core:default_config(), #{api_organization => <<"acme">>}, <<"user">>, read). +%% {ok, {200, ..., #{ +%% <<"email">> => <<"user@example.com">>, +%% <<"role">> => <<"read">>, +%% <<"url">> => <<"https://hex.pm/api/users/user">>, +%% <<"username">> => <<"user">> +%% }}} +%% ''' +%% @end +-spec update(hex_core:config(), binary(), role()) -> hex_api:response(). +update(Config, UsernameOrEmail, Role) when + is_map(Config) and is_binary(UsernameOrEmail) and is_atom(Role) +-> + Path = hex_api:build_organization_path(Config, ["members", UsernameOrEmail]), + Params = #{<<"role">> => Role}, + hex_api:post(Config, Path, Params). + +%% @doc +%% Deletes an organization member. +%% +%% Examples: +%% +%% ``` +%% > hex_api_organization_member:delete(hex_core:default_config(), #{api_organization => <<"acme">>}, <<"user">>). +%% {ok, {204, ..., nil}} +%% ''' +%% @end +-spec delete(hex_core:config(), binary()) -> hex_api:response(). +delete(Config, UsernameOrEmail) when is_map(Config) and is_binary(UsernameOrEmail) -> + Path = hex_api:build_organization_path(Config, ["members", UsernameOrEmail]), + hex_api:delete(Config, Path). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_package.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_package.erl new file mode 100644 index 0000000000000000000000000000000000000000..7a2e7f27c6ffde5a9511ed6279b3079382c34187 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_package.erl @@ -0,0 +1,53 @@ +%% @doc +%% Hex HTTP API - Packages. +-module(hex_api_package). +-export([get/2, search/3]). + +%% @doc +%% Gets a package. +%% +%% Examples: +%% +%% ``` +%% > hex_api_package:get(hex_core:default_config(), <<"package">>). +%% {ok, {200, ..., #{ +%% <<"name">> => <<"package1">>, +%% <<"meta">> => #{ +%% <<"description">> => ..., +%% <<"licenses">> => ..., +%% <<"links">> => ..., +%% <<"maintainers">> => ... +%% }, +%% ..., +%% <<"releases">> => [ +%% #{<<"url">> => ..., <<"version">> => <<"0.5.0">>}], +%% #{<<"url">> => ..., <<"version">> => <<"1.0.0">>}], +%% ... +%% ]}}} +%% ''' +%% @end +-spec get(hex_core:config(), binary()) -> hex_api:response(). +get(Config, Name) when is_map(Config) and is_binary(Name) -> + Path = hex_api:build_repository_path(Config, ["packages", Name]), + hex_api:get(Config, Path). + +%% @doc +%% Searches packages. +%% +%% Examples: +%% +%% ``` +%% > hex_api_package:search(hex_core:default_config(), <<"package">>, [{page, 1}]). +%% {ok, {200, ..., [ +%% #{<<"name">> => <<"package1">>, ...}, +%% ... +%% ]}} +%% ''' +-spec search(hex_core:config(), binary(), [{term(), term()}]) -> hex_api:response(). +search(Config, Query, SearchParams) when + is_map(Config) and is_binary(Query) and is_list(SearchParams) +-> + QueryString = hex_api:encode_query_string([{search, Query} | SearchParams]), + Path = hex_api:join_path_segments(hex_api:build_repository_path(Config, ["packages"])), + PathQuery = <>, + hex_api:get(Config, PathQuery). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_release.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_release.erl new file mode 100644 index 0000000000000000000000000000000000000000..6210cad0a47e2924c1d390d6576d2307c27d1685 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_release.erl @@ -0,0 +1,191 @@ +%% @doc +%% Hex HTTP API - Releases. +-module(hex_api_release). +-export([ + delete/3, + get/3, + publish/2, + publish/3, + retire/4, + unretire/3 +]). + +-export_type([publish_params/0, retirement_params/0]). + +-type publish_params() :: [{replace, boolean()}]. + +-type retirement_params() :: #{binary() := binary()}. +%% @doc +%% Gets a package release. +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:get(hex_core:default_config(), <<"package">>, <<"1.0.0">>). +%% {ok, {200, ..., #{ +%% <<"checksum">> => <<"540d210d81f56f17f64309a4896430e727972499b37bd59342dc08d61dff74d8">>, +%% <<"docs_html_url">> => <<"https://hexdocs.pm/package/1.0.0/">>, +%% <<"downloads">> => 740,<<"has_docs">> => true, +%% <<"html_url">> => <<"https://hex.pm/packages/package/1.0.0">>, +%% <<"inserted_at">> => <<"2014-12-09T18:32:03Z">>, +%% <<"meta">> => +%% #{<<"app">> => <<"package">>, +%% <<"build_tools">> => [<<"mix">>]}, +%% <<"package_url">> => <<"https://hex.pm/api/packages/package">>, +%% <<"publisher">> => nil,<<"requirements">> => #{}, +%% <<"retirement">> => nil, +%% <<"updated_at">> => <<"2019-07-28T21:12:11Z">>, +%% <<"url">> => <<"https://hex.pm/api/packages/package/releases/1.0.0">>, +%% <<"version">> => <<"1.0.0">> +%% }}} +%% ''' +%% @end +-spec get(hex_core:config(), binary(), binary()) -> hex_api:response(). +get(Config, Name, Version) when is_map(Config) and is_binary(Name) and is_binary(Version) -> + Path = hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]), + hex_api:get(Config, Path). + +%% @doc +%% Publishes a new package release. +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:publish(hex_core:default_config(), Tarball). +%% {ok, {200, ..., #{ +%% <<"checksum">> => <<"540d210d81f56f17f64309a4896430e727972499b37bd59342dc08d61dff74d8">>, +%% <<"docs_html_url">> => <<"https://hexdocs.pm/package/1.0.0/">>, +%% <<"downloads">> => 740,<<"has_docs">> => true, +%% <<"html_url">> => <<"https://hex.pm/packages/package/1.0.0">>, +%% <<"inserted_at">> => <<"2014-12-09T18:32:03Z">>, +%% <<"meta">> => +%% #{<<"app">> => <<"package">>, +%% <<"build_tools">> => [<<"mix">>]}, +%% <<"package_url">> => <<"https://hex.pm/api/packages/package">>, +%% <<"publisher">> => nil,<<"requirements">> => #{}, +%% <<"retirement">> => nil, +%% <<"updated_at">> => <<"2019-07-28T21:12:11Z">>, +%% <<"url">> => <<"https://hex.pm/api/packages/package/releases/1.0.0">>, +%% <<"version">> => <<"1.0.0">> +%% }}} +%% ''' +%% @end +-spec publish(hex_core:config(), binary()) -> hex_api:response(). +publish(Config, Tarball) -> publish(Config, Tarball, []). + +%% @doc +%% Publishes a new package release with query parameters. +%% +%% Supported query params : +%% - replace : boolean +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:publish(hex_core:default_config(), Tarball, [{replace, true}]). +%% {ok, {201, ..., #{ +%% <<"checksum">> => <<"540d210d81f56f17f64309a4896430e727972499b37bd59342dc08d61dff74d8">>, +%% <<"docs_html_url">> => <<"https://hexdocs.pm/package/1.0.0/">>, +%% <<"downloads">> => 740,<<"has_docs">> => true, +%% <<"html_url">> => <<"https://hex.pm/packages/package/1.0.0">>, +%% <<"inserted_at">> => <<"2014-12-09T18:32:03Z">>, +%% <<"meta">> => +%% #{<<"app">> => <<"package">>, +%% <<"build_tools">> => [<<"mix">>]}, +%% <<"package_url">> => <<"https://hex.pm/api/packages/package">>, +%% <<"publisher">> => nil,<<"requirements">> => #{}, +%% <<"retirement">> => nil, +%% <<"updated_at">> => <<"2019-07-28T21:12:11Z">>, +%% <<"url">> => <<"https://hex.pm/api/packages/package/releases/1.0.0">>, +%% <<"version">> => <<"1.0.0">> +%% }}} +%% ''' +%% @end +-spec publish(hex_core:config(), binary(), publish_params()) -> hex_api:response(). +publish(Config, Tarball, Params) when + is_map(Config) andalso is_binary(Tarball) andalso is_list(Params) +-> + case hex_tarball:unpack(Tarball, memory) of + {ok, #{metadata := Metadata}} -> + PackageName = maps:get(<<"name">>, Metadata), + QueryString = hex_api:encode_query_string([ + {replace, proplists:get_value(replace, Params, false)} + ]), + Path = hex_api:join_path_segments( + hex_api:build_repository_path(Config, ["packages", PackageName, "releases"]) + ), + PathWithQuery = <>, + TarballContentType = "application/octet-stream", + Config2 = put_header( + <<"content-length">>, integer_to_binary(byte_size(Tarball)), Config + ), + Config3 = maybe_put_expect_header(Config2), + Body = {TarballContentType, Tarball}, + hex_api:post(Config3, PathWithQuery, Body); + {error, Reason} -> + {error, {tarball, Reason}} + end. + +%% @doc +%% Deletes a package release. +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:delete(hex_core:default_config(), <<"package">>, <<"1.0.0">>). +%% {ok, {204, ..., nil}} +%% ''' +%% @end +-spec delete(hex_core:config(), binary(), binary()) -> hex_api:response(). +delete(Config, Name, Version) when is_map(Config) and is_binary(Name) and is_binary(Version) -> + Path = hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]), + hex_api:delete(Config, Path). + +%% @doc +%% Retires a package release. +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:retire(hex_core:default_config(), <<"package">>, <<"1.0.0">>, Params). +%% {ok, {204, ..., nil}} +%% ''' +%% @end +-spec retire(hex_core:config(), binary(), binary(), retirement_params()) -> hex_api:response(). +retire(Config, Name, Version, Params) when + is_map(Config) and is_binary(Name) and is_binary(Version) +-> + Path = hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]), + hex_api:post(Config, Path, Params). + +%% @doc +%% Unretires a package release. +%% +%% Examples: +%% +%% ``` +%% > hex_api_release:unretire(hex_core:default_config(), <<"package">>, <<"1.0.0">>). +%% {ok, {204, ..., nil}} +%% ''' +%% @end +-spec unretire(hex_core:config(), binary(), binary()) -> hex_api:response(). +unretire(Config, Name, Version) when is_map(Config) and is_binary(Name) and is_binary(Version) -> + Path = hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]), + hex_api:delete(Config, Path). + +%%==================================================================== +%% Internal functions +%%==================================================================== + +%% @private +put_header(Name, Value, Config) -> + Headers = maps:get(http_headers, Config, #{}), + Headers2 = maps:put(Name, Value, Headers), + maps:put(http_headers, Headers2, Config). + +%% @private +maybe_put_expect_header(Config) -> + case maps:get(send_100_continue, Config, true) of + true -> put_header(<<"expect">>, <<"100-continue">>, Config); + false -> Config + end. diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_api_short_url.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_api_short_url.erl new file mode 100644 index 0000000000000000000000000000000000000000..dbc491e7211e17ba377e0817f4b1c05db475cff2 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_api_short_url.erl @@ -0,0 +1,19 @@ +%% @doc +%% Hex HTTP API - Short URLs. +-module(hex_api_short_url). +-export([create/2]). + +%% @doc +%% Creates a short URL. +%% +%% Examples: +%% +%% ``` +%% > hex_api_short_url:create(hex_core:default_config(), <<"https://hex.pm/packages/example">>). +%% {ok, {201, ..., #{<<"url">> => <<"https://hex.pm/l/XXXXX">>}}} +%% ''' +%% @end +-spec create(hex_core:config(), binary()) -> hex_api:response(). +create(Config, URL) when is_map(Config) and is_binary(URL) -> + Body = #{<<"url">> => URL}, + hex_api:post(Config, ["short_url"], Body). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_core.app.src b/deps/eini/_build/default/plugins/hex_core/src/hex_core.app.src new file mode 100644 index 0000000000000000000000000000000000000000..6fd710f9a15f92e343882d8ecfa09f0db3a62947 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_core.app.src @@ -0,0 +1,12 @@ +{application,hex_core, + [{description,"Reference implementation of Hex specifications"}, + {vsn,"0.12.2"}, + {registered,[]}, + {applications,[kernel,stdlib,inets,ssl]}, + {licenses,["Apache-2.0"]}, + {include_paths,["CHANGELOG.md"]}, + {exclude_paths,["src/safe_erl_term.erl"]}, + {links,[{"GitHub","https://github.com/hexpm/hex_core"}, + {"Hex specifications", + "https://github.com/hexpm/specifications"}]}, + {doc,"doc"}]}. diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_core.hrl b/deps/eini/_build/default/plugins/hex_core/src/hex_core.hrl new file mode 100644 index 0000000000000000000000000000000000000000..18d2a20330ce593729049ee1354fdad8845e5f14 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_core.hrl @@ -0,0 +1 @@ +-define(HEX_CORE_VERSION, "0.12.2"). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_filename.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_filename.erl new file mode 100644 index 0000000000000000000000000000000000000000..7ebd9d31ef493d2e6b8ee60d987973e2dac54a74 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_filename.erl @@ -0,0 +1,58 @@ +% @private +% Excerpt from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/filename.erl#L761-L788 +% with modifications for changing local function calls to remote function calls +% to the `filename` module, for the functions `pathtype/1`, `split/1`, and `join/1` +% +% safe_relative_path/1 was not present in earlier OTP releases. + +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2017. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +-module(hex_filename). +-export([safe_relative_path/1]). + +safe_relative_path(Path) -> + case filename:pathtype(Path) of + relative -> + Cs0 = filename:split(Path), + safe_relative_path_1(Cs0, []); + _ -> + unsafe + end. + +safe_relative_path_1(["." | T], Acc) -> + safe_relative_path_1(T, Acc); +safe_relative_path_1([<<".">> | T], Acc) -> + safe_relative_path_1(T, Acc); +safe_relative_path_1([".." | T], Acc) -> + climb(T, Acc); +safe_relative_path_1([<<"..">> | T], Acc) -> + climb(T, Acc); +safe_relative_path_1([H | T], Acc) -> + safe_relative_path_1(T, [H | Acc]); +safe_relative_path_1([], []) -> + []; +safe_relative_path_1([], Acc) -> + filename:join(lists:reverse(Acc)). + +climb(_, []) -> + unsafe; +climb(T, [_ | Acc]) -> + safe_relative_path_1(T, Acc). diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_licenses.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_licenses.erl new file mode 100644 index 0000000000000000000000000000000000000000..8ae50ec17acdee14ee6b1ee266e055495258ac5b --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_licenses.erl @@ -0,0 +1,668 @@ +%% @doc +%% Hex Licenses. +%% File generated by https://github.com/supersimple/spdx. Do not edit manually. + +-module(hex_licenses). + +-export([valid/1]). + +valid(<<"0BSD">>) -> true; +valid(<<"3D-Slicer-1.0">>) -> true; +valid(<<"AAL">>) -> true; +valid(<<"ADSL">>) -> true; +valid(<<"AFL-1.1">>) -> true; +valid(<<"AFL-1.2">>) -> true; +valid(<<"AFL-2.0">>) -> true; +valid(<<"AFL-2.1">>) -> true; +valid(<<"AFL-3.0">>) -> true; +valid(<<"AGPL-1.0">>) -> true; +valid(<<"AGPL-1.0-only">>) -> true; +valid(<<"AGPL-1.0-or-later">>) -> true; +valid(<<"AGPL-3.0">>) -> true; +valid(<<"AGPL-3.0-only">>) -> true; +valid(<<"AGPL-3.0-or-later">>) -> true; +valid(<<"AMD-newlib">>) -> true; +valid(<<"AMDPLPA">>) -> true; +valid(<<"AML">>) -> true; +valid(<<"AML-glslang">>) -> true; +valid(<<"AMPAS">>) -> true; +valid(<<"ANTLR-PD">>) -> true; +valid(<<"ANTLR-PD-fallback">>) -> true; +valid(<<"APAFML">>) -> true; +valid(<<"APL-1.0">>) -> true; +valid(<<"APSL-1.0">>) -> true; +valid(<<"APSL-1.1">>) -> true; +valid(<<"APSL-1.2">>) -> true; +valid(<<"APSL-2.0">>) -> true; +valid(<<"ASWF-Digital-Assets-1.0">>) -> true; +valid(<<"ASWF-Digital-Assets-1.1">>) -> true; +valid(<<"Abstyles">>) -> true; +valid(<<"AdaCore-doc">>) -> true; +valid(<<"Adobe-2006">>) -> true; +valid(<<"Adobe-Display-PostScript">>) -> true; +valid(<<"Adobe-Glyph">>) -> true; +valid(<<"Adobe-Utopia">>) -> true; +valid(<<"Afmparse">>) -> true; +valid(<<"Aladdin">>) -> true; +valid(<<"Apache-1.0">>) -> true; +valid(<<"Apache-1.1">>) -> true; +valid(<<"Apache-2.0">>) -> true; +valid(<<"App-s2p">>) -> true; +valid(<<"Arphic-1999">>) -> true; +valid(<<"Artistic-1.0">>) -> true; +valid(<<"Artistic-1.0-Perl">>) -> true; +valid(<<"Artistic-1.0-cl8">>) -> true; +valid(<<"Artistic-2.0">>) -> true; +valid(<<"BSD-1-Clause">>) -> true; +valid(<<"BSD-2-Clause">>) -> true; +valid(<<"BSD-2-Clause-Darwin">>) -> true; +valid(<<"BSD-2-Clause-FreeBSD">>) -> true; +valid(<<"BSD-2-Clause-NetBSD">>) -> true; +valid(<<"BSD-2-Clause-Patent">>) -> true; +valid(<<"BSD-2-Clause-Views">>) -> true; +valid(<<"BSD-2-Clause-first-lines">>) -> true; +valid(<<"BSD-3-Clause">>) -> true; +valid(<<"BSD-3-Clause-Attribution">>) -> true; +valid(<<"BSD-3-Clause-Clear">>) -> true; +valid(<<"BSD-3-Clause-HP">>) -> true; +valid(<<"BSD-3-Clause-LBNL">>) -> true; +valid(<<"BSD-3-Clause-Modification">>) -> true; +valid(<<"BSD-3-Clause-No-Military-License">>) -> true; +valid(<<"BSD-3-Clause-No-Nuclear-License">>) -> true; +valid(<<"BSD-3-Clause-No-Nuclear-License-2014">>) -> true; +valid(<<"BSD-3-Clause-No-Nuclear-Warranty">>) -> true; +valid(<<"BSD-3-Clause-Open-MPI">>) -> true; +valid(<<"BSD-3-Clause-Sun">>) -> true; +valid(<<"BSD-3-Clause-acpica">>) -> true; +valid(<<"BSD-3-Clause-flex">>) -> true; +valid(<<"BSD-4-Clause">>) -> true; +valid(<<"BSD-4-Clause-Shortened">>) -> true; +valid(<<"BSD-4-Clause-UC">>) -> true; +valid(<<"BSD-4.3RENO">>) -> true; +valid(<<"BSD-4.3TAHOE">>) -> true; +valid(<<"BSD-Advertising-Acknowledgement">>) -> true; +valid(<<"BSD-Attribution-HPND-disclaimer">>) -> true; +valid(<<"BSD-Inferno-Nettverk">>) -> true; +valid(<<"BSD-Protection">>) -> true; +valid(<<"BSD-Source-Code">>) -> true; +valid(<<"BSD-Source-beginning-file">>) -> true; +valid(<<"BSD-Systemics">>) -> true; +valid(<<"BSD-Systemics-W3Works">>) -> true; +valid(<<"BSL-1.0">>) -> true; +valid(<<"BUSL-1.1">>) -> true; +valid(<<"Baekmuk">>) -> true; +valid(<<"Bahyph">>) -> true; +valid(<<"Barr">>) -> true; +valid(<<"Beerware">>) -> true; +valid(<<"BitTorrent-1.0">>) -> true; +valid(<<"BitTorrent-1.1">>) -> true; +valid(<<"Bitstream-Charter">>) -> true; +valid(<<"Bitstream-Vera">>) -> true; +valid(<<"BlueOak-1.0.0">>) -> true; +valid(<<"Boehm-GC">>) -> true; +valid(<<"Borceux">>) -> true; +valid(<<"Brian-Gladman-2-Clause">>) -> true; +valid(<<"Brian-Gladman-3-Clause">>) -> true; +valid(<<"C-UDA-1.0">>) -> true; +valid(<<"CAL-1.0">>) -> true; +valid(<<"CAL-1.0-Combined-Work-Exception">>) -> true; +valid(<<"CATOSL-1.1">>) -> true; +valid(<<"CC-BY-1.0">>) -> true; +valid(<<"CC-BY-2.0">>) -> true; +valid(<<"CC-BY-2.5">>) -> true; +valid(<<"CC-BY-2.5-AU">>) -> true; +valid(<<"CC-BY-3.0">>) -> true; +valid(<<"CC-BY-3.0-AT">>) -> true; +valid(<<"CC-BY-3.0-AU">>) -> true; +valid(<<"CC-BY-3.0-DE">>) -> true; +valid(<<"CC-BY-3.0-IGO">>) -> true; +valid(<<"CC-BY-3.0-NL">>) -> true; +valid(<<"CC-BY-3.0-US">>) -> true; +valid(<<"CC-BY-4.0">>) -> true; +valid(<<"CC-BY-NC-1.0">>) -> true; +valid(<<"CC-BY-NC-2.0">>) -> true; +valid(<<"CC-BY-NC-2.5">>) -> true; +valid(<<"CC-BY-NC-3.0">>) -> true; +valid(<<"CC-BY-NC-3.0-DE">>) -> true; +valid(<<"CC-BY-NC-4.0">>) -> true; +valid(<<"CC-BY-NC-ND-1.0">>) -> true; +valid(<<"CC-BY-NC-ND-2.0">>) -> true; +valid(<<"CC-BY-NC-ND-2.5">>) -> true; +valid(<<"CC-BY-NC-ND-3.0">>) -> true; +valid(<<"CC-BY-NC-ND-3.0-DE">>) -> true; +valid(<<"CC-BY-NC-ND-3.0-IGO">>) -> true; +valid(<<"CC-BY-NC-ND-4.0">>) -> true; +valid(<<"CC-BY-NC-SA-1.0">>) -> true; +valid(<<"CC-BY-NC-SA-2.0">>) -> true; +valid(<<"CC-BY-NC-SA-2.0-DE">>) -> true; +valid(<<"CC-BY-NC-SA-2.0-FR">>) -> true; +valid(<<"CC-BY-NC-SA-2.0-UK">>) -> true; +valid(<<"CC-BY-NC-SA-2.5">>) -> true; +valid(<<"CC-BY-NC-SA-3.0">>) -> true; +valid(<<"CC-BY-NC-SA-3.0-DE">>) -> true; +valid(<<"CC-BY-NC-SA-3.0-IGO">>) -> true; +valid(<<"CC-BY-NC-SA-4.0">>) -> true; +valid(<<"CC-BY-ND-1.0">>) -> true; +valid(<<"CC-BY-ND-2.0">>) -> true; +valid(<<"CC-BY-ND-2.5">>) -> true; +valid(<<"CC-BY-ND-3.0">>) -> true; +valid(<<"CC-BY-ND-3.0-DE">>) -> true; +valid(<<"CC-BY-ND-4.0">>) -> true; +valid(<<"CC-BY-SA-1.0">>) -> true; +valid(<<"CC-BY-SA-2.0">>) -> true; +valid(<<"CC-BY-SA-2.0-UK">>) -> true; +valid(<<"CC-BY-SA-2.1-JP">>) -> true; +valid(<<"CC-BY-SA-2.5">>) -> true; +valid(<<"CC-BY-SA-3.0">>) -> true; +valid(<<"CC-BY-SA-3.0-AT">>) -> true; +valid(<<"CC-BY-SA-3.0-DE">>) -> true; +valid(<<"CC-BY-SA-3.0-IGO">>) -> true; +valid(<<"CC-BY-SA-4.0">>) -> true; +valid(<<"CC-PDDC">>) -> true; +valid(<<"CC0-1.0">>) -> true; +valid(<<"CDDL-1.0">>) -> true; +valid(<<"CDDL-1.1">>) -> true; +valid(<<"CDL-1.0">>) -> true; +valid(<<"CDLA-Permissive-1.0">>) -> true; +valid(<<"CDLA-Permissive-2.0">>) -> true; +valid(<<"CDLA-Sharing-1.0">>) -> true; +valid(<<"CECILL-1.0">>) -> true; +valid(<<"CECILL-1.1">>) -> true; +valid(<<"CECILL-2.0">>) -> true; +valid(<<"CECILL-2.1">>) -> true; +valid(<<"CECILL-B">>) -> true; +valid(<<"CECILL-C">>) -> true; +valid(<<"CERN-OHL-1.1">>) -> true; +valid(<<"CERN-OHL-1.2">>) -> true; +valid(<<"CERN-OHL-P-2.0">>) -> true; +valid(<<"CERN-OHL-S-2.0">>) -> true; +valid(<<"CERN-OHL-W-2.0">>) -> true; +valid(<<"CFITSIO">>) -> true; +valid(<<"CMU-Mach">>) -> true; +valid(<<"CMU-Mach-nodoc">>) -> true; +valid(<<"CNRI-Jython">>) -> true; +valid(<<"CNRI-Python">>) -> true; +valid(<<"CNRI-Python-GPL-Compatible">>) -> true; +valid(<<"COIL-1.0">>) -> true; +valid(<<"CPAL-1.0">>) -> true; +valid(<<"CPL-1.0">>) -> true; +valid(<<"CPOL-1.02">>) -> true; +valid(<<"CUA-OPL-1.0">>) -> true; +valid(<<"Caldera">>) -> true; +valid(<<"Caldera-no-preamble">>) -> true; +valid(<<"Catharon">>) -> true; +valid(<<"ClArtistic">>) -> true; +valid(<<"Clips">>) -> true; +valid(<<"Community-Spec-1.0">>) -> true; +valid(<<"Condor-1.1">>) -> true; +valid(<<"Cornell-Lossless-JPEG">>) -> true; +valid(<<"Cronyx">>) -> true; +valid(<<"Crossword">>) -> true; +valid(<<"CrystalStacker">>) -> true; +valid(<<"Cube">>) -> true; +valid(<<"D-FSL-1.0">>) -> true; +valid(<<"DEC-3-Clause">>) -> true; +valid(<<"DL-DE-BY-2.0">>) -> true; +valid(<<"DL-DE-ZERO-2.0">>) -> true; +valid(<<"DOC">>) -> true; +valid(<<"DRL-1.0">>) -> true; +valid(<<"DRL-1.1">>) -> true; +valid(<<"DSDP">>) -> true; +valid(<<"Dotseqn">>) -> true; +valid(<<"ECL-1.0">>) -> true; +valid(<<"ECL-2.0">>) -> true; +valid(<<"EFL-1.0">>) -> true; +valid(<<"EFL-2.0">>) -> true; +valid(<<"EPICS">>) -> true; +valid(<<"EPL-1.0">>) -> true; +valid(<<"EPL-2.0">>) -> true; +valid(<<"EUDatagrid">>) -> true; +valid(<<"EUPL-1.0">>) -> true; +valid(<<"EUPL-1.1">>) -> true; +valid(<<"EUPL-1.2">>) -> true; +valid(<<"Elastic-2.0">>) -> true; +valid(<<"Entessa">>) -> true; +valid(<<"ErlPL-1.1">>) -> true; +valid(<<"Eurosym">>) -> true; +valid(<<"FBM">>) -> true; +valid(<<"FDK-AAC">>) -> true; +valid(<<"FSFAP">>) -> true; +valid(<<"FSFAP-no-warranty-disclaimer">>) -> true; +valid(<<"FSFUL">>) -> true; +valid(<<"FSFULLR">>) -> true; +valid(<<"FSFULLRWD">>) -> true; +valid(<<"FTL">>) -> true; +valid(<<"Fair">>) -> true; +valid(<<"Ferguson-Twofish">>) -> true; +valid(<<"Frameworx-1.0">>) -> true; +valid(<<"FreeBSD-DOC">>) -> true; +valid(<<"FreeImage">>) -> true; +valid(<<"Furuseth">>) -> true; +valid(<<"GCR-docs">>) -> true; +valid(<<"GD">>) -> true; +valid(<<"GFDL-1.1">>) -> true; +valid(<<"GFDL-1.1-invariants-only">>) -> true; +valid(<<"GFDL-1.1-invariants-or-later">>) -> true; +valid(<<"GFDL-1.1-no-invariants-only">>) -> true; +valid(<<"GFDL-1.1-no-invariants-or-later">>) -> true; +valid(<<"GFDL-1.1-only">>) -> true; +valid(<<"GFDL-1.1-or-later">>) -> true; +valid(<<"GFDL-1.2">>) -> true; +valid(<<"GFDL-1.2-invariants-only">>) -> true; +valid(<<"GFDL-1.2-invariants-or-later">>) -> true; +valid(<<"GFDL-1.2-no-invariants-only">>) -> true; +valid(<<"GFDL-1.2-no-invariants-or-later">>) -> true; +valid(<<"GFDL-1.2-only">>) -> true; +valid(<<"GFDL-1.2-or-later">>) -> true; +valid(<<"GFDL-1.3">>) -> true; +valid(<<"GFDL-1.3-invariants-only">>) -> true; +valid(<<"GFDL-1.3-invariants-or-later">>) -> true; +valid(<<"GFDL-1.3-no-invariants-only">>) -> true; +valid(<<"GFDL-1.3-no-invariants-or-later">>) -> true; +valid(<<"GFDL-1.3-only">>) -> true; +valid(<<"GFDL-1.3-or-later">>) -> true; +valid(<<"GL2PS">>) -> true; +valid(<<"GLWTPL">>) -> true; +valid(<<"GPL-1.0">>) -> true; +valid(<<"GPL-1.0+">>) -> true; +valid(<<"GPL-1.0-only">>) -> true; +valid(<<"GPL-1.0-or-later">>) -> true; +valid(<<"GPL-2.0">>) -> true; +valid(<<"GPL-2.0+">>) -> true; +valid(<<"GPL-2.0-only">>) -> true; +valid(<<"GPL-2.0-or-later">>) -> true; +valid(<<"GPL-2.0-with-GCC-exception">>) -> true; +valid(<<"GPL-2.0-with-autoconf-exception">>) -> true; +valid(<<"GPL-2.0-with-bison-exception">>) -> true; +valid(<<"GPL-2.0-with-classpath-exception">>) -> true; +valid(<<"GPL-2.0-with-font-exception">>) -> true; +valid(<<"GPL-3.0">>) -> true; +valid(<<"GPL-3.0+">>) -> true; +valid(<<"GPL-3.0-only">>) -> true; +valid(<<"GPL-3.0-or-later">>) -> true; +valid(<<"GPL-3.0-with-GCC-exception">>) -> true; +valid(<<"GPL-3.0-with-autoconf-exception">>) -> true; +valid(<<"Giftware">>) -> true; +valid(<<"Glide">>) -> true; +valid(<<"Glulxe">>) -> true; +valid(<<"Graphics-Gems">>) -> true; +valid(<<"Gutmann">>) -> true; +valid(<<"HP-1986">>) -> true; +valid(<<"HP-1989">>) -> true; +valid(<<"HPND">>) -> true; +valid(<<"HPND-DEC">>) -> true; +valid(<<"HPND-Fenneberg-Livingston">>) -> true; +valid(<<"HPND-INRIA-IMAG">>) -> true; +valid(<<"HPND-Intel">>) -> true; +valid(<<"HPND-Kevlin-Henney">>) -> true; +valid(<<"HPND-MIT-disclaimer">>) -> true; +valid(<<"HPND-Markus-Kuhn">>) -> true; +valid(<<"HPND-Pbmplus">>) -> true; +valid(<<"HPND-UC">>) -> true; +valid(<<"HPND-UC-export-US">>) -> true; +valid(<<"HPND-doc">>) -> true; +valid(<<"HPND-doc-sell">>) -> true; +valid(<<"HPND-export-US">>) -> true; +valid(<<"HPND-export-US-acknowledgement">>) -> true; +valid(<<"HPND-export-US-modify">>) -> true; +valid(<<"HPND-export2-US">>) -> true; +valid(<<"HPND-merchantability-variant">>) -> true; +valid(<<"HPND-sell-MIT-disclaimer-xserver">>) -> true; +valid(<<"HPND-sell-regexpr">>) -> true; +valid(<<"HPND-sell-variant">>) -> true; +valid(<<"HPND-sell-variant-MIT-disclaimer">>) -> true; +valid(<<"HPND-sell-variant-MIT-disclaimer-rev">>) -> true; +valid(<<"HTMLTIDY">>) -> true; +valid(<<"HaskellReport">>) -> true; +valid(<<"Hippocratic-2.1">>) -> true; +valid(<<"IBM-pibs">>) -> true; +valid(<<"ICU">>) -> true; +valid(<<"IEC-Code-Components-EULA">>) -> true; +valid(<<"IJG">>) -> true; +valid(<<"IJG-short">>) -> true; +valid(<<"IPA">>) -> true; +valid(<<"IPL-1.0">>) -> true; +valid(<<"ISC">>) -> true; +valid(<<"ISC-Veillard">>) -> true; +valid(<<"ImageMagick">>) -> true; +valid(<<"Imlib2">>) -> true; +valid(<<"Info-ZIP">>) -> true; +valid(<<"Inner-Net-2.0">>) -> true; +valid(<<"Intel">>) -> true; +valid(<<"Intel-ACPI">>) -> true; +valid(<<"Interbase-1.0">>) -> true; +valid(<<"JPL-image">>) -> true; +valid(<<"JPNIC">>) -> true; +valid(<<"JSON">>) -> true; +valid(<<"Jam">>) -> true; +valid(<<"JasPer-2.0">>) -> true; +valid(<<"Kastrup">>) -> true; +valid(<<"Kazlib">>) -> true; +valid(<<"Knuth-CTAN">>) -> true; +valid(<<"LAL-1.2">>) -> true; +valid(<<"LAL-1.3">>) -> true; +valid(<<"LGPL-2.0">>) -> true; +valid(<<"LGPL-2.0+">>) -> true; +valid(<<"LGPL-2.0-only">>) -> true; +valid(<<"LGPL-2.0-or-later">>) -> true; +valid(<<"LGPL-2.1">>) -> true; +valid(<<"LGPL-2.1+">>) -> true; +valid(<<"LGPL-2.1-only">>) -> true; +valid(<<"LGPL-2.1-or-later">>) -> true; +valid(<<"LGPL-3.0">>) -> true; +valid(<<"LGPL-3.0+">>) -> true; +valid(<<"LGPL-3.0-only">>) -> true; +valid(<<"LGPL-3.0-or-later">>) -> true; +valid(<<"LGPLLR">>) -> true; +valid(<<"LOOP">>) -> true; +valid(<<"LPD-document">>) -> true; +valid(<<"LPL-1.0">>) -> true; +valid(<<"LPL-1.02">>) -> true; +valid(<<"LPPL-1.0">>) -> true; +valid(<<"LPPL-1.1">>) -> true; +valid(<<"LPPL-1.2">>) -> true; +valid(<<"LPPL-1.3a">>) -> true; +valid(<<"LPPL-1.3c">>) -> true; +valid(<<"LZMA-SDK-9.11-to-9.20">>) -> true; +valid(<<"LZMA-SDK-9.22">>) -> true; +valid(<<"Latex2e">>) -> true; +valid(<<"Latex2e-translated-notice">>) -> true; +valid(<<"Leptonica">>) -> true; +valid(<<"LiLiQ-P-1.1">>) -> true; +valid(<<"LiLiQ-R-1.1">>) -> true; +valid(<<"LiLiQ-Rplus-1.1">>) -> true; +valid(<<"Libpng">>) -> true; +valid(<<"Linux-OpenIB">>) -> true; +valid(<<"Linux-man-pages-1-para">>) -> true; +valid(<<"Linux-man-pages-copyleft">>) -> true; +valid(<<"Linux-man-pages-copyleft-2-para">>) -> true; +valid(<<"Linux-man-pages-copyleft-var">>) -> true; +valid(<<"Lucida-Bitmap-Fonts">>) -> true; +valid(<<"MIT">>) -> true; +valid(<<"MIT-0">>) -> true; +valid(<<"MIT-CMU">>) -> true; +valid(<<"MIT-Festival">>) -> true; +valid(<<"MIT-Khronos-old">>) -> true; +valid(<<"MIT-Modern-Variant">>) -> true; +valid(<<"MIT-Wu">>) -> true; +valid(<<"MIT-advertising">>) -> true; +valid(<<"MIT-enna">>) -> true; +valid(<<"MIT-feh">>) -> true; +valid(<<"MIT-open-group">>) -> true; +valid(<<"MIT-testregex">>) -> true; +valid(<<"MITNFA">>) -> true; +valid(<<"MMIXware">>) -> true; +valid(<<"MPEG-SSG">>) -> true; +valid(<<"MPL-1.0">>) -> true; +valid(<<"MPL-1.1">>) -> true; +valid(<<"MPL-2.0">>) -> true; +valid(<<"MPL-2.0-no-copyleft-exception">>) -> true; +valid(<<"MS-LPL">>) -> true; +valid(<<"MS-PL">>) -> true; +valid(<<"MS-RL">>) -> true; +valid(<<"MTLL">>) -> true; +valid(<<"Mackerras-3-Clause">>) -> true; +valid(<<"Mackerras-3-Clause-acknowledgment">>) -> true; +valid(<<"MakeIndex">>) -> true; +valid(<<"Martin-Birgmeier">>) -> true; +valid(<<"McPhee-slideshow">>) -> true; +valid(<<"Minpack">>) -> true; +valid(<<"MirOS">>) -> true; +valid(<<"Motosoto">>) -> true; +valid(<<"MulanPSL-1.0">>) -> true; +valid(<<"MulanPSL-2.0">>) -> true; +valid(<<"Multics">>) -> true; +valid(<<"Mup">>) -> true; +valid(<<"NAIST-2003">>) -> true; +valid(<<"NASA-1.3">>) -> true; +valid(<<"NBPL-1.0">>) -> true; +valid(<<"NCBI-PD">>) -> true; +valid(<<"NCGL-UK-2.0">>) -> true; +valid(<<"NCL">>) -> true; +valid(<<"NCSA">>) -> true; +valid(<<"NGPL">>) -> true; +valid(<<"NICTA-1.0">>) -> true; +valid(<<"NIST-PD">>) -> true; +valid(<<"NIST-PD-fallback">>) -> true; +valid(<<"NIST-Software">>) -> true; +valid(<<"NLOD-1.0">>) -> true; +valid(<<"NLOD-2.0">>) -> true; +valid(<<"NLPL">>) -> true; +valid(<<"NOSL">>) -> true; +valid(<<"NPL-1.0">>) -> true; +valid(<<"NPL-1.1">>) -> true; +valid(<<"NPOSL-3.0">>) -> true; +valid(<<"NRL">>) -> true; +valid(<<"NTP">>) -> true; +valid(<<"NTP-0">>) -> true; +valid(<<"Naumen">>) -> true; +valid(<<"Net-SNMP">>) -> true; +valid(<<"NetCDF">>) -> true; +valid(<<"Newsletr">>) -> true; +valid(<<"Nokia">>) -> true; +valid(<<"Noweb">>) -> true; +valid(<<"Nunit">>) -> true; +valid(<<"O-UDA-1.0">>) -> true; +valid(<<"OAR">>) -> true; +valid(<<"OCCT-PL">>) -> true; +valid(<<"OCLC-2.0">>) -> true; +valid(<<"ODC-By-1.0">>) -> true; +valid(<<"ODbL-1.0">>) -> true; +valid(<<"OFFIS">>) -> true; +valid(<<"OFL-1.0">>) -> true; +valid(<<"OFL-1.0-RFN">>) -> true; +valid(<<"OFL-1.0-no-RFN">>) -> true; +valid(<<"OFL-1.1">>) -> true; +valid(<<"OFL-1.1-RFN">>) -> true; +valid(<<"OFL-1.1-no-RFN">>) -> true; +valid(<<"OGC-1.0">>) -> true; +valid(<<"OGDL-Taiwan-1.0">>) -> true; +valid(<<"OGL-Canada-2.0">>) -> true; +valid(<<"OGL-UK-1.0">>) -> true; +valid(<<"OGL-UK-2.0">>) -> true; +valid(<<"OGL-UK-3.0">>) -> true; +valid(<<"OGTSL">>) -> true; +valid(<<"OLDAP-1.1">>) -> true; +valid(<<"OLDAP-1.2">>) -> true; +valid(<<"OLDAP-1.3">>) -> true; +valid(<<"OLDAP-1.4">>) -> true; +valid(<<"OLDAP-2.0">>) -> true; +valid(<<"OLDAP-2.0.1">>) -> true; +valid(<<"OLDAP-2.1">>) -> true; +valid(<<"OLDAP-2.2">>) -> true; +valid(<<"OLDAP-2.2.1">>) -> true; +valid(<<"OLDAP-2.2.2">>) -> true; +valid(<<"OLDAP-2.3">>) -> true; +valid(<<"OLDAP-2.4">>) -> true; +valid(<<"OLDAP-2.5">>) -> true; +valid(<<"OLDAP-2.6">>) -> true; +valid(<<"OLDAP-2.7">>) -> true; +valid(<<"OLDAP-2.8">>) -> true; +valid(<<"OLFL-1.3">>) -> true; +valid(<<"OML">>) -> true; +valid(<<"OPL-1.0">>) -> true; +valid(<<"OPL-UK-3.0">>) -> true; +valid(<<"OPUBL-1.0">>) -> true; +valid(<<"OSET-PL-2.1">>) -> true; +valid(<<"OSL-1.0">>) -> true; +valid(<<"OSL-1.1">>) -> true; +valid(<<"OSL-2.0">>) -> true; +valid(<<"OSL-2.1">>) -> true; +valid(<<"OSL-3.0">>) -> true; +valid(<<"OpenPBS-2.3">>) -> true; +valid(<<"OpenSSL">>) -> true; +valid(<<"OpenSSL-standalone">>) -> true; +valid(<<"OpenVision">>) -> true; +valid(<<"PADL">>) -> true; +valid(<<"PDDL-1.0">>) -> true; +valid(<<"PHP-3.0">>) -> true; +valid(<<"PHP-3.01">>) -> true; +valid(<<"PPL">>) -> true; +valid(<<"PSF-2.0">>) -> true; +valid(<<"Parity-6.0.0">>) -> true; +valid(<<"Parity-7.0.0">>) -> true; +valid(<<"Pixar">>) -> true; +valid(<<"Plexus">>) -> true; +valid(<<"PolyForm-Noncommercial-1.0.0">>) -> true; +valid(<<"PolyForm-Small-Business-1.0.0">>) -> true; +valid(<<"PostgreSQL">>) -> true; +valid(<<"Python-2.0">>) -> true; +valid(<<"Python-2.0.1">>) -> true; +valid(<<"QPL-1.0">>) -> true; +valid(<<"QPL-1.0-INRIA-2004">>) -> true; +valid(<<"Qhull">>) -> true; +valid(<<"RHeCos-1.1">>) -> true; +valid(<<"RPL-1.1">>) -> true; +valid(<<"RPL-1.5">>) -> true; +valid(<<"RPSL-1.0">>) -> true; +valid(<<"RSA-MD">>) -> true; +valid(<<"RSCPL">>) -> true; +valid(<<"Rdisc">>) -> true; +valid(<<"Ruby">>) -> true; +valid(<<"SAX-PD">>) -> true; +valid(<<"SAX-PD-2.0">>) -> true; +valid(<<"SCEA">>) -> true; +valid(<<"SGI-B-1.0">>) -> true; +valid(<<"SGI-B-1.1">>) -> true; +valid(<<"SGI-B-2.0">>) -> true; +valid(<<"SGI-OpenGL">>) -> true; +valid(<<"SGP4">>) -> true; +valid(<<"SHL-0.5">>) -> true; +valid(<<"SHL-0.51">>) -> true; +valid(<<"SISSL">>) -> true; +valid(<<"SISSL-1.2">>) -> true; +valid(<<"SL">>) -> true; +valid(<<"SMLNJ">>) -> true; +valid(<<"SMPPL">>) -> true; +valid(<<"SNIA">>) -> true; +valid(<<"SPL-1.0">>) -> true; +valid(<<"SSH-OpenSSH">>) -> true; +valid(<<"SSH-short">>) -> true; +valid(<<"SSLeay-standalone">>) -> true; +valid(<<"SSPL-1.0">>) -> true; +valid(<<"SWL">>) -> true; +valid(<<"Saxpath">>) -> true; +valid(<<"SchemeReport">>) -> true; +valid(<<"Sendmail">>) -> true; +valid(<<"Sendmail-8.23">>) -> true; +valid(<<"SimPL-2.0">>) -> true; +valid(<<"Sleepycat">>) -> true; +valid(<<"Soundex">>) -> true; +valid(<<"Spencer-86">>) -> true; +valid(<<"Spencer-94">>) -> true; +valid(<<"Spencer-99">>) -> true; +valid(<<"StandardML-NJ">>) -> true; +valid(<<"SugarCRM-1.1.3">>) -> true; +valid(<<"Sun-PPP">>) -> true; +valid(<<"Sun-PPP-2000">>) -> true; +valid(<<"SunPro">>) -> true; +valid(<<"Symlinks">>) -> true; +valid(<<"TAPR-OHL-1.0">>) -> true; +valid(<<"TCL">>) -> true; +valid(<<"TCP-wrappers">>) -> true; +valid(<<"TGPPL-1.0">>) -> true; +valid(<<"TMate">>) -> true; +valid(<<"TORQUE-1.1">>) -> true; +valid(<<"TOSL">>) -> true; +valid(<<"TPDL">>) -> true; +valid(<<"TPL-1.0">>) -> true; +valid(<<"TTWL">>) -> true; +valid(<<"TTYP0">>) -> true; +valid(<<"TU-Berlin-1.0">>) -> true; +valid(<<"TU-Berlin-2.0">>) -> true; +valid(<<"TermReadKey">>) -> true; +valid(<<"UCAR">>) -> true; +valid(<<"UCL-1.0">>) -> true; +valid(<<"UMich-Merit">>) -> true; +valid(<<"UPL-1.0">>) -> true; +valid(<<"URT-RLE">>) -> true; +valid(<<"Unicode-3.0">>) -> true; +valid(<<"Unicode-DFS-2015">>) -> true; +valid(<<"Unicode-DFS-2016">>) -> true; +valid(<<"Unicode-TOU">>) -> true; +valid(<<"UnixCrypt">>) -> true; +valid(<<"Unlicense">>) -> true; +valid(<<"VOSTROM">>) -> true; +valid(<<"VSL-1.0">>) -> true; +valid(<<"Vim">>) -> true; +valid(<<"W3C">>) -> true; +valid(<<"W3C-19980720">>) -> true; +valid(<<"W3C-20150513">>) -> true; +valid(<<"WTFPL">>) -> true; +valid(<<"Watcom-1.0">>) -> true; +valid(<<"Widget-Workshop">>) -> true; +valid(<<"Wsuipa">>) -> true; +valid(<<"X11">>) -> true; +valid(<<"X11-distribute-modifications-variant">>) -> true; +valid(<<"XFree86-1.1">>) -> true; +valid(<<"XSkat">>) -> true; +valid(<<"Xdebug-1.03">>) -> true; +valid(<<"Xerox">>) -> true; +valid(<<"Xfig">>) -> true; +valid(<<"Xnet">>) -> true; +valid(<<"YPL-1.0">>) -> true; +valid(<<"YPL-1.1">>) -> true; +valid(<<"ZPL-1.1">>) -> true; +valid(<<"ZPL-2.0">>) -> true; +valid(<<"ZPL-2.1">>) -> true; +valid(<<"Zed">>) -> true; +valid(<<"Zeeff">>) -> true; +valid(<<"Zend-2.0">>) -> true; +valid(<<"Zimbra-1.3">>) -> true; +valid(<<"Zimbra-1.4">>) -> true; +valid(<<"Zlib">>) -> true; +valid(<<"any-OSI">>) -> true; +valid(<<"bcrypt-Solar-Designer">>) -> true; +valid(<<"blessing">>) -> true; +valid(<<"bzip2-1.0.5">>) -> true; +valid(<<"bzip2-1.0.6">>) -> true; +valid(<<"check-cvs">>) -> true; +valid(<<"checkmk">>) -> true; +valid(<<"copyleft-next-0.3.0">>) -> true; +valid(<<"copyleft-next-0.3.1">>) -> true; +valid(<<"curl">>) -> true; +valid(<<"cve-tou">>) -> true; +valid(<<"diffmark">>) -> true; +valid(<<"dtoa">>) -> true; +valid(<<"dvipdfm">>) -> true; +valid(<<"eCos-2.0">>) -> true; +valid(<<"eGenix">>) -> true; +valid(<<"etalab-2.0">>) -> true; +valid(<<"fwlw">>) -> true; +valid(<<"gSOAP-1.3b">>) -> true; +valid(<<"gnuplot">>) -> true; +valid(<<"gtkbook">>) -> true; +valid(<<"hdparm">>) -> true; +valid(<<"iMatix">>) -> true; +valid(<<"libpng-2.0">>) -> true; +valid(<<"libselinux-1.0">>) -> true; +valid(<<"libtiff">>) -> true; +valid(<<"libutil-David-Nugent">>) -> true; +valid(<<"lsof">>) -> true; +valid(<<"magaz">>) -> true; +valid(<<"mailprio">>) -> true; +valid(<<"metamail">>) -> true; +valid(<<"mpi-permissive">>) -> true; +valid(<<"mpich2">>) -> true; +valid(<<"mplus">>) -> true; +valid(<<"pkgconf">>) -> true; +valid(<<"pnmstitch">>) -> true; +valid(<<"psfrag">>) -> true; +valid(<<"psutils">>) -> true; +valid(<<"python-ldap">>) -> true; +valid(<<"radvd">>) -> true; +valid(<<"snprintf">>) -> true; +valid(<<"softSurfer">>) -> true; +valid(<<"ssh-keyscan">>) -> true; +valid(<<"swrule">>) -> true; +valid(<<"threeparttable">>) -> true; +valid(<<"ulem">>) -> true; +valid(<<"w3m">>) -> true; +valid(<<"wxWindows">>) -> true; +valid(<<"xinetd">>) -> true; +valid(<<"xkeyboard-config-Zinoviev">>) -> true; +valid(<<"xlock">>) -> true; +valid(<<"xpp">>) -> true; +valid(<<"xzoom">>) -> true; +valid(<<"zlib-acknowledgement">>) -> true; +valid(_) -> false. diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_pb_package.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_package.erl new file mode 100644 index 0000000000000000000000000000000000000000..4a8516f65ce43bd9dadf8c0a0738a61280e14ed2 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_package.erl @@ -0,0 +1,1227 @@ +%% -*- coding: utf-8 -*- +%% % this file is @generated +%% @private +%% Automatically generated, do not edit +%% Generated by gpb_compile version 4.21.1 +%% Version source: file +-module(hex_pb_package). + +-export([encode_msg/2, encode_msg/3]). +-export([decode_msg/2, decode_msg/3]). +-export([merge_msgs/3, merge_msgs/4]). +-export([verify_msg/2, verify_msg/3]). +-export([get_msg_defs/0]). +-export([get_msg_names/0]). +-export([get_group_names/0]). +-export([get_msg_or_group_names/0]). +-export([get_enum_names/0]). +-export([find_msg_def/1, fetch_msg_def/1]). +-export([find_enum_def/1, fetch_enum_def/1]). +-export([enum_symbol_by_value/2, enum_value_by_symbol/2]). +-export([enum_symbol_by_value_RetirementReason/1, enum_value_by_symbol_RetirementReason/1]). +-export([get_service_names/0]). +-export([get_service_def/1]). +-export([get_rpc_names/1]). +-export([find_rpc_def/2, fetch_rpc_def/2]). +-export([fqbin_to_service_name/1]). +-export([service_name_to_fqbin/1]). +-export([fqbins_to_service_and_rpc_name/2]). +-export([service_and_rpc_name_to_fqbins/2]). +-export([fqbin_to_msg_name/1]). +-export([msg_name_to_fqbin/1]). +-export([fqbin_to_enum_name/1]). +-export([enum_name_to_fqbin/1]). +-export([get_package_name/0]). +-export([uses_packages/0]). +-export([source_basename/0]). +-export([get_all_source_basenames/0]). +-export([get_all_proto_names/0]). +-export([get_msg_containment/1]). +-export([get_pkg_containment/1]). +-export([get_service_containment/1]). +-export([get_rpc_containment/1]). +-export([get_enum_containment/1]). +-export([get_proto_by_msg_name_as_fqbin/1]). +-export([get_proto_by_service_name_as_fqbin/1]). +-export([get_proto_by_enum_name_as_fqbin/1]). +-export([get_protos_by_pkg_name_as_fqbin/1]). +-export([gpb_version_as_string/0, gpb_version_as_list/0]). +-export([gpb_version_source/0]). + + +%% enumerated types +-type 'RetirementReason'() :: 'RETIRED_OTHER' | 'RETIRED_INVALID' | 'RETIRED_SECURITY' | 'RETIRED_DEPRECATED' | 'RETIRED_RENAMED'. +-export_type(['RetirementReason'/0]). + +%% message types +-type 'Package'() :: + #{releases => ['Release'()], % = 1, repeated + name => unicode:chardata(), % = 2, required + repository => unicode:chardata() % = 3, required + }. + +-type 'Release'() :: + #{version => unicode:chardata(), % = 1, required + inner_checksum => iodata(), % = 2, required + dependencies => ['Dependency'()], % = 3, repeated + retired => 'RetirementStatus'(), % = 4, optional + outer_checksum => iodata() % = 5, optional + }. + +-type 'RetirementStatus'() :: + #{reason => 'RETIRED_OTHER' | 'RETIRED_INVALID' | 'RETIRED_SECURITY' | 'RETIRED_DEPRECATED' | 'RETIRED_RENAMED' | integer(), % = 1, required, enum RetirementReason + message => unicode:chardata() % = 2, optional + }. + +-type 'Dependency'() :: + #{package => unicode:chardata(), % = 1, required + requirement => unicode:chardata(), % = 2, required + optional => boolean() | 0 | 1, % = 3, optional + app => unicode:chardata(), % = 4, optional + repository => unicode:chardata() % = 5, optional + }. + +-export_type(['Package'/0, 'Release'/0, 'RetirementStatus'/0, 'Dependency'/0]). +-type '$msg_name'() :: 'Package' | 'Release' | 'RetirementStatus' | 'Dependency'. +-type '$msg'() :: 'Package'() | 'Release'() | 'RetirementStatus'() | 'Dependency'(). +-export_type(['$msg_name'/0, '$msg'/0]). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/2}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'()) -> binary(). +encode_msg(Msg, MsgName) when is_atom(MsgName) -> encode_msg(Msg, MsgName, []). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/3}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'(), list()) -> binary(). +encode_msg(Msg, MsgName, Opts) -> + verify_msg(Msg, MsgName, Opts), + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Package' -> encode_msg_Package(id(Msg, TrUserData), TrUserData); + 'Release' -> encode_msg_Release(id(Msg, TrUserData), TrUserData); + 'RetirementStatus' -> encode_msg_RetirementStatus(id(Msg, TrUserData), TrUserData); + 'Dependency' -> encode_msg_Dependency(id(Msg, TrUserData), TrUserData) + end. + + +encode_msg_Package(Msg, TrUserData) -> encode_msg_Package(Msg, <<>>, TrUserData). + + +encode_msg_Package(#{name := F2, repository := F3} = M, Bin, TrUserData) -> + B1 = case M of + #{releases := F1} -> + TrF1 = id(F1, TrUserData), + if TrF1 == [] -> Bin; + true -> e_field_Package_releases(TrF1, Bin, TrUserData) + end; + _ -> Bin + end, + B2 = begin TrF2 = id(F2, TrUserData), e_type_string(TrF2, <>, TrUserData) end, + begin TrF3 = id(F3, TrUserData), e_type_string(TrF3, <>, TrUserData) end. + +encode_msg_Release(Msg, TrUserData) -> encode_msg_Release(Msg, <<>>, TrUserData). + + +encode_msg_Release(#{version := F1, inner_checksum := F2} = M, Bin, TrUserData) -> + B1 = begin TrF1 = id(F1, TrUserData), e_type_string(TrF1, <>, TrUserData) end, + B2 = begin TrF2 = id(F2, TrUserData), e_type_bytes(TrF2, <>, TrUserData) end, + B3 = case M of + #{dependencies := F3} -> + TrF3 = id(F3, TrUserData), + if TrF3 == [] -> B2; + true -> e_field_Release_dependencies(TrF3, B2, TrUserData) + end; + _ -> B2 + end, + B4 = case M of + #{retired := F4} -> begin TrF4 = id(F4, TrUserData), e_mfield_Release_retired(TrF4, <>, TrUserData) end; + _ -> B3 + end, + case M of + #{outer_checksum := F5} -> begin TrF5 = id(F5, TrUserData), e_type_bytes(TrF5, <>, TrUserData) end; + _ -> B4 + end. + +encode_msg_RetirementStatus(Msg, TrUserData) -> encode_msg_RetirementStatus(Msg, <<>>, TrUserData). + + +encode_msg_RetirementStatus(#{reason := F1} = M, Bin, TrUserData) -> + B1 = begin TrF1 = id(F1, TrUserData), e_enum_RetirementReason(TrF1, <>, TrUserData) end, + case M of + #{message := F2} -> begin TrF2 = id(F2, TrUserData), e_type_string(TrF2, <>, TrUserData) end; + _ -> B1 + end. + +encode_msg_Dependency(Msg, TrUserData) -> encode_msg_Dependency(Msg, <<>>, TrUserData). + + +encode_msg_Dependency(#{package := F1, requirement := F2} = M, Bin, TrUserData) -> + B1 = begin TrF1 = id(F1, TrUserData), e_type_string(TrF1, <>, TrUserData) end, + B2 = begin TrF2 = id(F2, TrUserData), e_type_string(TrF2, <>, TrUserData) end, + B3 = case M of + #{optional := F3} -> begin TrF3 = id(F3, TrUserData), e_type_bool(TrF3, <>, TrUserData) end; + _ -> B2 + end, + B4 = case M of + #{app := F4} -> begin TrF4 = id(F4, TrUserData), e_type_string(TrF4, <>, TrUserData) end; + _ -> B3 + end, + case M of + #{repository := F5} -> begin TrF5 = id(F5, TrUserData), e_type_string(TrF5, <>, TrUserData) end; + _ -> B4 + end. + +e_mfield_Package_releases(Msg, Bin, TrUserData) -> + SubBin = encode_msg_Release(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_field_Package_releases([Elem | Rest], Bin, TrUserData) -> + Bin2 = <>, + Bin3 = e_mfield_Package_releases(id(Elem, TrUserData), Bin2, TrUserData), + e_field_Package_releases(Rest, Bin3, TrUserData); +e_field_Package_releases([], Bin, _TrUserData) -> Bin. + +e_mfield_Release_dependencies(Msg, Bin, TrUserData) -> + SubBin = encode_msg_Dependency(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_field_Release_dependencies([Elem | Rest], Bin, TrUserData) -> + Bin2 = <>, + Bin3 = e_mfield_Release_dependencies(id(Elem, TrUserData), Bin2, TrUserData), + e_field_Release_dependencies(Rest, Bin3, TrUserData); +e_field_Release_dependencies([], Bin, _TrUserData) -> Bin. + +e_mfield_Release_retired(Msg, Bin, TrUserData) -> + SubBin = encode_msg_RetirementStatus(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_enum_RetirementReason('RETIRED_OTHER', Bin, _TrUserData) -> <>; +e_enum_RetirementReason('RETIRED_INVALID', Bin, _TrUserData) -> <>; +e_enum_RetirementReason('RETIRED_SECURITY', Bin, _TrUserData) -> <>; +e_enum_RetirementReason('RETIRED_DEPRECATED', Bin, _TrUserData) -> <>; +e_enum_RetirementReason('RETIRED_RENAMED', Bin, _TrUserData) -> <>; +e_enum_RetirementReason(V, Bin, _TrUserData) -> e_varint(V, Bin). + +-compile({nowarn_unused_function,e_type_sint/3}). +e_type_sint(Value, Bin, _TrUserData) when Value >= 0 -> e_varint(Value * 2, Bin); +e_type_sint(Value, Bin, _TrUserData) -> e_varint(Value * -2 - 1, Bin). + +-compile({nowarn_unused_function,e_type_int32/3}). +e_type_int32(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int32(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_int64/3}). +e_type_int64(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int64(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_bool/3}). +e_type_bool(true, Bin, _TrUserData) -> <>; +e_type_bool(false, Bin, _TrUserData) -> <>; +e_type_bool(1, Bin, _TrUserData) -> <>; +e_type_bool(0, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_string/3}). +e_type_string(S, Bin, _TrUserData) -> + Utf8 = unicode:characters_to_binary(S), + Bin2 = e_varint(byte_size(Utf8), Bin), + <>. + +-compile({nowarn_unused_function,e_type_bytes/3}). +e_type_bytes(Bytes, Bin, _TrUserData) when is_binary(Bytes) -> + Bin2 = e_varint(byte_size(Bytes), Bin), + <>; +e_type_bytes(Bytes, Bin, _TrUserData) when is_list(Bytes) -> + BytesBin = iolist_to_binary(Bytes), + Bin2 = e_varint(byte_size(BytesBin), Bin), + <>. + +-compile({nowarn_unused_function,e_type_fixed32/3}). +e_type_fixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed32/3}). +e_type_sfixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_fixed64/3}). +e_type_fixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed64/3}). +e_type_sfixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_float/3}). +e_type_float(V, Bin, _) when is_number(V) -> <>; +e_type_float(infinity, Bin, _) -> <>; +e_type_float('-infinity', Bin, _) -> <>; +e_type_float(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_type_double/3}). +e_type_double(V, Bin, _) when is_number(V) -> <>; +e_type_double(infinity, Bin, _) -> <>; +e_type_double('-infinity', Bin, _) -> <>; +e_type_double(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_unknown_elems/2}). +e_unknown_elems([Elem | Rest], Bin) -> + BinR = case Elem of + {varint, FNum, N} -> + BinF = e_varint(FNum bsl 3, Bin), + e_varint(N, BinF); + {length_delimited, FNum, Data} -> + BinF = e_varint(FNum bsl 3 bor 2, Bin), + BinL = e_varint(byte_size(Data), BinF), + <>; + {group, FNum, GroupFields} -> + Bin1 = e_varint(FNum bsl 3 bor 3, Bin), + Bin2 = e_unknown_elems(GroupFields, Bin1), + e_varint(FNum bsl 3 bor 4, Bin2); + {fixed32, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 5, Bin), + <>; + {fixed64, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 1, Bin), + <> + end, + e_unknown_elems(Rest, BinR); +e_unknown_elems([], Bin) -> Bin. + +-compile({nowarn_unused_function,e_varint/3}). +e_varint(N, Bin, _TrUserData) -> e_varint(N, Bin). + +-compile({nowarn_unused_function,e_varint/2}). +e_varint(N, Bin) when N =< 127 -> <>; +e_varint(N, Bin) -> + Bin2 = <>, + e_varint(N bsr 7, Bin2). + + +decode_msg(Bin, MsgName) when is_binary(Bin) -> decode_msg(Bin, MsgName, []). + +decode_msg(Bin, MsgName, Opts) when is_binary(Bin) -> + TrUserData = proplists:get_value(user_data, Opts), + decode_msg_1_catch(Bin, MsgName, TrUserData). + +-ifdef('OTP_RELEASE'). +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason:StackTrace -> + erlang:raise(error, Reason, StackTrace); + Class:Reason:StackTrace -> error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-else. +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason -> + erlang:raise(error, Reason, + erlang:get_stacktrace()); + Class:Reason -> + StackTrace = erlang:get_stacktrace(), + error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-endif. + +decode_msg_2_doit('Package', Bin, TrUserData) -> id(decode_msg_Package(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Release', Bin, TrUserData) -> id(decode_msg_Release(Bin, TrUserData), TrUserData); +decode_msg_2_doit('RetirementStatus', Bin, TrUserData) -> id(decode_msg_RetirementStatus(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Dependency', Bin, TrUserData) -> id(decode_msg_Dependency(Bin, TrUserData), TrUserData). + + + +decode_msg_Package(Bin, TrUserData) -> dfp_read_field_def_Package(Bin, 0, 0, 0, id([], TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_Package(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_releases(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_name(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_repository(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<>>, 0, 0, _, R1, F@_2, F@_3, TrUserData) -> + S1 = #{name => F@_2, repository => F@_3}, + if R1 == '$undef' -> S1; + true -> S1#{releases => lists_reverse(R1, TrUserData)} + end; +dfp_read_field_def_Package(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_Package(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +dg_read_field_def_Package(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_Package(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_Package(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Package_releases(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 18 -> d_field_Package_name(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 26 -> d_field_Package_repository(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + end + end; +dg_read_field_def_Package(<<>>, 0, 0, _, R1, F@_2, F@_3, TrUserData) -> + S1 = #{name => F@_2, repository => F@_3}, + if R1 == '$undef' -> S1; + true -> S1#{releases => lists_reverse(R1, TrUserData)} + end. + +d_field_Package_releases(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_releases(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_releases(<<0:1, X:7, Rest/binary>>, N, Acc, F, Prev, F@_2, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_Release(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_Package(RestF, 0, 0, F, cons(NewFValue, Prev, TrUserData), F@_2, F@_3, TrUserData). + +d_field_Package_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_name(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Package(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). + +d_field_Package_repository(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_repository(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_repository(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Package(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). + +skip_varint_Package(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_Package(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_length_delimited_Package(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_Package(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_Package(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Package(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + +skip_group_Package(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Package(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + +skip_32_Package(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_64_Package(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +decode_msg_Release(Bin, TrUserData) -> dfp_read_field_def_Release(Bin, 0, 0, 0, id('$undef', TrUserData), id('$undef', TrUserData), id([], TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_Release(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Release_version(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Release(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Release_inner_checksum(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Release(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Release_dependencies(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Release(<<34, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Release_retired(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Release(<<42, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Release_outer_checksum(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Release(<<>>, 0, 0, _, F@_1, F@_2, R1, F@_4, F@_5, TrUserData) -> + S1 = #{version => F@_1, inner_checksum => F@_2}, + S2 = if R1 == '$undef' -> S1; + true -> S1#{dependencies => lists_reverse(R1, TrUserData)} + end, + S3 = if F@_4 == '$undef' -> S2; + true -> S2#{retired => F@_4} + end, + if F@_5 == '$undef' -> S3; + true -> S3#{outer_checksum => F@_5} + end; +dfp_read_field_def_Release(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dg_read_field_def_Release(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +dg_read_field_def_Release(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 32 - 7 -> dg_read_field_def_Release(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dg_read_field_def_Release(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Release_version(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 18 -> d_field_Release_inner_checksum(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 26 -> d_field_Release_dependencies(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 34 -> d_field_Release_retired(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 42 -> d_field_Release_outer_checksum(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Release(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 1 -> skip_64_Release(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 2 -> skip_length_delimited_Release(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 3 -> skip_group_Release(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 5 -> skip_32_Release(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) + end + end; +dg_read_field_def_Release(<<>>, 0, 0, _, F@_1, F@_2, R1, F@_4, F@_5, TrUserData) -> + S1 = #{version => F@_1, inner_checksum => F@_2}, + S2 = if R1 == '$undef' -> S1; + true -> S1#{dependencies => lists_reverse(R1, TrUserData)} + end, + S3 = if F@_4 == '$undef' -> S2; + true -> S2#{retired => F@_4} + end, + if F@_5 == '$undef' -> S3; + true -> S3#{outer_checksum => F@_5} + end. + +d_field_Release_version(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Release_version(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Release_version(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Release(RestF, 0, 0, F, NewFValue, F@_2, F@_3, F@_4, F@_5, TrUserData). + +d_field_Release_inner_checksum(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Release_inner_checksum(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Release_inner_checksum(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Release(RestF, 0, 0, F, F@_1, NewFValue, F@_3, F@_4, F@_5, TrUserData). + +d_field_Release_dependencies(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Release_dependencies(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Release_dependencies(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, Prev, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_Dependency(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_Release(RestF, 0, 0, F, F@_1, F@_2, cons(NewFValue, Prev, TrUserData), F@_4, F@_5, TrUserData). + +d_field_Release_retired(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Release_retired(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Release_retired(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, Prev, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_RetirementStatus(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_Release(RestF, + 0, + 0, + F, + F@_1, + F@_2, + F@_3, + if Prev == '$undef' -> NewFValue; + true -> merge_msg_RetirementStatus(Prev, NewFValue, TrUserData) + end, + F@_5, + TrUserData). + +d_field_Release_outer_checksum(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Release_outer_checksum(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Release_outer_checksum(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Release(RestF, 0, 0, F, F@_1, F@_2, F@_3, F@_4, NewFValue, TrUserData). + +skip_varint_Release(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> skip_varint_Release(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_varint_Release(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Release(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_length_delimited_Release(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> skip_length_delimited_Release(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_length_delimited_Release(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Release(Rest2, 0, 0, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_group_Release(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Release(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_32_Release(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Release(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_64_Release(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Release(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +decode_msg_RetirementStatus(Bin, TrUserData) -> dfp_read_field_def_RetirementStatus(Bin, 0, 0, 0, id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_RetirementStatus(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_RetirementStatus_reason(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_RetirementStatus(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_RetirementStatus_message(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_RetirementStatus(<<>>, 0, 0, _, F@_1, F@_2, _) -> + S1 = #{reason => F@_1}, + if F@_2 == '$undef' -> S1; + true -> S1#{message => F@_2} + end; +dfp_read_field_def_RetirementStatus(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_RetirementStatus(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_RetirementStatus(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_RetirementStatus(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_RetirementStatus(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 8 -> d_field_RetirementStatus_reason(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_RetirementStatus_message(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_RetirementStatus(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_RetirementStatus(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_RetirementStatus(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_RetirementStatus(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_RetirementStatus(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_RetirementStatus(<<>>, 0, 0, _, F@_1, F@_2, _) -> + S1 = #{reason => F@_1}, + if F@_2 == '$undef' -> S1; + true -> S1#{message => F@_2} + end. + +d_field_RetirementStatus_reason(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_RetirementStatus_reason(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_RetirementStatus_reason(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = {id(d_enum_RetirementReason(begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end), TrUserData), Rest}, + dfp_read_field_def_RetirementStatus(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_RetirementStatus_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_RetirementStatus_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_RetirementStatus_message(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_RetirementStatus(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_RetirementStatus(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_RetirementStatus(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_RetirementStatus(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_RetirementStatus(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_RetirementStatus(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_RetirementStatus(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_RetirementStatus(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_RetirementStatus(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_RetirementStatus(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_RetirementStatus(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_RetirementStatus(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_RetirementStatus(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_RetirementStatus(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_RetirementStatus(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_Dependency(Bin, TrUserData) -> dfp_read_field_def_Dependency(Bin, 0, 0, 0, id('$undef', TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_Dependency(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Dependency_package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Dependency(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Dependency_requirement(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Dependency(<<24, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Dependency_optional(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Dependency(<<34, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Dependency_app(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Dependency(<<42, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_Dependency_repository(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_Dependency(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> + S1 = #{package => F@_1, requirement => F@_2}, + S2 = if F@_3 == '$undef' -> S1; + true -> S1#{optional => F@_3} + end, + S3 = if F@_4 == '$undef' -> S2; + true -> S2#{app => F@_4} + end, + if F@_5 == '$undef' -> S3; + true -> S3#{repository => F@_5} + end; +dfp_read_field_def_Dependency(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dg_read_field_def_Dependency(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +dg_read_field_def_Dependency(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 32 - 7 -> dg_read_field_def_Dependency(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dg_read_field_def_Dependency(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Dependency_package(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 18 -> d_field_Dependency_requirement(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 24 -> d_field_Dependency_optional(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 34 -> d_field_Dependency_app(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 42 -> d_field_Dependency_repository(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Dependency(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 1 -> skip_64_Dependency(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 2 -> skip_length_delimited_Dependency(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 3 -> skip_group_Dependency(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 5 -> skip_32_Dependency(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) + end + end; +dg_read_field_def_Dependency(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> + S1 = #{package => F@_1, requirement => F@_2}, + S2 = if F@_3 == '$undef' -> S1; + true -> S1#{optional => F@_3} + end, + S3 = if F@_4 == '$undef' -> S2; + true -> S2#{app => F@_4} + end, + if F@_5 == '$undef' -> S3; + true -> S3#{repository => F@_5} + end. + +d_field_Dependency_package(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Dependency_package(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Dependency_package(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Dependency(RestF, 0, 0, F, NewFValue, F@_2, F@_3, F@_4, F@_5, TrUserData). + +d_field_Dependency_requirement(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Dependency_requirement(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Dependency_requirement(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Dependency(RestF, 0, 0, F, F@_1, NewFValue, F@_3, F@_4, F@_5, TrUserData). + +d_field_Dependency_optional(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Dependency_optional(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Dependency_optional(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = {id(X bsl N + Acc =/= 0, TrUserData), Rest}, + dfp_read_field_def_Dependency(RestF, 0, 0, F, F@_1, F@_2, NewFValue, F@_4, F@_5, TrUserData). + +d_field_Dependency_app(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Dependency_app(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Dependency_app(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, _, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Dependency(RestF, 0, 0, F, F@_1, F@_2, F@_3, NewFValue, F@_5, TrUserData). + +d_field_Dependency_repository(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_Dependency_repository(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_Dependency_repository(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Dependency(RestF, 0, 0, F, F@_1, F@_2, F@_3, F@_4, NewFValue, TrUserData). + +skip_varint_Dependency(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> skip_varint_Dependency(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_varint_Dependency(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Dependency(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_length_delimited_Dependency(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> skip_length_delimited_Dependency(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_length_delimited_Dependency(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Dependency(Rest2, 0, 0, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_group_Dependency(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Dependency(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_32_Dependency(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Dependency(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_64_Dependency(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_Dependency(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +d_enum_RetirementReason(0) -> 'RETIRED_OTHER'; +d_enum_RetirementReason(1) -> 'RETIRED_INVALID'; +d_enum_RetirementReason(2) -> 'RETIRED_SECURITY'; +d_enum_RetirementReason(3) -> 'RETIRED_DEPRECATED'; +d_enum_RetirementReason(4) -> 'RETIRED_RENAMED'; +d_enum_RetirementReason(V) -> V. + +read_group(Bin, FieldNum) -> + {NumBytes, EndTagLen} = read_gr_b(Bin, 0, 0, 0, 0, FieldNum), + <> = Bin, + {Group, Rest}. + +%% Like skipping over fields, but record the total length, +%% Each field is <(FieldNum bsl 3) bor FieldType> ++ +%% Record the length because varints may be non-optimally encoded. +%% +%% Groups can be nested, but assume the same FieldNum cannot be nested +%% because group field numbers are shared with the rest of the fields +%% numbers. Thus we can search just for an group-end with the same +%% field number. +%% +%% (The only time the same group field number could occur would +%% be in a nested sub message, but then it would be inside a +%% length-delimited entry, which we skip-read by length.) +read_gr_b(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, FieldNum) + when N < (32-7) -> + read_gr_b(Tl, N+7, X bsl N + Acc, NumBytes, TagLen+1, FieldNum); +read_gr_b(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, + FieldNum) -> + Key = X bsl N + Acc, + TagLen1 = TagLen + 1, + case {Key bsr 3, Key band 7} of + {FieldNum, 4} -> % 4 = group_end + {NumBytes, TagLen1}; + {_, 0} -> % 0 = varint + read_gr_vi(Tl, 0, NumBytes + TagLen1, FieldNum); + {_, 1} -> % 1 = bits64 + <<_:64, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 8, 0, FieldNum); + {_, 2} -> % 2 = length_delimited + read_gr_ld(Tl, 0, 0, NumBytes + TagLen1, FieldNum); + {_, 3} -> % 3 = group_start + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 4} -> % 4 = group_end + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 5} -> % 5 = bits32 + <<_:32, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 4, 0, FieldNum) + end. + +read_gr_vi(<<1:1, _:7, Tl/binary>>, N, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_vi(Tl, N+7, NumBytes+1, FieldNum); +read_gr_vi(<<0:1, _:7, Tl/binary>>, _, NumBytes, FieldNum) -> + read_gr_b(Tl, 0, 0, NumBytes+1, 0, FieldNum). + +read_gr_ld(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_ld(Tl, N+7, X bsl N + Acc, NumBytes+1, FieldNum); +read_gr_ld(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) -> + Len = X bsl N + Acc, + NumBytes1 = NumBytes + 1, + <<_:Len/binary, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes1 + Len, 0, FieldNum). + +merge_msgs(Prev, New, MsgName) when is_atom(MsgName) -> merge_msgs(Prev, New, MsgName, []). + +merge_msgs(Prev, New, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Package' -> merge_msg_Package(Prev, New, TrUserData); + 'Release' -> merge_msg_Release(Prev, New, TrUserData); + 'RetirementStatus' -> merge_msg_RetirementStatus(Prev, New, TrUserData); + 'Dependency' -> merge_msg_Dependency(Prev, New, TrUserData) + end. + +-compile({nowarn_unused_function,merge_msg_Package/3}). +merge_msg_Package(#{} = PMsg, #{name := NFname, repository := NFrepository} = NMsg, TrUserData) -> + S1 = #{name => NFname, repository => NFrepository}, + case {PMsg, NMsg} of + {#{releases := PFreleases}, #{releases := NFreleases}} -> S1#{releases => 'erlang_++'(PFreleases, NFreleases, TrUserData)}; + {_, #{releases := NFreleases}} -> S1#{releases => NFreleases}; + {#{releases := PFreleases}, _} -> S1#{releases => PFreleases}; + {_, _} -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_Release/3}). +merge_msg_Release(#{} = PMsg, #{version := NFversion, inner_checksum := NFinner_checksum} = NMsg, TrUserData) -> + S1 = #{version => NFversion, inner_checksum => NFinner_checksum}, + S2 = case {PMsg, NMsg} of + {#{dependencies := PFdependencies}, #{dependencies := NFdependencies}} -> S1#{dependencies => 'erlang_++'(PFdependencies, NFdependencies, TrUserData)}; + {_, #{dependencies := NFdependencies}} -> S1#{dependencies => NFdependencies}; + {#{dependencies := PFdependencies}, _} -> S1#{dependencies => PFdependencies}; + {_, _} -> S1 + end, + S3 = case {PMsg, NMsg} of + {#{retired := PFretired}, #{retired := NFretired}} -> S2#{retired => merge_msg_RetirementStatus(PFretired, NFretired, TrUserData)}; + {_, #{retired := NFretired}} -> S2#{retired => NFretired}; + {#{retired := PFretired}, _} -> S2#{retired => PFretired}; + {_, _} -> S2 + end, + case {PMsg, NMsg} of + {_, #{outer_checksum := NFouter_checksum}} -> S3#{outer_checksum => NFouter_checksum}; + {#{outer_checksum := PFouter_checksum}, _} -> S3#{outer_checksum => PFouter_checksum}; + _ -> S3 + end. + +-compile({nowarn_unused_function,merge_msg_RetirementStatus/3}). +merge_msg_RetirementStatus(#{} = PMsg, #{reason := NFreason} = NMsg, _) -> + S1 = #{reason => NFreason}, + case {PMsg, NMsg} of + {_, #{message := NFmessage}} -> S1#{message => NFmessage}; + {#{message := PFmessage}, _} -> S1#{message => PFmessage}; + _ -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_Dependency/3}). +merge_msg_Dependency(#{} = PMsg, #{package := NFpackage, requirement := NFrequirement} = NMsg, _) -> + S1 = #{package => NFpackage, requirement => NFrequirement}, + S2 = case {PMsg, NMsg} of + {_, #{optional := NFoptional}} -> S1#{optional => NFoptional}; + {#{optional := PFoptional}, _} -> S1#{optional => PFoptional}; + _ -> S1 + end, + S3 = case {PMsg, NMsg} of + {_, #{app := NFapp}} -> S2#{app => NFapp}; + {#{app := PFapp}, _} -> S2#{app => PFapp}; + _ -> S2 + end, + case {PMsg, NMsg} of + {_, #{repository := NFrepository}} -> S3#{repository => NFrepository}; + {#{repository := PFrepository}, _} -> S3#{repository => PFrepository}; + _ -> S3 + end. + + +verify_msg(Msg, MsgName) when is_atom(MsgName) -> verify_msg(Msg, MsgName, []). + +verify_msg(Msg, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Package' -> v_msg_Package(Msg, [MsgName], TrUserData); + 'Release' -> v_msg_Release(Msg, [MsgName], TrUserData); + 'RetirementStatus' -> v_msg_RetirementStatus(Msg, [MsgName], TrUserData); + 'Dependency' -> v_msg_Dependency(Msg, [MsgName], TrUserData); + _ -> mk_type_error(not_a_known_message, Msg, []) + end. + + +-compile({nowarn_unused_function,v_msg_Package/3}). +-dialyzer({nowarn_function,v_msg_Package/3}). +v_msg_Package(#{name := F2, repository := F3} = M, Path, TrUserData) -> + case M of + #{releases := F1} -> + if is_list(F1) -> + _ = [v_submsg_Release(Elem, [releases | Path], TrUserData) || Elem <- F1], + ok; + true -> mk_type_error({invalid_list_of, {msg, 'Release'}}, F1, [releases | Path]) + end; + _ -> ok + end, + v_type_string(F2, [name | Path], TrUserData), + v_type_string(F3, [repository | Path], TrUserData), + lists:foreach(fun (releases) -> ok; + (name) -> ok; + (repository) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Package(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [name, repository] -- maps:keys(M), 'Package'}, M, Path); +v_msg_Package(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Package'}, X, Path). + +-compile({nowarn_unused_function,v_submsg_Release/3}). +-dialyzer({nowarn_function,v_submsg_Release/3}). +v_submsg_Release(Msg, Path, TrUserData) -> v_msg_Release(Msg, Path, TrUserData). + +-compile({nowarn_unused_function,v_msg_Release/3}). +-dialyzer({nowarn_function,v_msg_Release/3}). +v_msg_Release(#{version := F1, inner_checksum := F2} = M, Path, TrUserData) -> + v_type_string(F1, [version | Path], TrUserData), + v_type_bytes(F2, [inner_checksum | Path], TrUserData), + case M of + #{dependencies := F3} -> + if is_list(F3) -> + _ = [v_submsg_Dependency(Elem, [dependencies | Path], TrUserData) || Elem <- F3], + ok; + true -> mk_type_error({invalid_list_of, {msg, 'Dependency'}}, F3, [dependencies | Path]) + end; + _ -> ok + end, + case M of + #{retired := F4} -> v_submsg_RetirementStatus(F4, [retired | Path], TrUserData); + _ -> ok + end, + case M of + #{outer_checksum := F5} -> v_type_bytes(F5, [outer_checksum | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (version) -> ok; + (inner_checksum) -> ok; + (dependencies) -> ok; + (retired) -> ok; + (outer_checksum) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Release(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [version, inner_checksum] -- maps:keys(M), 'Release'}, M, Path); +v_msg_Release(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Release'}, X, Path). + +-compile({nowarn_unused_function,v_submsg_RetirementStatus/3}). +-dialyzer({nowarn_function,v_submsg_RetirementStatus/3}). +v_submsg_RetirementStatus(Msg, Path, TrUserData) -> v_msg_RetirementStatus(Msg, Path, TrUserData). + +-compile({nowarn_unused_function,v_msg_RetirementStatus/3}). +-dialyzer({nowarn_function,v_msg_RetirementStatus/3}). +v_msg_RetirementStatus(#{reason := F1} = M, Path, TrUserData) -> + v_enum_RetirementReason(F1, [reason | Path], TrUserData), + case M of + #{message := F2} -> v_type_string(F2, [message | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (reason) -> ok; + (message) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_RetirementStatus(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [reason] -- maps:keys(M), 'RetirementStatus'}, M, Path); +v_msg_RetirementStatus(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'RetirementStatus'}, X, Path). + +-compile({nowarn_unused_function,v_submsg_Dependency/3}). +-dialyzer({nowarn_function,v_submsg_Dependency/3}). +v_submsg_Dependency(Msg, Path, TrUserData) -> v_msg_Dependency(Msg, Path, TrUserData). + +-compile({nowarn_unused_function,v_msg_Dependency/3}). +-dialyzer({nowarn_function,v_msg_Dependency/3}). +v_msg_Dependency(#{package := F1, requirement := F2} = M, Path, TrUserData) -> + v_type_string(F1, [package | Path], TrUserData), + v_type_string(F2, [requirement | Path], TrUserData), + case M of + #{optional := F3} -> v_type_bool(F3, [optional | Path], TrUserData); + _ -> ok + end, + case M of + #{app := F4} -> v_type_string(F4, [app | Path], TrUserData); + _ -> ok + end, + case M of + #{repository := F5} -> v_type_string(F5, [repository | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (package) -> ok; + (requirement) -> ok; + (optional) -> ok; + (app) -> ok; + (repository) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Dependency(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [package, requirement] -- maps:keys(M), 'Dependency'}, M, Path); +v_msg_Dependency(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Dependency'}, X, Path). + +-compile({nowarn_unused_function,v_enum_RetirementReason/3}). +-dialyzer({nowarn_function,v_enum_RetirementReason/3}). +v_enum_RetirementReason('RETIRED_OTHER', _Path, _TrUserData) -> ok; +v_enum_RetirementReason('RETIRED_INVALID', _Path, _TrUserData) -> ok; +v_enum_RetirementReason('RETIRED_SECURITY', _Path, _TrUserData) -> ok; +v_enum_RetirementReason('RETIRED_DEPRECATED', _Path, _TrUserData) -> ok; +v_enum_RetirementReason('RETIRED_RENAMED', _Path, _TrUserData) -> ok; +v_enum_RetirementReason(V, _Path, _TrUserData) when -2147483648 =< V, V =< 2147483647, is_integer(V) -> ok; +v_enum_RetirementReason(X, Path, _TrUserData) -> mk_type_error({invalid_enum, 'RetirementReason'}, X, Path). + +-compile({nowarn_unused_function,v_type_bool/3}). +-dialyzer({nowarn_function,v_type_bool/3}). +v_type_bool(false, _Path, _TrUserData) -> ok; +v_type_bool(true, _Path, _TrUserData) -> ok; +v_type_bool(0, _Path, _TrUserData) -> ok; +v_type_bool(1, _Path, _TrUserData) -> ok; +v_type_bool(X, Path, _TrUserData) -> mk_type_error(bad_boolean_value, X, Path). + +-compile({nowarn_unused_function,v_type_string/3}). +-dialyzer({nowarn_function,v_type_string/3}). +v_type_string(S, Path, _TrUserData) when is_list(S); is_binary(S) -> + try unicode:characters_to_binary(S) of + B when is_binary(B) -> ok; + {error, _, _} -> mk_type_error(bad_unicode_string, S, Path) + catch + error:badarg -> mk_type_error(bad_unicode_string, S, Path) + end; +v_type_string(X, Path, _TrUserData) -> mk_type_error(bad_unicode_string, X, Path). + +-compile({nowarn_unused_function,v_type_bytes/3}). +-dialyzer({nowarn_function,v_type_bytes/3}). +v_type_bytes(B, _Path, _TrUserData) when is_binary(B) -> ok; +v_type_bytes(B, _Path, _TrUserData) when is_list(B) -> ok; +v_type_bytes(X, Path, _TrUserData) -> mk_type_error(bad_binary_value, X, Path). + +-compile({nowarn_unused_function,mk_type_error/3}). +-spec mk_type_error(_, _, list()) -> no_return(). +mk_type_error(Error, ValueSeen, Path) -> + Path2 = prettify_path(Path), + erlang:error({gpb_type_error, {Error, [{value, ValueSeen}, {path, Path2}]}}). + + +-compile({nowarn_unused_function,prettify_path/1}). +-dialyzer({nowarn_function,prettify_path/1}). +prettify_path([]) -> top_level; +prettify_path(PathR) -> lists:append(lists:join(".", lists:map(fun atom_to_list/1, lists:reverse(PathR)))). + + +-compile({nowarn_unused_function,id/2}). +-compile({inline,id/2}). +id(X, _TrUserData) -> X. + +-compile({nowarn_unused_function,v_ok/3}). +-compile({inline,v_ok/3}). +v_ok(_Value, _Path, _TrUserData) -> ok. + +-compile({nowarn_unused_function,m_overwrite/3}). +-compile({inline,m_overwrite/3}). +m_overwrite(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,cons/3}). +-compile({inline,cons/3}). +cons(Elem, Acc, _TrUserData) -> [Elem | Acc]. + +-compile({nowarn_unused_function,lists_reverse/2}). +-compile({inline,lists_reverse/2}). +'lists_reverse'(L, _TrUserData) -> lists:reverse(L). +-compile({nowarn_unused_function,'erlang_++'/3}). +-compile({inline,'erlang_++'/3}). +'erlang_++'(A, B, _TrUserData) -> A ++ B. + + +get_msg_defs() -> + [{{enum, 'RetirementReason'}, [{'RETIRED_OTHER', 0}, {'RETIRED_INVALID', 1}, {'RETIRED_SECURITY', 2}, {'RETIRED_DEPRECATED', 3}, {'RETIRED_RENAMED', 4}]}, + {{msg, 'Package'}, + [#{name => releases, fnum => 1, rnum => 2, type => {msg, 'Release'}, occurrence => repeated, opts => []}, + #{name => name, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}, + #{name => repository, fnum => 3, rnum => 4, type => string, occurrence => required, opts => []}]}, + {{msg, 'Release'}, + [#{name => version, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => inner_checksum, fnum => 2, rnum => 3, type => bytes, occurrence => required, opts => []}, + #{name => dependencies, fnum => 3, rnum => 4, type => {msg, 'Dependency'}, occurrence => repeated, opts => []}, + #{name => retired, fnum => 4, rnum => 5, type => {msg, 'RetirementStatus'}, occurrence => optional, opts => []}, + #{name => outer_checksum, fnum => 5, rnum => 6, type => bytes, occurrence => optional, opts => []}]}, + {{msg, 'RetirementStatus'}, [#{name => reason, fnum => 1, rnum => 2, type => {enum, 'RetirementReason'}, occurrence => required, opts => []}, #{name => message, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}]}, + {{msg, 'Dependency'}, + [#{name => package, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => requirement, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}, + #{name => optional, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}, + #{name => app, fnum => 4, rnum => 5, type => string, occurrence => optional, opts => []}, + #{name => repository, fnum => 5, rnum => 6, type => string, occurrence => optional, opts => []}]}]. + + +get_msg_names() -> ['Package', 'Release', 'RetirementStatus', 'Dependency']. + + +get_group_names() -> []. + + +get_msg_or_group_names() -> ['Package', 'Release', 'RetirementStatus', 'Dependency']. + + +get_enum_names() -> ['RetirementReason']. + + +fetch_msg_def(MsgName) -> + case find_msg_def(MsgName) of + Fs when is_list(Fs) -> Fs; + error -> erlang:error({no_such_msg, MsgName}) + end. + + +fetch_enum_def(EnumName) -> + case find_enum_def(EnumName) of + Es when is_list(Es) -> Es; + error -> erlang:error({no_such_enum, EnumName}) + end. + + +find_msg_def('Package') -> + [#{name => releases, fnum => 1, rnum => 2, type => {msg, 'Release'}, occurrence => repeated, opts => []}, + #{name => name, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}, + #{name => repository, fnum => 3, rnum => 4, type => string, occurrence => required, opts => []}]; +find_msg_def('Release') -> + [#{name => version, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => inner_checksum, fnum => 2, rnum => 3, type => bytes, occurrence => required, opts => []}, + #{name => dependencies, fnum => 3, rnum => 4, type => {msg, 'Dependency'}, occurrence => repeated, opts => []}, + #{name => retired, fnum => 4, rnum => 5, type => {msg, 'RetirementStatus'}, occurrence => optional, opts => []}, + #{name => outer_checksum, fnum => 5, rnum => 6, type => bytes, occurrence => optional, opts => []}]; +find_msg_def('RetirementStatus') -> [#{name => reason, fnum => 1, rnum => 2, type => {enum, 'RetirementReason'}, occurrence => required, opts => []}, #{name => message, fnum => 2, rnum => 3, type => string, occurrence => optional, opts => []}]; +find_msg_def('Dependency') -> + [#{name => package, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => requirement, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}, + #{name => optional, fnum => 3, rnum => 4, type => bool, occurrence => optional, opts => []}, + #{name => app, fnum => 4, rnum => 5, type => string, occurrence => optional, opts => []}, + #{name => repository, fnum => 5, rnum => 6, type => string, occurrence => optional, opts => []}]; +find_msg_def(_) -> error. + + +find_enum_def('RetirementReason') -> [{'RETIRED_OTHER', 0}, {'RETIRED_INVALID', 1}, {'RETIRED_SECURITY', 2}, {'RETIRED_DEPRECATED', 3}, {'RETIRED_RENAMED', 4}]; +find_enum_def(_) -> error. + + +enum_symbol_by_value('RetirementReason', Value) -> enum_symbol_by_value_RetirementReason(Value). + + +enum_value_by_symbol('RetirementReason', Sym) -> enum_value_by_symbol_RetirementReason(Sym). + + +enum_symbol_by_value_RetirementReason(0) -> 'RETIRED_OTHER'; +enum_symbol_by_value_RetirementReason(1) -> 'RETIRED_INVALID'; +enum_symbol_by_value_RetirementReason(2) -> 'RETIRED_SECURITY'; +enum_symbol_by_value_RetirementReason(3) -> 'RETIRED_DEPRECATED'; +enum_symbol_by_value_RetirementReason(4) -> 'RETIRED_RENAMED'. + + +enum_value_by_symbol_RetirementReason('RETIRED_OTHER') -> 0; +enum_value_by_symbol_RetirementReason('RETIRED_INVALID') -> 1; +enum_value_by_symbol_RetirementReason('RETIRED_SECURITY') -> 2; +enum_value_by_symbol_RetirementReason('RETIRED_DEPRECATED') -> 3; +enum_value_by_symbol_RetirementReason('RETIRED_RENAMED') -> 4. + + +get_service_names() -> []. + + +get_service_def(_) -> error. + + +get_rpc_names(_) -> error. + + +find_rpc_def(_, _) -> error. + + + +-spec fetch_rpc_def(_, _) -> no_return(). +fetch_rpc_def(ServiceName, RpcName) -> erlang:error({no_such_rpc, ServiceName, RpcName}). + + +%% Convert a a fully qualified (ie with package name) service name +%% as a binary to a service name as an atom. +-spec fqbin_to_service_name(_) -> no_return(). +fqbin_to_service_name(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a service name as an atom to a fully qualified +%% (ie with package name) name as a binary. +-spec service_name_to_fqbin(_) -> no_return(). +service_name_to_fqbin(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a a fully qualified (ie with package name) service name +%% and an rpc name, both as binaries to a service name and an rpc +%% name, as atoms. +-spec fqbins_to_service_and_rpc_name(_, _) -> no_return(). +fqbins_to_service_and_rpc_name(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +%% Convert a service name and an rpc name, both as atoms, +%% to a fully qualified (ie with package name) service name and +%% an rpc name as binaries. +-spec service_and_rpc_name_to_fqbins(_, _) -> no_return(). +service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +fqbin_to_msg_name(<<"Package">>) -> 'Package'; +fqbin_to_msg_name(<<"Release">>) -> 'Release'; +fqbin_to_msg_name(<<"RetirementStatus">>) -> 'RetirementStatus'; +fqbin_to_msg_name(<<"Dependency">>) -> 'Dependency'; +fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). + + +msg_name_to_fqbin('Package') -> <<"Package">>; +msg_name_to_fqbin('Release') -> <<"Release">>; +msg_name_to_fqbin('RetirementStatus') -> <<"RetirementStatus">>; +msg_name_to_fqbin('Dependency') -> <<"Dependency">>; +msg_name_to_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +fqbin_to_enum_name(<<"RetirementReason">>) -> 'RetirementReason'; +fqbin_to_enum_name(E) -> error({gpb_error, {badenum, E}}). + + +enum_name_to_fqbin('RetirementReason') -> <<"RetirementReason">>; +enum_name_to_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_package_name() -> undefined. + + +%% Whether or not the message names +%% are prepended with package name or not. +uses_packages() -> false. + + +source_basename() -> "hex_pb_package.proto". + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned with extension, +%% see get_all_proto_names/0 for a version that returns +%% the basenames sans extension +get_all_source_basenames() -> ["hex_pb_package.proto"]. + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned sans .proto extension, +%% to make it easier to use them with the various get_xyz_containment +%% functions. +get_all_proto_names() -> ["hex_pb_package"]. + + +get_msg_containment("hex_pb_package") -> ['Dependency', 'Package', 'Release', 'RetirementStatus']; +get_msg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_pkg_containment("hex_pb_package") -> undefined; +get_pkg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_service_containment("hex_pb_package") -> []; +get_service_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_rpc_containment("hex_pb_package") -> []; +get_rpc_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_enum_containment("hex_pb_package") -> ['RetirementReason']; +get_enum_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_proto_by_msg_name_as_fqbin(<<"RetirementStatus">>) -> "hex_pb_package"; +get_proto_by_msg_name_as_fqbin(<<"Release">>) -> "hex_pb_package"; +get_proto_by_msg_name_as_fqbin(<<"Package">>) -> "hex_pb_package"; +get_proto_by_msg_name_as_fqbin(<<"Dependency">>) -> "hex_pb_package"; +get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec get_proto_by_service_name_as_fqbin(_) -> no_return(). +get_proto_by_service_name_as_fqbin(E) -> error({gpb_error, {badservice, E}}). + + +get_proto_by_enum_name_as_fqbin(<<"RetirementReason">>) -> "hex_pb_package"; +get_proto_by_enum_name_as_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +-spec get_protos_by_pkg_name_as_fqbin(_) -> no_return(). +get_protos_by_pkg_name_as_fqbin(E) -> error({gpb_error, {badpkg, E}}). + + + +gpb_version_as_string() -> + "4.21.1". + +gpb_version_as_list() -> + [4,21,1]. + +gpb_version_source() -> + "file". diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_pb_signed.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_signed.erl new file mode 100644 index 0000000000000000000000000000000000000000..8258f2a0fd490e7b68e809fd94e5936338a2e351 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_signed.erl @@ -0,0 +1,593 @@ +%% -*- coding: utf-8 -*- +%% % this file is @generated +%% @private +%% Automatically generated, do not edit +%% Generated by gpb_compile version 4.21.1 +%% Version source: file +-module(hex_pb_signed). + +-export([encode_msg/2, encode_msg/3]). +-export([decode_msg/2, decode_msg/3]). +-export([merge_msgs/3, merge_msgs/4]). +-export([verify_msg/2, verify_msg/3]). +-export([get_msg_defs/0]). +-export([get_msg_names/0]). +-export([get_group_names/0]). +-export([get_msg_or_group_names/0]). +-export([get_enum_names/0]). +-export([find_msg_def/1, fetch_msg_def/1]). +-export([find_enum_def/1, fetch_enum_def/1]). +-export([enum_symbol_by_value/2, enum_value_by_symbol/2]). +-export([get_service_names/0]). +-export([get_service_def/1]). +-export([get_rpc_names/1]). +-export([find_rpc_def/2, fetch_rpc_def/2]). +-export([fqbin_to_service_name/1]). +-export([service_name_to_fqbin/1]). +-export([fqbins_to_service_and_rpc_name/2]). +-export([service_and_rpc_name_to_fqbins/2]). +-export([fqbin_to_msg_name/1]). +-export([msg_name_to_fqbin/1]). +-export([fqbin_to_enum_name/1]). +-export([enum_name_to_fqbin/1]). +-export([get_package_name/0]). +-export([uses_packages/0]). +-export([source_basename/0]). +-export([get_all_source_basenames/0]). +-export([get_all_proto_names/0]). +-export([get_msg_containment/1]). +-export([get_pkg_containment/1]). +-export([get_service_containment/1]). +-export([get_rpc_containment/1]). +-export([get_enum_containment/1]). +-export([get_proto_by_msg_name_as_fqbin/1]). +-export([get_proto_by_service_name_as_fqbin/1]). +-export([get_proto_by_enum_name_as_fqbin/1]). +-export([get_protos_by_pkg_name_as_fqbin/1]). +-export([gpb_version_as_string/0, gpb_version_as_list/0]). +-export([gpb_version_source/0]). + + +%% enumerated types + +-export_type([]). + +%% message types +-type 'Signed'() :: + #{payload => iodata(), % = 1, required + signature => iodata() % = 2, optional + }. + +-export_type(['Signed'/0]). +-type '$msg_name'() :: 'Signed'. +-type '$msg'() :: 'Signed'(). +-export_type(['$msg_name'/0, '$msg'/0]). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/2}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'()) -> binary(). +encode_msg(Msg, MsgName) when is_atom(MsgName) -> encode_msg(Msg, MsgName, []). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/3}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'(), list()) -> binary(). +encode_msg(Msg, MsgName, Opts) -> + verify_msg(Msg, MsgName, Opts), + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of 'Signed' -> encode_msg_Signed(id(Msg, TrUserData), TrUserData) end. + + +encode_msg_Signed(Msg, TrUserData) -> encode_msg_Signed(Msg, <<>>, TrUserData). + + +encode_msg_Signed(#{payload := F1} = M, Bin, TrUserData) -> + B1 = begin TrF1 = id(F1, TrUserData), e_type_bytes(TrF1, <>, TrUserData) end, + case M of + #{signature := F2} -> begin TrF2 = id(F2, TrUserData), e_type_bytes(TrF2, <>, TrUserData) end; + _ -> B1 + end. + +-compile({nowarn_unused_function,e_type_sint/3}). +e_type_sint(Value, Bin, _TrUserData) when Value >= 0 -> e_varint(Value * 2, Bin); +e_type_sint(Value, Bin, _TrUserData) -> e_varint(Value * -2 - 1, Bin). + +-compile({nowarn_unused_function,e_type_int32/3}). +e_type_int32(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int32(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_int64/3}). +e_type_int64(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int64(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_bool/3}). +e_type_bool(true, Bin, _TrUserData) -> <>; +e_type_bool(false, Bin, _TrUserData) -> <>; +e_type_bool(1, Bin, _TrUserData) -> <>; +e_type_bool(0, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_string/3}). +e_type_string(S, Bin, _TrUserData) -> + Utf8 = unicode:characters_to_binary(S), + Bin2 = e_varint(byte_size(Utf8), Bin), + <>. + +-compile({nowarn_unused_function,e_type_bytes/3}). +e_type_bytes(Bytes, Bin, _TrUserData) when is_binary(Bytes) -> + Bin2 = e_varint(byte_size(Bytes), Bin), + <>; +e_type_bytes(Bytes, Bin, _TrUserData) when is_list(Bytes) -> + BytesBin = iolist_to_binary(Bytes), + Bin2 = e_varint(byte_size(BytesBin), Bin), + <>. + +-compile({nowarn_unused_function,e_type_fixed32/3}). +e_type_fixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed32/3}). +e_type_sfixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_fixed64/3}). +e_type_fixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed64/3}). +e_type_sfixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_float/3}). +e_type_float(V, Bin, _) when is_number(V) -> <>; +e_type_float(infinity, Bin, _) -> <>; +e_type_float('-infinity', Bin, _) -> <>; +e_type_float(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_type_double/3}). +e_type_double(V, Bin, _) when is_number(V) -> <>; +e_type_double(infinity, Bin, _) -> <>; +e_type_double('-infinity', Bin, _) -> <>; +e_type_double(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_unknown_elems/2}). +e_unknown_elems([Elem | Rest], Bin) -> + BinR = case Elem of + {varint, FNum, N} -> + BinF = e_varint(FNum bsl 3, Bin), + e_varint(N, BinF); + {length_delimited, FNum, Data} -> + BinF = e_varint(FNum bsl 3 bor 2, Bin), + BinL = e_varint(byte_size(Data), BinF), + <>; + {group, FNum, GroupFields} -> + Bin1 = e_varint(FNum bsl 3 bor 3, Bin), + Bin2 = e_unknown_elems(GroupFields, Bin1), + e_varint(FNum bsl 3 bor 4, Bin2); + {fixed32, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 5, Bin), + <>; + {fixed64, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 1, Bin), + <> + end, + e_unknown_elems(Rest, BinR); +e_unknown_elems([], Bin) -> Bin. + +-compile({nowarn_unused_function,e_varint/3}). +e_varint(N, Bin, _TrUserData) -> e_varint(N, Bin). + +-compile({nowarn_unused_function,e_varint/2}). +e_varint(N, Bin) when N =< 127 -> <>; +e_varint(N, Bin) -> + Bin2 = <>, + e_varint(N bsr 7, Bin2). + + +decode_msg(Bin, MsgName) when is_binary(Bin) -> decode_msg(Bin, MsgName, []). + +decode_msg(Bin, MsgName, Opts) when is_binary(Bin) -> + TrUserData = proplists:get_value(user_data, Opts), + decode_msg_1_catch(Bin, MsgName, TrUserData). + +-ifdef('OTP_RELEASE'). +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason:StackTrace -> + erlang:raise(error, Reason, StackTrace); + Class:Reason:StackTrace -> error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-else. +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason -> + erlang:raise(error, Reason, + erlang:get_stacktrace()); + Class:Reason -> + StackTrace = erlang:get_stacktrace(), + error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-endif. + +decode_msg_2_doit('Signed', Bin, TrUserData) -> id(decode_msg_Signed(Bin, TrUserData), TrUserData). + + + +decode_msg_Signed(Bin, TrUserData) -> dfp_read_field_def_Signed(Bin, 0, 0, 0, id('$undef', TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_Signed(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Signed_payload(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Signed(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Signed_signature(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Signed(<<>>, 0, 0, _, F@_1, F@_2, _) -> + S1 = #{payload => F@_1}, + if F@_2 == '$undef' -> S1; + true -> S1#{signature => F@_2} + end; +dfp_read_field_def_Signed(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_Signed(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_Signed(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_Signed(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_Signed(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Signed_payload(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_Signed_signature(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Signed(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_Signed(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_Signed(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_Signed(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_Signed(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_Signed(<<>>, 0, 0, _, F@_1, F@_2, _) -> + S1 = #{payload => F@_1}, + if F@_2 == '$undef' -> S1; + true -> S1#{signature => F@_2} + end. + +d_field_Signed_payload(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Signed_payload(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Signed_payload(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Signed(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_Signed_signature(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Signed_signature(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Signed_signature(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Signed(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_Signed(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_Signed(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_Signed(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Signed(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_Signed(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_Signed(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_Signed(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Signed(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_Signed(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Signed(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_Signed(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Signed(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_Signed(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Signed(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +read_group(Bin, FieldNum) -> + {NumBytes, EndTagLen} = read_gr_b(Bin, 0, 0, 0, 0, FieldNum), + <> = Bin, + {Group, Rest}. + +%% Like skipping over fields, but record the total length, +%% Each field is <(FieldNum bsl 3) bor FieldType> ++ +%% Record the length because varints may be non-optimally encoded. +%% +%% Groups can be nested, but assume the same FieldNum cannot be nested +%% because group field numbers are shared with the rest of the fields +%% numbers. Thus we can search just for an group-end with the same +%% field number. +%% +%% (The only time the same group field number could occur would +%% be in a nested sub message, but then it would be inside a +%% length-delimited entry, which we skip-read by length.) +read_gr_b(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, FieldNum) + when N < (32-7) -> + read_gr_b(Tl, N+7, X bsl N + Acc, NumBytes, TagLen+1, FieldNum); +read_gr_b(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, + FieldNum) -> + Key = X bsl N + Acc, + TagLen1 = TagLen + 1, + case {Key bsr 3, Key band 7} of + {FieldNum, 4} -> % 4 = group_end + {NumBytes, TagLen1}; + {_, 0} -> % 0 = varint + read_gr_vi(Tl, 0, NumBytes + TagLen1, FieldNum); + {_, 1} -> % 1 = bits64 + <<_:64, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 8, 0, FieldNum); + {_, 2} -> % 2 = length_delimited + read_gr_ld(Tl, 0, 0, NumBytes + TagLen1, FieldNum); + {_, 3} -> % 3 = group_start + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 4} -> % 4 = group_end + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 5} -> % 5 = bits32 + <<_:32, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 4, 0, FieldNum) + end. + +read_gr_vi(<<1:1, _:7, Tl/binary>>, N, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_vi(Tl, N+7, NumBytes+1, FieldNum); +read_gr_vi(<<0:1, _:7, Tl/binary>>, _, NumBytes, FieldNum) -> + read_gr_b(Tl, 0, 0, NumBytes+1, 0, FieldNum). + +read_gr_ld(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_ld(Tl, N+7, X bsl N + Acc, NumBytes+1, FieldNum); +read_gr_ld(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) -> + Len = X bsl N + Acc, + NumBytes1 = NumBytes + 1, + <<_:Len/binary, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes1 + Len, 0, FieldNum). + +merge_msgs(Prev, New, MsgName) when is_atom(MsgName) -> merge_msgs(Prev, New, MsgName, []). + +merge_msgs(Prev, New, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of 'Signed' -> merge_msg_Signed(Prev, New, TrUserData) end. + +-compile({nowarn_unused_function,merge_msg_Signed/3}). +merge_msg_Signed(#{} = PMsg, #{payload := NFpayload} = NMsg, _) -> + S1 = #{payload => NFpayload}, + case {PMsg, NMsg} of + {_, #{signature := NFsignature}} -> S1#{signature => NFsignature}; + {#{signature := PFsignature}, _} -> S1#{signature => PFsignature}; + _ -> S1 + end. + + +verify_msg(Msg, MsgName) when is_atom(MsgName) -> verify_msg(Msg, MsgName, []). + +verify_msg(Msg, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Signed' -> v_msg_Signed(Msg, [MsgName], TrUserData); + _ -> mk_type_error(not_a_known_message, Msg, []) + end. + + +-compile({nowarn_unused_function,v_msg_Signed/3}). +-dialyzer({nowarn_function,v_msg_Signed/3}). +v_msg_Signed(#{payload := F1} = M, Path, TrUserData) -> + v_type_bytes(F1, [payload | Path], TrUserData), + case M of + #{signature := F2} -> v_type_bytes(F2, [signature | Path], TrUserData); + _ -> ok + end, + lists:foreach(fun (payload) -> ok; + (signature) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Signed(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [payload] -- maps:keys(M), 'Signed'}, M, Path); +v_msg_Signed(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Signed'}, X, Path). + +-compile({nowarn_unused_function,v_type_bytes/3}). +-dialyzer({nowarn_function,v_type_bytes/3}). +v_type_bytes(B, _Path, _TrUserData) when is_binary(B) -> ok; +v_type_bytes(B, _Path, _TrUserData) when is_list(B) -> ok; +v_type_bytes(X, Path, _TrUserData) -> mk_type_error(bad_binary_value, X, Path). + +-compile({nowarn_unused_function,mk_type_error/3}). +-spec mk_type_error(_, _, list()) -> no_return(). +mk_type_error(Error, ValueSeen, Path) -> + Path2 = prettify_path(Path), + erlang:error({gpb_type_error, {Error, [{value, ValueSeen}, {path, Path2}]}}). + + +-compile({nowarn_unused_function,prettify_path/1}). +-dialyzer({nowarn_function,prettify_path/1}). +prettify_path([]) -> top_level; +prettify_path(PathR) -> lists:append(lists:join(".", lists:map(fun atom_to_list/1, lists:reverse(PathR)))). + + +-compile({nowarn_unused_function,id/2}). +-compile({inline,id/2}). +id(X, _TrUserData) -> X. + +-compile({nowarn_unused_function,v_ok/3}). +-compile({inline,v_ok/3}). +v_ok(_Value, _Path, _TrUserData) -> ok. + +-compile({nowarn_unused_function,m_overwrite/3}). +-compile({inline,m_overwrite/3}). +m_overwrite(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,cons/3}). +-compile({inline,cons/3}). +cons(Elem, Acc, _TrUserData) -> [Elem | Acc]. + +-compile({nowarn_unused_function,lists_reverse/2}). +-compile({inline,lists_reverse/2}). +'lists_reverse'(L, _TrUserData) -> lists:reverse(L). +-compile({nowarn_unused_function,'erlang_++'/3}). +-compile({inline,'erlang_++'/3}). +'erlang_++'(A, B, _TrUserData) -> A ++ B. + + +get_msg_defs() -> [{{msg, 'Signed'}, [#{name => payload, fnum => 1, rnum => 2, type => bytes, occurrence => required, opts => []}, #{name => signature, fnum => 2, rnum => 3, type => bytes, occurrence => optional, opts => []}]}]. + + +get_msg_names() -> ['Signed']. + + +get_group_names() -> []. + + +get_msg_or_group_names() -> ['Signed']. + + +get_enum_names() -> []. + + +fetch_msg_def(MsgName) -> + case find_msg_def(MsgName) of + Fs when is_list(Fs) -> Fs; + error -> erlang:error({no_such_msg, MsgName}) + end. + + +-spec fetch_enum_def(_) -> no_return(). +fetch_enum_def(EnumName) -> erlang:error({no_such_enum, EnumName}). + + +find_msg_def('Signed') -> [#{name => payload, fnum => 1, rnum => 2, type => bytes, occurrence => required, opts => []}, #{name => signature, fnum => 2, rnum => 3, type => bytes, occurrence => optional, opts => []}]; +find_msg_def(_) -> error. + + +find_enum_def(_) -> error. + + +-spec enum_symbol_by_value(_, _) -> no_return(). +enum_symbol_by_value(E, V) -> erlang:error({no_enum_defs, E, V}). + + +-spec enum_value_by_symbol(_, _) -> no_return(). +enum_value_by_symbol(E, V) -> erlang:error({no_enum_defs, E, V}). + + + +get_service_names() -> []. + + +get_service_def(_) -> error. + + +get_rpc_names(_) -> error. + + +find_rpc_def(_, _) -> error. + + + +-spec fetch_rpc_def(_, _) -> no_return(). +fetch_rpc_def(ServiceName, RpcName) -> erlang:error({no_such_rpc, ServiceName, RpcName}). + + +%% Convert a a fully qualified (ie with package name) service name +%% as a binary to a service name as an atom. +-spec fqbin_to_service_name(_) -> no_return(). +fqbin_to_service_name(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a service name as an atom to a fully qualified +%% (ie with package name) name as a binary. +-spec service_name_to_fqbin(_) -> no_return(). +service_name_to_fqbin(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a a fully qualified (ie with package name) service name +%% and an rpc name, both as binaries to a service name and an rpc +%% name, as atoms. +-spec fqbins_to_service_and_rpc_name(_, _) -> no_return(). +fqbins_to_service_and_rpc_name(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +%% Convert a service name and an rpc name, both as atoms, +%% to a fully qualified (ie with package name) service name and +%% an rpc name as binaries. +-spec service_and_rpc_name_to_fqbins(_, _) -> no_return(). +service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +fqbin_to_msg_name(<<"Signed">>) -> 'Signed'; +fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). + + +msg_name_to_fqbin('Signed') -> <<"Signed">>; +msg_name_to_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec fqbin_to_enum_name(_) -> no_return(). +fqbin_to_enum_name(E) -> error({gpb_error, {badenum, E}}). + + +-spec enum_name_to_fqbin(_) -> no_return(). +enum_name_to_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_package_name() -> undefined. + + +%% Whether or not the message names +%% are prepended with package name or not. +uses_packages() -> false. + + +source_basename() -> "hex_pb_signed.proto". + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned with extension, +%% see get_all_proto_names/0 for a version that returns +%% the basenames sans extension +get_all_source_basenames() -> ["hex_pb_signed.proto"]. + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned sans .proto extension, +%% to make it easier to use them with the various get_xyz_containment +%% functions. +get_all_proto_names() -> ["hex_pb_signed"]. + + +get_msg_containment("hex_pb_signed") -> ['Signed']; +get_msg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_pkg_containment("hex_pb_signed") -> undefined; +get_pkg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_service_containment("hex_pb_signed") -> []; +get_service_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_rpc_containment("hex_pb_signed") -> []; +get_rpc_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_enum_containment("hex_pb_signed") -> []; +get_enum_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_proto_by_msg_name_as_fqbin(<<"Signed">>) -> "hex_pb_signed"; +get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec get_proto_by_service_name_as_fqbin(_) -> no_return(). +get_proto_by_service_name_as_fqbin(E) -> error({gpb_error, {badservice, E}}). + + +-spec get_proto_by_enum_name_as_fqbin(_) -> no_return(). +get_proto_by_enum_name_as_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +-spec get_protos_by_pkg_name_as_fqbin(_) -> no_return(). +get_protos_by_pkg_name_as_fqbin(E) -> error({gpb_error, {badpkg, E}}). + + + +gpb_version_as_string() -> + "4.21.1". + +gpb_version_as_list() -> + [4,21,1]. + +gpb_version_source() -> + "file". diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_pb_versions.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_versions.erl new file mode 100644 index 0000000000000000000000000000000000000000..0bade1bccf9dc36e371625d6536132bbf8751f61 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_pb_versions.erl @@ -0,0 +1,816 @@ +%% -*- coding: utf-8 -*- +%% % this file is @generated +%% @private +%% Automatically generated, do not edit +%% Generated by gpb_compile version 4.21.1 +%% Version source: file +-module(hex_pb_versions). + +-export([encode_msg/2, encode_msg/3]). +-export([decode_msg/2, decode_msg/3]). +-export([merge_msgs/3, merge_msgs/4]). +-export([verify_msg/2, verify_msg/3]). +-export([get_msg_defs/0]). +-export([get_msg_names/0]). +-export([get_group_names/0]). +-export([get_msg_or_group_names/0]). +-export([get_enum_names/0]). +-export([find_msg_def/1, fetch_msg_def/1]). +-export([find_enum_def/1, fetch_enum_def/1]). +-export([enum_symbol_by_value/2, enum_value_by_symbol/2]). +-export([get_service_names/0]). +-export([get_service_def/1]). +-export([get_rpc_names/1]). +-export([find_rpc_def/2, fetch_rpc_def/2]). +-export([fqbin_to_service_name/1]). +-export([service_name_to_fqbin/1]). +-export([fqbins_to_service_and_rpc_name/2]). +-export([service_and_rpc_name_to_fqbins/2]). +-export([fqbin_to_msg_name/1]). +-export([msg_name_to_fqbin/1]). +-export([fqbin_to_enum_name/1]). +-export([enum_name_to_fqbin/1]). +-export([get_package_name/0]). +-export([uses_packages/0]). +-export([source_basename/0]). +-export([get_all_source_basenames/0]). +-export([get_all_proto_names/0]). +-export([get_msg_containment/1]). +-export([get_pkg_containment/1]). +-export([get_service_containment/1]). +-export([get_rpc_containment/1]). +-export([get_enum_containment/1]). +-export([get_proto_by_msg_name_as_fqbin/1]). +-export([get_proto_by_service_name_as_fqbin/1]). +-export([get_proto_by_enum_name_as_fqbin/1]). +-export([get_protos_by_pkg_name_as_fqbin/1]). +-export([gpb_version_as_string/0, gpb_version_as_list/0]). +-export([gpb_version_source/0]). + + +%% enumerated types + +-export_type([]). + +%% message types +-type 'Versions'() :: + #{packages => ['Package'()], % = 1, repeated + repository => unicode:chardata() % = 2, required + }. + +-type 'Package'() :: + #{name => unicode:chardata(), % = 1, required + versions => [unicode:chardata()], % = 2, repeated + retired => [integer()] % = 3, repeated, 32 bits + }. + +-export_type(['Versions'/0, 'Package'/0]). +-type '$msg_name'() :: 'Versions' | 'Package'. +-type '$msg'() :: 'Versions'() | 'Package'(). +-export_type(['$msg_name'/0, '$msg'/0]). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/2}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'()) -> binary(). +encode_msg(Msg, MsgName) when is_atom(MsgName) -> encode_msg(Msg, MsgName, []). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/3}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'(), list()) -> binary(). +encode_msg(Msg, MsgName, Opts) -> + verify_msg(Msg, MsgName, Opts), + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Versions' -> encode_msg_Versions(id(Msg, TrUserData), TrUserData); + 'Package' -> encode_msg_Package(id(Msg, TrUserData), TrUserData) + end. + + +encode_msg_Versions(Msg, TrUserData) -> encode_msg_Versions(Msg, <<>>, TrUserData). + + +encode_msg_Versions(#{repository := F2} = M, Bin, TrUserData) -> + B1 = case M of + #{packages := F1} -> + TrF1 = id(F1, TrUserData), + if TrF1 == [] -> Bin; + true -> e_field_Versions_packages(TrF1, Bin, TrUserData) + end; + _ -> Bin + end, + begin TrF2 = id(F2, TrUserData), e_type_string(TrF2, <>, TrUserData) end. + +encode_msg_Package(Msg, TrUserData) -> encode_msg_Package(Msg, <<>>, TrUserData). + + +encode_msg_Package(#{name := F1} = M, Bin, TrUserData) -> + B1 = begin TrF1 = id(F1, TrUserData), e_type_string(TrF1, <>, TrUserData) end, + B2 = case M of + #{versions := F2} -> + TrF2 = id(F2, TrUserData), + if TrF2 == [] -> B1; + true -> e_field_Package_versions(TrF2, B1, TrUserData) + end; + _ -> B1 + end, + case M of + #{retired := F3} -> + TrF3 = id(F3, TrUserData), + if TrF3 == [] -> B2; + true -> e_field_Package_retired(TrF3, B2, TrUserData) + end; + _ -> B2 + end. + +e_mfield_Versions_packages(Msg, Bin, TrUserData) -> + SubBin = encode_msg_Package(Msg, <<>>, TrUserData), + Bin2 = e_varint(byte_size(SubBin), Bin), + <>. + +e_field_Versions_packages([Elem | Rest], Bin, TrUserData) -> + Bin2 = <>, + Bin3 = e_mfield_Versions_packages(id(Elem, TrUserData), Bin2, TrUserData), + e_field_Versions_packages(Rest, Bin3, TrUserData); +e_field_Versions_packages([], Bin, _TrUserData) -> Bin. + +e_field_Package_versions([Elem | Rest], Bin, TrUserData) -> + Bin2 = <>, + Bin3 = e_type_string(id(Elem, TrUserData), Bin2, TrUserData), + e_field_Package_versions(Rest, Bin3, TrUserData); +e_field_Package_versions([], Bin, _TrUserData) -> Bin. + +e_field_Package_retired(Elems, Bin, TrUserData) when Elems =/= [] -> + SubBin = e_pfield_Package_retired(Elems, <<>>, TrUserData), + Bin2 = <>, + Bin3 = e_varint(byte_size(SubBin), Bin2), + <>; +e_field_Package_retired([], Bin, _TrUserData) -> Bin. + +e_pfield_Package_retired([Value | Rest], Bin, TrUserData) -> + Bin2 = e_type_int32(id(Value, TrUserData), Bin, TrUserData), + e_pfield_Package_retired(Rest, Bin2, TrUserData); +e_pfield_Package_retired([], Bin, _TrUserData) -> Bin. + +-compile({nowarn_unused_function,e_type_sint/3}). +e_type_sint(Value, Bin, _TrUserData) when Value >= 0 -> e_varint(Value * 2, Bin); +e_type_sint(Value, Bin, _TrUserData) -> e_varint(Value * -2 - 1, Bin). + +-compile({nowarn_unused_function,e_type_int32/3}). +e_type_int32(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int32(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_int64/3}). +e_type_int64(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int64(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_bool/3}). +e_type_bool(true, Bin, _TrUserData) -> <>; +e_type_bool(false, Bin, _TrUserData) -> <>; +e_type_bool(1, Bin, _TrUserData) -> <>; +e_type_bool(0, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_string/3}). +e_type_string(S, Bin, _TrUserData) -> + Utf8 = unicode:characters_to_binary(S), + Bin2 = e_varint(byte_size(Utf8), Bin), + <>. + +-compile({nowarn_unused_function,e_type_bytes/3}). +e_type_bytes(Bytes, Bin, _TrUserData) when is_binary(Bytes) -> + Bin2 = e_varint(byte_size(Bytes), Bin), + <>; +e_type_bytes(Bytes, Bin, _TrUserData) when is_list(Bytes) -> + BytesBin = iolist_to_binary(Bytes), + Bin2 = e_varint(byte_size(BytesBin), Bin), + <>. + +-compile({nowarn_unused_function,e_type_fixed32/3}). +e_type_fixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed32/3}). +e_type_sfixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_fixed64/3}). +e_type_fixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed64/3}). +e_type_sfixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_float/3}). +e_type_float(V, Bin, _) when is_number(V) -> <>; +e_type_float(infinity, Bin, _) -> <>; +e_type_float('-infinity', Bin, _) -> <>; +e_type_float(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_type_double/3}). +e_type_double(V, Bin, _) when is_number(V) -> <>; +e_type_double(infinity, Bin, _) -> <>; +e_type_double('-infinity', Bin, _) -> <>; +e_type_double(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_unknown_elems/2}). +e_unknown_elems([Elem | Rest], Bin) -> + BinR = case Elem of + {varint, FNum, N} -> + BinF = e_varint(FNum bsl 3, Bin), + e_varint(N, BinF); + {length_delimited, FNum, Data} -> + BinF = e_varint(FNum bsl 3 bor 2, Bin), + BinL = e_varint(byte_size(Data), BinF), + <>; + {group, FNum, GroupFields} -> + Bin1 = e_varint(FNum bsl 3 bor 3, Bin), + Bin2 = e_unknown_elems(GroupFields, Bin1), + e_varint(FNum bsl 3 bor 4, Bin2); + {fixed32, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 5, Bin), + <>; + {fixed64, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 1, Bin), + <> + end, + e_unknown_elems(Rest, BinR); +e_unknown_elems([], Bin) -> Bin. + +-compile({nowarn_unused_function,e_varint/3}). +e_varint(N, Bin, _TrUserData) -> e_varint(N, Bin). + +-compile({nowarn_unused_function,e_varint/2}). +e_varint(N, Bin) when N =< 127 -> <>; +e_varint(N, Bin) -> + Bin2 = <>, + e_varint(N bsr 7, Bin2). + + +decode_msg(Bin, MsgName) when is_binary(Bin) -> decode_msg(Bin, MsgName, []). + +decode_msg(Bin, MsgName, Opts) when is_binary(Bin) -> + TrUserData = proplists:get_value(user_data, Opts), + decode_msg_1_catch(Bin, MsgName, TrUserData). + +-ifdef('OTP_RELEASE'). +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason:StackTrace -> + erlang:raise(error, Reason, StackTrace); + Class:Reason:StackTrace -> error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-else. +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason -> + erlang:raise(error, Reason, + erlang:get_stacktrace()); + Class:Reason -> + StackTrace = erlang:get_stacktrace(), + error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-endif. + +decode_msg_2_doit('Versions', Bin, TrUserData) -> id(decode_msg_Versions(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Package', Bin, TrUserData) -> id(decode_msg_Package(Bin, TrUserData), TrUserData). + + + +decode_msg_Versions(Bin, TrUserData) -> dfp_read_field_def_Versions(Bin, 0, 0, 0, id([], TrUserData), id('$undef', TrUserData), TrUserData). + +dfp_read_field_def_Versions(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Versions_packages(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Versions(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Versions_repository(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Versions(<<>>, 0, 0, _, R1, F@_2, TrUserData) -> + S1 = #{repository => F@_2}, + if R1 == '$undef' -> S1; + true -> S1#{packages => lists_reverse(R1, TrUserData)} + end; +dfp_read_field_def_Versions(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_Versions(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_Versions(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_Versions(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_Versions(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Versions_packages(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_Versions_repository(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Versions(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_Versions(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_Versions(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_Versions(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_Versions(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_Versions(<<>>, 0, 0, _, R1, F@_2, TrUserData) -> + S1 = #{repository => F@_2}, + if R1 == '$undef' -> S1; + true -> S1#{packages => lists_reverse(R1, TrUserData)} + end. + +d_field_Versions_packages(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Versions_packages(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Versions_packages(<<0:1, X:7, Rest/binary>>, N, Acc, F, Prev, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, {id(decode_msg_Package(Bs, TrUserData), TrUserData), Rest2} end, + dfp_read_field_def_Versions(RestF, 0, 0, F, cons(NewFValue, Prev, TrUserData), F@_2, TrUserData). + +d_field_Versions_repository(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Versions_repository(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Versions_repository(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Versions(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_Versions(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_Versions(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_Versions(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Versions(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_Versions(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_Versions(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_Versions(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Versions(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_Versions(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Versions(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_Versions(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Versions(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_Versions(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Versions(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_Package(Bin, TrUserData) -> dfp_read_field_def_Package(Bin, 0, 0, 0, id('$undef', TrUserData), id([], TrUserData), id([], TrUserData), TrUserData). + +dfp_read_field_def_Package(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_name(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_versions(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_pfield_Package_retired(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<24, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Package_retired(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Package(<<>>, 0, 0, _, F@_1, R1, R2, TrUserData) -> #{name => F@_1, versions => lists_reverse(R1, TrUserData), retired => lists_reverse(R2, TrUserData)}; +dfp_read_field_def_Package(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_Package(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +dg_read_field_def_Package(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_Package(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_Package(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Package_name(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 18 -> d_field_Package_versions(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 26 -> d_pfield_Package_retired(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 24 -> d_field_Package_retired(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_Package(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + end + end; +dg_read_field_def_Package(<<>>, 0, 0, _, F@_1, R1, R2, TrUserData) -> #{name => F@_1, versions => lists_reverse(R1, TrUserData), retired => lists_reverse(R2, TrUserData)}. + +d_field_Package_name(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_name(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_name(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Package(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). + +d_field_Package_versions(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_versions(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_versions(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, Prev, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Package(RestF, 0, 0, F, F@_1, cons(NewFValue, Prev, TrUserData), F@_3, TrUserData). + +d_field_Package_retired(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Package_retired(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Package_retired(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, Prev, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_Package(RestF, 0, 0, F, F@_1, F@_2, cons(NewFValue, Prev, TrUserData), TrUserData). + +d_pfield_Package_retired(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_pfield_Package_retired(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_pfield_Package_retired(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, E, TrUserData) -> + Len = X bsl N + Acc, + <> = Rest, + NewSeq = d_packed_field_Package_retired(PackedBytes, 0, 0, F, E, TrUserData), + dfp_read_field_def_Package(Rest2, 0, 0, F, F@_1, F@_2, NewSeq, TrUserData). + +d_packed_field_Package_retired(<<1:1, X:7, Rest/binary>>, N, Acc, F, AccSeq, TrUserData) when N < 57 -> d_packed_field_Package_retired(Rest, N + 7, X bsl N + Acc, F, AccSeq, TrUserData); +d_packed_field_Package_retired(<<0:1, X:7, Rest/binary>>, N, Acc, F, AccSeq, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + d_packed_field_Package_retired(RestF, 0, 0, F, [NewFValue | AccSeq], TrUserData); +d_packed_field_Package_retired(<<>>, 0, 0, _, AccSeq, _) -> AccSeq. + +skip_varint_Package(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_Package(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_length_delimited_Package(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_Package(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_Package(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_Package(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + +skip_group_Package(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Package(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + +skip_32_Package(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_64_Package(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Package(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +read_group(Bin, FieldNum) -> + {NumBytes, EndTagLen} = read_gr_b(Bin, 0, 0, 0, 0, FieldNum), + <> = Bin, + {Group, Rest}. + +%% Like skipping over fields, but record the total length, +%% Each field is <(FieldNum bsl 3) bor FieldType> ++ +%% Record the length because varints may be non-optimally encoded. +%% +%% Groups can be nested, but assume the same FieldNum cannot be nested +%% because group field numbers are shared with the rest of the fields +%% numbers. Thus we can search just for an group-end with the same +%% field number. +%% +%% (The only time the same group field number could occur would +%% be in a nested sub message, but then it would be inside a +%% length-delimited entry, which we skip-read by length.) +read_gr_b(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, FieldNum) + when N < (32-7) -> + read_gr_b(Tl, N+7, X bsl N + Acc, NumBytes, TagLen+1, FieldNum); +read_gr_b(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, + FieldNum) -> + Key = X bsl N + Acc, + TagLen1 = TagLen + 1, + case {Key bsr 3, Key band 7} of + {FieldNum, 4} -> % 4 = group_end + {NumBytes, TagLen1}; + {_, 0} -> % 0 = varint + read_gr_vi(Tl, 0, NumBytes + TagLen1, FieldNum); + {_, 1} -> % 1 = bits64 + <<_:64, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 8, 0, FieldNum); + {_, 2} -> % 2 = length_delimited + read_gr_ld(Tl, 0, 0, NumBytes + TagLen1, FieldNum); + {_, 3} -> % 3 = group_start + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 4} -> % 4 = group_end + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 5} -> % 5 = bits32 + <<_:32, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 4, 0, FieldNum) + end. + +read_gr_vi(<<1:1, _:7, Tl/binary>>, N, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_vi(Tl, N+7, NumBytes+1, FieldNum); +read_gr_vi(<<0:1, _:7, Tl/binary>>, _, NumBytes, FieldNum) -> + read_gr_b(Tl, 0, 0, NumBytes+1, 0, FieldNum). + +read_gr_ld(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_ld(Tl, N+7, X bsl N + Acc, NumBytes+1, FieldNum); +read_gr_ld(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) -> + Len = X bsl N + Acc, + NumBytes1 = NumBytes + 1, + <<_:Len/binary, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes1 + Len, 0, FieldNum). + +merge_msgs(Prev, New, MsgName) when is_atom(MsgName) -> merge_msgs(Prev, New, MsgName, []). + +merge_msgs(Prev, New, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Versions' -> merge_msg_Versions(Prev, New, TrUserData); + 'Package' -> merge_msg_Package(Prev, New, TrUserData) + end. + +-compile({nowarn_unused_function,merge_msg_Versions/3}). +merge_msg_Versions(#{} = PMsg, #{repository := NFrepository} = NMsg, TrUserData) -> + S1 = #{repository => NFrepository}, + case {PMsg, NMsg} of + {#{packages := PFpackages}, #{packages := NFpackages}} -> S1#{packages => 'erlang_++'(PFpackages, NFpackages, TrUserData)}; + {_, #{packages := NFpackages}} -> S1#{packages => NFpackages}; + {#{packages := PFpackages}, _} -> S1#{packages => PFpackages}; + {_, _} -> S1 + end. + +-compile({nowarn_unused_function,merge_msg_Package/3}). +merge_msg_Package(#{} = PMsg, #{name := NFname} = NMsg, TrUserData) -> + S1 = #{name => NFname}, + S2 = case {PMsg, NMsg} of + {#{versions := PFversions}, #{versions := NFversions}} -> S1#{versions => 'erlang_++'(PFversions, NFversions, TrUserData)}; + {_, #{versions := NFversions}} -> S1#{versions => NFversions}; + {#{versions := PFversions}, _} -> S1#{versions => PFversions}; + {_, _} -> S1 + end, + case {PMsg, NMsg} of + {#{retired := PFretired}, #{retired := NFretired}} -> S2#{retired => 'erlang_++'(PFretired, NFretired, TrUserData)}; + {_, #{retired := NFretired}} -> S2#{retired => NFretired}; + {#{retired := PFretired}, _} -> S2#{retired => PFretired}; + {_, _} -> S2 + end. + + +verify_msg(Msg, MsgName) when is_atom(MsgName) -> verify_msg(Msg, MsgName, []). + +verify_msg(Msg, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'Versions' -> v_msg_Versions(Msg, [MsgName], TrUserData); + 'Package' -> v_msg_Package(Msg, [MsgName], TrUserData); + _ -> mk_type_error(not_a_known_message, Msg, []) + end. + + +-compile({nowarn_unused_function,v_msg_Versions/3}). +-dialyzer({nowarn_function,v_msg_Versions/3}). +v_msg_Versions(#{repository := F2} = M, Path, TrUserData) -> + case M of + #{packages := F1} -> + if is_list(F1) -> + _ = [v_submsg_Package(Elem, [packages | Path], TrUserData) || Elem <- F1], + ok; + true -> mk_type_error({invalid_list_of, {msg, 'Package'}}, F1, [packages | Path]) + end; + _ -> ok + end, + v_type_string(F2, [repository | Path], TrUserData), + lists:foreach(fun (packages) -> ok; + (repository) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Versions(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [repository] -- maps:keys(M), 'Versions'}, M, Path); +v_msg_Versions(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Versions'}, X, Path). + +-compile({nowarn_unused_function,v_submsg_Package/3}). +-dialyzer({nowarn_function,v_submsg_Package/3}). +v_submsg_Package(Msg, Path, TrUserData) -> v_msg_Package(Msg, Path, TrUserData). + +-compile({nowarn_unused_function,v_msg_Package/3}). +-dialyzer({nowarn_function,v_msg_Package/3}). +v_msg_Package(#{name := F1} = M, Path, TrUserData) -> + v_type_string(F1, [name | Path], TrUserData), + case M of + #{versions := F2} -> + if is_list(F2) -> + _ = [v_type_string(Elem, [versions | Path], TrUserData) || Elem <- F2], + ok; + true -> mk_type_error({invalid_list_of, string}, F2, [versions | Path]) + end; + _ -> ok + end, + case M of + #{retired := F3} -> + if is_list(F3) -> + _ = [v_type_int32(Elem, [retired | Path], TrUserData) || Elem <- F3], + ok; + true -> mk_type_error({invalid_list_of, int32}, F3, [retired | Path]) + end; + _ -> ok + end, + lists:foreach(fun (name) -> ok; + (versions) -> ok; + (retired) -> ok; + (OtherKey) -> mk_type_error({extraneous_key, OtherKey}, M, Path) + end, + maps:keys(M)), + ok; +v_msg_Package(M, Path, _TrUserData) when is_map(M) -> mk_type_error({missing_fields, [name] -- maps:keys(M), 'Package'}, M, Path); +v_msg_Package(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Package'}, X, Path). + +-compile({nowarn_unused_function,v_type_int32/3}). +-dialyzer({nowarn_function,v_type_int32/3}). +v_type_int32(N, _Path, _TrUserData) when is_integer(N), -2147483648 =< N, N =< 2147483647 -> ok; +v_type_int32(N, Path, _TrUserData) when is_integer(N) -> mk_type_error({value_out_of_range, int32, signed, 32}, N, Path); +v_type_int32(X, Path, _TrUserData) -> mk_type_error({bad_integer, int32, signed, 32}, X, Path). + +-compile({nowarn_unused_function,v_type_string/3}). +-dialyzer({nowarn_function,v_type_string/3}). +v_type_string(S, Path, _TrUserData) when is_list(S); is_binary(S) -> + try unicode:characters_to_binary(S) of + B when is_binary(B) -> ok; + {error, _, _} -> mk_type_error(bad_unicode_string, S, Path) + catch + error:badarg -> mk_type_error(bad_unicode_string, S, Path) + end; +v_type_string(X, Path, _TrUserData) -> mk_type_error(bad_unicode_string, X, Path). + +-compile({nowarn_unused_function,mk_type_error/3}). +-spec mk_type_error(_, _, list()) -> no_return(). +mk_type_error(Error, ValueSeen, Path) -> + Path2 = prettify_path(Path), + erlang:error({gpb_type_error, {Error, [{value, ValueSeen}, {path, Path2}]}}). + + +-compile({nowarn_unused_function,prettify_path/1}). +-dialyzer({nowarn_function,prettify_path/1}). +prettify_path([]) -> top_level; +prettify_path(PathR) -> lists:append(lists:join(".", lists:map(fun atom_to_list/1, lists:reverse(PathR)))). + + +-compile({nowarn_unused_function,id/2}). +-compile({inline,id/2}). +id(X, _TrUserData) -> X. + +-compile({nowarn_unused_function,v_ok/3}). +-compile({inline,v_ok/3}). +v_ok(_Value, _Path, _TrUserData) -> ok. + +-compile({nowarn_unused_function,m_overwrite/3}). +-compile({inline,m_overwrite/3}). +m_overwrite(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,cons/3}). +-compile({inline,cons/3}). +cons(Elem, Acc, _TrUserData) -> [Elem | Acc]. + +-compile({nowarn_unused_function,lists_reverse/2}). +-compile({inline,lists_reverse/2}). +'lists_reverse'(L, _TrUserData) -> lists:reverse(L). +-compile({nowarn_unused_function,'erlang_++'/3}). +-compile({inline,'erlang_++'/3}). +'erlang_++'(A, B, _TrUserData) -> A ++ B. + + +get_msg_defs() -> + [{{msg, 'Versions'}, [#{name => packages, fnum => 1, rnum => 2, type => {msg, 'Package'}, occurrence => repeated, opts => []}, #{name => repository, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}]}, + {{msg, 'Package'}, + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => versions, fnum => 2, rnum => 3, type => string, occurrence => repeated, opts => []}, + #{name => retired, fnum => 3, rnum => 4, type => int32, occurrence => repeated, opts => [packed]}]}]. + + +get_msg_names() -> ['Versions', 'Package']. + + +get_group_names() -> []. + + +get_msg_or_group_names() -> ['Versions', 'Package']. + + +get_enum_names() -> []. + + +fetch_msg_def(MsgName) -> + case find_msg_def(MsgName) of + Fs when is_list(Fs) -> Fs; + error -> erlang:error({no_such_msg, MsgName}) + end. + + +-spec fetch_enum_def(_) -> no_return(). +fetch_enum_def(EnumName) -> erlang:error({no_such_enum, EnumName}). + + +find_msg_def('Versions') -> [#{name => packages, fnum => 1, rnum => 2, type => {msg, 'Package'}, occurrence => repeated, opts => []}, #{name => repository, fnum => 2, rnum => 3, type => string, occurrence => required, opts => []}]; +find_msg_def('Package') -> + [#{name => name, fnum => 1, rnum => 2, type => string, occurrence => required, opts => []}, + #{name => versions, fnum => 2, rnum => 3, type => string, occurrence => repeated, opts => []}, + #{name => retired, fnum => 3, rnum => 4, type => int32, occurrence => repeated, opts => [packed]}]; +find_msg_def(_) -> error. + + +find_enum_def(_) -> error. + + +-spec enum_symbol_by_value(_, _) -> no_return(). +enum_symbol_by_value(E, V) -> erlang:error({no_enum_defs, E, V}). + + +-spec enum_value_by_symbol(_, _) -> no_return(). +enum_value_by_symbol(E, V) -> erlang:error({no_enum_defs, E, V}). + + + +get_service_names() -> []. + + +get_service_def(_) -> error. + + +get_rpc_names(_) -> error. + + +find_rpc_def(_, _) -> error. + + + +-spec fetch_rpc_def(_, _) -> no_return(). +fetch_rpc_def(ServiceName, RpcName) -> erlang:error({no_such_rpc, ServiceName, RpcName}). + + +%% Convert a a fully qualified (ie with package name) service name +%% as a binary to a service name as an atom. +-spec fqbin_to_service_name(_) -> no_return(). +fqbin_to_service_name(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a service name as an atom to a fully qualified +%% (ie with package name) name as a binary. +-spec service_name_to_fqbin(_) -> no_return(). +service_name_to_fqbin(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a a fully qualified (ie with package name) service name +%% and an rpc name, both as binaries to a service name and an rpc +%% name, as atoms. +-spec fqbins_to_service_and_rpc_name(_, _) -> no_return(). +fqbins_to_service_and_rpc_name(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +%% Convert a service name and an rpc name, both as atoms, +%% to a fully qualified (ie with package name) service name and +%% an rpc name as binaries. +-spec service_and_rpc_name_to_fqbins(_, _) -> no_return(). +service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +fqbin_to_msg_name(<<"Versions">>) -> 'Versions'; +fqbin_to_msg_name(<<"Package">>) -> 'Package'; +fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). + + +msg_name_to_fqbin('Versions') -> <<"Versions">>; +msg_name_to_fqbin('Package') -> <<"Package">>; +msg_name_to_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec fqbin_to_enum_name(_) -> no_return(). +fqbin_to_enum_name(E) -> error({gpb_error, {badenum, E}}). + + +-spec enum_name_to_fqbin(_) -> no_return(). +enum_name_to_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_package_name() -> undefined. + + +%% Whether or not the message names +%% are prepended with package name or not. +uses_packages() -> false. + + +source_basename() -> "hex_pb_versions.proto". + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned with extension, +%% see get_all_proto_names/0 for a version that returns +%% the basenames sans extension +get_all_source_basenames() -> ["hex_pb_versions.proto"]. + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned sans .proto extension, +%% to make it easier to use them with the various get_xyz_containment +%% functions. +get_all_proto_names() -> ["hex_pb_versions"]. + + +get_msg_containment("hex_pb_versions") -> ['Package', 'Versions']; +get_msg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_pkg_containment("hex_pb_versions") -> undefined; +get_pkg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_service_containment("hex_pb_versions") -> []; +get_service_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_rpc_containment("hex_pb_versions") -> []; +get_rpc_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_enum_containment("hex_pb_versions") -> []; +get_enum_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_proto_by_msg_name_as_fqbin(<<"Versions">>) -> "hex_pb_versions"; +get_proto_by_msg_name_as_fqbin(<<"Package">>) -> "hex_pb_versions"; +get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec get_proto_by_service_name_as_fqbin(_) -> no_return(). +get_proto_by_service_name_as_fqbin(E) -> error({gpb_error, {badservice, E}}). + + +-spec get_proto_by_enum_name_as_fqbin(_) -> no_return(). +get_proto_by_enum_name_as_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +-spec get_protos_by_pkg_name_as_fqbin(_) -> no_return(). +get_protos_by_pkg_name_as_fqbin(E) -> error({gpb_error, {badpkg, E}}). + + + +gpb_version_as_string() -> + "4.21.1". + +gpb_version_as_list() -> + [4,21,1]. + +gpb_version_source() -> + "file". diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_registry.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_registry.erl new file mode 100644 index 0000000000000000000000000000000000000000..9bb9cb5a9222640657054499cb98986013c41e8d --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_registry.erl @@ -0,0 +1,165 @@ +%% @doc +%% Functions for encoding and decoding Hex registries. +-module(hex_registry). +-export([ + encode_names/1, + decode_names/2, + build_names/2, + unpack_names/3, + encode_versions/1, + decode_versions/2, + build_versions/2, + unpack_versions/3, + encode_package/1, + decode_package/3, + build_package/2, + unpack_package/4, + sign_protobuf/2, + decode_signed/1, + decode_and_verify_signed/2, + sign/2, + verify/3 +]). +-include_lib("public_key/include/public_key.hrl"). + +-type private_key() :: #'RSAPrivateKey'{} | binary(). +-type public_key() :: #'RSAPublicKey'{} | binary(). + +%%==================================================================== +%% API functions +%%==================================================================== + +%% @doc +%% Builds names resource. +build_names(Names, PrivateKey) -> + Payload = encode_names(Names), + zlib:gzip(sign_protobuf(Payload, PrivateKey)). + +%% @doc +%% Unpacks names resource. +unpack_names(Payload, Repository, PublicKey) -> + case decode_and_verify_signed(zlib:gunzip(Payload), PublicKey) of + {ok, Names} -> decode_names(Names, Repository); + Other -> Other + end. + +%% @private +encode_names(Names) -> + hex_pb_names:encode_msg(Names, 'Names'). + +%% @private +decode_names(Payload, no_verify) -> + {ok, hex_pb_names:decode_msg(Payload, 'Names')}; +decode_names(Payload, Repository) -> + case hex_pb_names:decode_msg(Payload, 'Names') of + #{repository := Repository, packages := _Packages} = Result -> + {ok, Result}; + _ -> + {error, bad_repo_name} + end. + +%% @doc +%% Builds versions resource. +build_versions(Versions, PrivateKey) -> + Payload = encode_versions(Versions), + zlib:gzip(sign_protobuf(Payload, PrivateKey)). + +%% @doc +%% Unpacks versions resource. +unpack_versions(Payload, Repository, PublicKey) -> + case decode_and_verify_signed(zlib:gunzip(Payload), PublicKey) of + {ok, Versions} -> decode_versions(Versions, Repository); + Other -> Other + end. + +%% @private +encode_versions(Versions) -> + hex_pb_versions:encode_msg(Versions, 'Versions'). + +%% @private +decode_versions(Payload, no_verify) -> + {ok, hex_pb_versions:decode_msg(Payload, 'Versions')}; +decode_versions(Payload, Repository) -> + case hex_pb_versions:decode_msg(Payload, 'Versions') of + #{repository := Repository, packages := _Packages} = Result -> + {ok, Result}; + _ -> + {error, bad_repo_name} + end. + +%% @doc +%% Builds package resource. +build_package(Package, PrivateKey) -> + Payload = encode_package(Package), + zlib:gzip(sign_protobuf(Payload, PrivateKey)). + +%% @doc +%% Unpacks package resource. +unpack_package(Payload, Repository, Name, PublicKey) -> + case decode_and_verify_signed(zlib:gunzip(Payload), PublicKey) of + {ok, Package} -> decode_package(Package, Repository, Name); + Other -> Other + end. + +%% @private +encode_package(Package) -> + hex_pb_package:encode_msg(Package, 'Package'). + +%% @private +decode_package(Payload, no_verify, no_verify) -> + {ok, hex_pb_package:decode_msg(Payload, 'Package')}; +decode_package(Payload, Repository, Package) -> + case hex_pb_package:decode_msg(Payload, 'Package') of + #{repository := Repository, name := Package, releases := _Releases} = Result -> + {ok, Result}; + _ -> + {error, bad_repo_name} + end. + +%% @private +sign_protobuf(Payload, PrivateKey) -> + Signature = sign(Payload, PrivateKey), + hex_pb_signed:encode_msg(#{payload => Payload, signature => Signature}, 'Signed'). + +%% @private +decode_signed(Signed) -> + hex_pb_signed:decode_msg(Signed, 'Signed'). + +%% @private +-spec decode_and_verify_signed(binary(), public_key()) -> {ok, binary()} | {error, term()}. +decode_and_verify_signed(Signed, PublicKey) -> + #{payload := Payload, signature := Signature} = decode_signed(Signed), + case verify(Payload, Signature, PublicKey) of + true -> {ok, Payload}; + false -> {error, bad_signature}; + {error, Reason} -> {error, Reason} + end. + +%% @private +-spec sign(binary(), private_key()) -> binary(). +sign(Binary, PrivateKey) -> + {ok, RSAPrivateKey} = key(PrivateKey), + public_key:sign(Binary, sha512, RSAPrivateKey). + +%% @private +-spec verify(binary(), binary(), public_key()) -> boolean() | {error, term()}. +verify(Binary, Signature, PublicKey) -> + case key(PublicKey) of + {ok, RSAPublicKey} -> public_key:verify(Binary, sha512, Signature, RSAPublicKey); + {error, Reason} -> {error, Reason} + end. + +%%==================================================================== +%% Internal functions +%%==================================================================== + +%% @private +key(#'RSAPublicKey'{} = Key) -> + {ok, Key}; +key(#'RSAPrivateKey'{} = Key) -> + {ok, Key}; +key(Binary) when is_binary(Binary) -> + case public_key:pem_decode(Binary) of + [Entry | _] -> {ok, public_key:pem_entry_decode(Entry)}; + _ -> {error, bad_key} + end. diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_safe_binary_to_term.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_safe_binary_to_term.erl new file mode 100644 index 0000000000000000000000000000000000000000..1086417a4bf6f2618a3ff4f9441b0b1bed1fe5cb --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_safe_binary_to_term.erl @@ -0,0 +1,92 @@ +%% @hidden +%% Safe deserialization of Erlang terms from binary. +%% +%% This module provides a restricted version of `binary_to_term/1' that: +%% - Uses the `safe' option to prevent creation of new atoms (DoS protection) +%% - Validates that the term contains no executable code (RCE protection) +%% +%% Inspired by Plug.Crypto's non_executable_binary_to_term: +%% https://github.com/elixir-plug/plug_crypto/blob/c326c3c743b18cf5f4b12735d06dd90c72dcd779/lib/plug/crypto.ex +-module(hex_safe_binary_to_term). + +-export([safe_binary_to_term/1]). + +-type unsafe_term() :: function() | port(). +-type error_reason() :: invalid_term | {unsafe_term, unsafe_term()}. + +-spec safe_binary_to_term(binary()) -> {ok, term()} | {error, error_reason()}. +safe_binary_to_term(Binary) when is_binary(Binary) -> + try binary_to_term(Binary, [safe]) of + Term -> + case validate_term(Term) of + ok -> {ok, Term}; + {error, _} = Error -> Error + end + catch + error:badarg -> + {error, invalid_term} + end. + +-spec validate_term(term()) -> ok | {error, {unsafe_term, term()}}. +validate_term(Term) when is_list(Term) -> + validate_list(Term); +validate_term(Term) when is_tuple(Term) -> + validate_tuple(Term, tuple_size(Term)); +validate_term(Term) when is_map(Term) -> + validate_map(Term); +validate_term(Term) when + is_atom(Term); + is_number(Term); + is_bitstring(Term); + is_pid(Term); + is_reference(Term) +-> + ok; +validate_term(Term) -> + {error, {unsafe_term, Term}}. + +-spec validate_list(list()) -> ok | {error, {unsafe_term, term()}}. +validate_list([]) -> + ok; +validate_list([H | T]) when is_list(T) -> + case validate_term(H) of + ok -> validate_list(T); + Error -> Error + end; +validate_list([H | T]) -> + %% Improper list + case validate_term(H) of + ok -> validate_term(T); + Error -> Error + end. + +-spec validate_tuple(tuple(), non_neg_integer()) -> ok | {error, {unsafe_term, term()}}. +validate_tuple(_Tuple, 0) -> + ok; +validate_tuple(Tuple, N) -> + case validate_term(element(N, Tuple)) of + ok -> validate_tuple(Tuple, N - 1); + Error -> Error + end. + +-spec validate_map(map()) -> ok | {error, {unsafe_term, term()}}. +validate_map(Map) -> + try + maps:fold( + fun(Key, Value, ok) -> + case validate_term(Key) of + ok -> + case validate_term(Value) of + ok -> ok; + Error -> throw(Error) + end; + Error -> + throw(Error) + end + end, + ok, + Map + ) + catch + throw:{error, _} = Error -> Error + end. diff --git a/deps/eini/_build/default/plugins/hex_core/src/hex_tarball.erl b/deps/eini/_build/default/plugins/hex_core/src/hex_tarball.erl new file mode 100644 index 0000000000000000000000000000000000000000..51247b40083cef3a43aacb13a284780b1bb6b84a --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/hex_tarball.erl @@ -0,0 +1,717 @@ +%% @doc +%% Functions for creating and unpacking Hex tarballs. +-module(hex_tarball). +-export([ + create/2, create/3, + create_docs/1, create_docs/2, + unpack/2, unpack/3, + unpack_docs/2, unpack_docs/3, + format_checksum/1, + format_error/1 +]). +-ifdef(TEST). +-export([do_decode_metadata/1, gzip/1, normalize_requirements/1]). +-endif. +-define(VERSION, <<"3">>). +-define(BUILD_TOOL_FILES, [ + {<<"mix.exs">>, <<"mix">>}, + {<<"rebar.config">>, <<"rebar3">>}, + {<<"rebar">>, <<"rebar3">>}, + {<<"Makefile">>, <<"make">>}, + {<<"Makefile.win">>, <<"make">>} +]). +-include_lib("kernel/include/file.hrl"). + +-type checksum() :: binary(). +-type contents() :: #{filename() => binary()}. +-type filename() :: string(). +-type files() :: [{filename(), filename() | binary()}]. +-type metadata() :: map(). +-type tarball() :: binary(). + +%%==================================================================== +%% API functions +%%==================================================================== + +%% @doc +%% Creates a package tarball. +%% +%% Returns the binary of the tarball the "inner checksum" and "outer checksum". +%% The inner checksum is deprecated in favor of the outer checksum. +%% +%% Examples: +%% +%% ``` +%% > Metadata = #{<<"name">> => <<"foo">>, <<"version">> => <<"1.0.0">>}, +%% > Files = [{"src/foo.erl", <<"-module(foo).">>}], +%% > hex_tarball:create(Metadata, Files). +%% {ok, #{tarball => <<86,69,...>>, +%% outer_checksum => <<40,32,...>>, +%% inner_checksum => <<178,12,...>>}} +%% ''' +%% @end +-spec create(metadata(), files(), hex_core:config()) -> + {ok, #{ + tarball => tarball(), + outer_checksum => checksum(), + inner_checksum => tarball() + }} + | {error, term()}. +create(Metadata, Files, Config) -> + #{ + tarball_max_size := TarballMaxSize, + tarball_max_uncompressed_size := TarballMaxUncompressedSize + } = Config, + + MetadataBinary = encode_metadata(Metadata), + ContentsTarball = create_memory_tarball(Files), + ContentsTarballCompressed = gzip(ContentsTarball), + InnerChecksum = inner_checksum(?VERSION, MetadataBinary, ContentsTarballCompressed), + InnerChecksumBase16 = encode_base16(InnerChecksum), + TarballMaxSize = maps:get(tarball_max_size, Config), + TarballMaxUncompressedSize = maps:get(tarball_max_uncompressed_size, Config), + + OuterFiles = [ + {"VERSION", ?VERSION}, + {"CHECKSUM", InnerChecksumBase16}, + {"metadata.config", MetadataBinary}, + {"contents.tar.gz", ContentsTarballCompressed} + ], + + case valid_size(ContentsTarball, TarballMaxUncompressedSize) of + true -> + Tarball = create_memory_tarball(OuterFiles), + OuterChecksum = checksum(Tarball), + + case valid_size(Tarball, TarballMaxSize) of + true -> + {ok, #{ + tarball => Tarball, + outer_checksum => OuterChecksum, + inner_checksum => InnerChecksum + }}; + false -> + {error, {tarball, {too_big_compressed, TarballMaxSize}}} + end; + false -> + {error, {tarball, {too_big_uncompressed, TarballMaxUncompressedSize}}} + end. + +-spec create(metadata(), files()) -> + {ok, #{ + tarball => tarball(), + outer_checksum => checksum(), + inner_checksum => tarball() + }} + | {error, term()}. +create(Metadata, Files) -> + create(Metadata, Files, hex_core:default_config()). + +%% @doc +%% Creates a docs tarball. +%% +%% Examples: +%% +%% ``` +%% > Files = [{"doc/index.html", <<"Docs">>}], +%% > hex_tarball:create_docs(Files). +%% {ok, <<86,69,...>>} +%% ''' +%% @end +-spec create_docs(files(), hex_core:config()) -> {ok, tarball()} | {error, term()}. +create_docs(Files, Config) -> + #{ + docs_tarball_max_size := TarballMaxSize, + docs_tarball_max_uncompressed_size := TarballMaxUncompressedSize + } = Config, + + UncompressedTarball = create_memory_tarball(Files), + + case valid_size(UncompressedTarball, TarballMaxUncompressedSize) of + true -> + Tarball = gzip(UncompressedTarball), + + case valid_size(Tarball, TarballMaxSize) of + true -> + {ok, Tarball}; + false -> + {error, {tarball, {too_big_compressed, TarballMaxSize}}} + end; + false -> + {error, {tarball, {too_big_uncompressed, TarballMaxUncompressedSize}}} + end. + +-spec create_docs(files()) -> {ok, tarball()} | {error, term()}. +create_docs(Files) -> + create_docs(Files, hex_core:default_config()). + +%% @doc +%% Unpacks a package tarball. +%% +%% Remember to verify the outer tarball checksum against the registry checksum +%% returned from `hex_repo:get_package(Config, Package)'. +%% +%% Examples: +%% +%% ``` +%% > hex_tarball:unpack(Tarball, memory). +%% {ok,#{outer_checksum => <<...>>, +%% contents => [{"src/foo.erl",<<"-module(foo).">>}], +%% metadata => #{<<"name">> => <<"foo">>, ...}}} +%% +%% > hex_tarball:unpack(Tarball, "path/to/unpack"). +%% {ok,#{outer_checksum => <<...>>, +%% metadata => #{<<"name">> => <<"foo">>, ...}}} +%% ''' +-spec unpack + (tarball(), memory, hex_core:config()) -> + {ok, #{ + outer_checksum => checksum(), + inner_checksum => checksum(), + metadata => metadata(), + contents => contents() + }} + | {error, term()}; + (tarball(), filename(), hex_core:config()) -> + {ok, #{ + outer_checksum => checksum(), + inner_checksum => checksum(), + metadata => metadata() + }} + | {error, term()}. +unpack(Tarball, Output, Config) -> + case valid_size(Tarball, maps:get(tarball_max_size, Config)) of + true -> + case hex_erl_tar:extract({binary, Tarball}, [memory]) of + {ok, []} -> + {error, {tarball, empty}}; + {ok, FileList} -> + OuterChecksum = crypto:hash(sha256, Tarball), + do_unpack(maps:from_list(FileList), OuterChecksum, Output); + {error, Reason} -> + {error, {tarball, Reason}} + end; + false -> + {error, {tarball, too_big}} + end. + +%% @doc +%% Unpacks a package tarball. +%% +%% @see unpack/3 +-spec unpack + (tarball(), memory) -> + {ok, #{ + outer_checksum => checksum(), + inner_checksum => checksum(), + metadata => metadata(), + contents => contents() + }} + | {error, term()}; + (tarball(), filename()) -> + {ok, #{ + outer_checksum => checksum(), + inner_checksum => checksum(), + metadata => metadata() + }} + | {error, term()}. +unpack(Tarball, Output) -> + unpack(Tarball, Output, hex_core:default_config()). + +%% @doc +%% Unpacks a documentation tarball. +%% +%% Examples: +%% +%% ``` +%% > hex_tarball:unpack_docs(Tarball, memory). +%% {ok, [{"index.html", <<"">>}, ...]} +%% +%% > hex_tarball:unpack_docs(Tarball, "path/to/unpack"). +%% ok +%% ''' +-spec unpack_docs + (tarball(), memory, hex_core:config()) -> {ok, contents()} | {error, term()}; + (tarball(), filename(), hex_core:config()) -> ok | {error, term()}. +unpack_docs(Tarball, Output, Config) -> + case valid_size(Tarball, maps:get(docs_tarball_max_size, Config)) of + true -> + unpack_tarball(Tarball, Output); + false -> + {error, {tarball, too_big}} + end. + +-spec unpack_docs + (tarball(), memory) -> {ok, contents()} | {error, term()}; + (tarball(), filename()) -> ok | {error, term()}. +unpack_docs(Tarball, Output) -> + unpack_docs(Tarball, Output, hex_core:default_config()). + +%% @doc +%% Returns base16-encoded representation of checksum. +-spec format_checksum(checksum()) -> binary(). +format_checksum(Checksum) -> + encode_base16(Checksum). + +%% @doc +%% Converts an error reason term to a human-readable error message string. +-spec format_error(term()) -> string(). +format_error({tarball, empty}) -> + "empty tarball"; +format_error({tarball, {too_big_uncompressed, Size}}) -> + io_lib:format("package exceeds max uncompressed size ~w ~s", [format_byte_size(Size), "MB"]); +format_error({tarball, {too_big_compressed, Size}}) -> + io_lib:format("package exceeds max compressed size ~w ~s", [format_byte_size(Size), "MB"]); +format_error({tarball, {missing_files, Files}}) -> + io_lib:format("missing files: ~p", [Files]); +format_error({tarball, {bad_version, Vsn}}) -> + io_lib:format("unsupported version: ~p", [Vsn]); +format_error({tarball, invalid_checksum}) -> + "invalid tarball checksum"; +format_error({tarball, Reason}) -> + "tarball error, " ++ hex_erl_tar:format_error(Reason); +format_error({inner_tarball, Reason}) -> + "inner tarball error, " ++ hex_erl_tar:format_error(Reason); +format_error({metadata, invalid_terms}) -> + "error reading package metadata: invalid terms"; +format_error({metadata, not_key_value}) -> + "error reading package metadata: not in key-value format"; +format_error({metadata, Reason}) -> + "error reading package metadata" ++ safe_erl_term:format_error(Reason); +format_error({checksum_mismatch, ExpectedChecksum, ActualChecksum}) -> + io_lib:format( + "tarball checksum mismatch~n~n" ++ + "Expected (base16-encoded): ~s~n" ++ + "Actual (base16-encoded): ~s", + [encode_base16(ExpectedChecksum), encode_base16(ActualChecksum)] + ). + +format_byte_size(Size) -> + Size / 1000000. + +%%==================================================================== +%% Internal functions +%%==================================================================== + +%% @private +inner_checksum(Version, MetadataBinary, ContentsBinary) -> + Blob = <>, + crypto:hash(sha256, Blob). + +%% @private +checksum(ContentsBinary) when is_binary(ContentsBinary) -> + crypto:hash(sha256, ContentsBinary). + +%% @private +encode_metadata(Meta) -> + Data = lists:map( + fun(MetaPair) -> + String = io_lib_pretty:print(binarify(MetaPair), [{encoding, utf8}]), + unicode:characters_to_binary([String, ".\n"]) + end, + maps:to_list(Meta) + ), + iolist_to_binary(Data). + +%% @private +do_unpack(Files, OuterChecksum, Output) -> + State = #{ + inner_checksum => undefined, + outer_checksum => OuterChecksum, + contents => undefined, + files => Files, + metadata => undefined, + output => Output + }, + State1 = check_files(State), + State2 = check_version(State1), + State3 = check_inner_checksum(State2), + State4 = decode_metadata(State3), + finish_unpack(State4). + +%% @private +finish_unpack({error, _} = Error) -> + Error; +finish_unpack(#{ + metadata := Metadata, + files := Files, + inner_checksum := InnerChecksum, + outer_checksum := OuterChecksum, + output := Output +}) -> + _ = maps:get("VERSION", Files), + ContentsBinary = maps:get("contents.tar.gz", Files), + + case Output of + memory -> ok; + _ -> filelib:ensure_dir(filename:join(Output, "*")) + end, + + case unpack_tarball(ContentsBinary, Output) of + ok -> + copy_metadata_config(Output, maps:get("metadata.config", Files)), + {ok, #{ + inner_checksum => InnerChecksum, + outer_checksum => OuterChecksum, + metadata => Metadata + }}; + {ok, Contents} -> + {ok, #{ + inner_checksum => InnerChecksum, + outer_checksum => OuterChecksum, + metadata => Metadata, + contents => Contents + }}; + {error, Reason} -> + {error, {inner_tarball, Reason}} + end. + +%% @private +copy_metadata_config(Output, MetadataBinary) -> + ok = file:write_file(filename:join(Output, "hex_metadata.config"), MetadataBinary). + +%% @private +check_files(#{files := Files} = State) -> + RequiredFiles = ["VERSION", "CHECKSUM", "metadata.config", "contents.tar.gz"], + case diff_keys(Files, RequiredFiles, []) of + ok -> + State; + {error, {missing_keys, Keys}} -> + {error, {tarball, {missing_files, Keys}}} + end. + +%% @private +check_version({error, _} = Error) -> + Error; +check_version(#{files := Files} = State) -> + case maps:get("VERSION", Files) of + <<"3">> -> + State; + Version -> + {error, {tarball, {bad_version, Version}}} + end. + +%% @private +% Note: This checksum is deprecated +check_inner_checksum({error, _} = Error) -> + Error; +check_inner_checksum(#{files := Files} = State) -> + ChecksumBase16 = maps:get("CHECKSUM", Files), + ExpectedChecksum = decode_base16(ChecksumBase16), + + Version = maps:get("VERSION", Files), + MetadataBinary = maps:get("metadata.config", Files), + ContentsBinary = maps:get("contents.tar.gz", Files), + ActualChecksum = inner_checksum(Version, MetadataBinary, ContentsBinary), + + if + byte_size(ExpectedChecksum) /= 32 -> + {error, {tarball, invalid_inner_checksum}}; + ExpectedChecksum == ActualChecksum -> + maps:put(inner_checksum, ExpectedChecksum, State); + true -> + {error, {tarball, {inner_checksum_mismatch, ExpectedChecksum, ActualChecksum}}} + end. + +%% @private +decode_metadata({error, _} = Error) -> + Error; +decode_metadata(#{files := #{"metadata.config" := Binary}} = State) when is_binary(Binary) -> + case do_decode_metadata(Binary) of + #{} = Metadata -> maps:put(metadata, normalize_metadata(Metadata), State); + Other -> Other + end. + +%% @private +do_decode_metadata(Binary) when is_binary(Binary) -> + {ok, String} = characters_to_list(Binary), + + case safe_erl_term:string(String) of + {ok, Tokens, _Line} -> + try + Terms = safe_erl_term:terms(Tokens), + maps:from_list(Terms) + catch + error:function_clause -> + {error, {metadata, invalid_terms}}; + error:badarg -> + {error, {metadata, not_key_value}} + end; + {error, {_Line, safe_erl_term, Reason}, _Line2} -> + {error, {metadata, Reason}} + end. + +%% @private +characters_to_list(Binary) -> + case unicode:characters_to_list(Binary) of + List when is_list(List) -> + {ok, List}; + {error, _, _} -> + case unicode:characters_to_list(Binary, latin1) of + List when is_list(List) -> {ok, List}; + Other -> Other + end + end. + +%% @private +normalize_metadata(Metadata1) -> + Metadata2 = maybe_update_with(<<"requirements">>, fun normalize_requirements/1, Metadata1), + Metadata3 = maybe_update_with(<<"links">>, fun try_into_map/1, Metadata2), + Metadata4 = maybe_update_with(<<"extra">>, fun try_into_nested_map/1, Metadata3), + guess_build_tools(Metadata4). + +%% @private +normalize_requirements(Requirements) -> + case is_list(Requirements) andalso (Requirements /= []) andalso is_list(hd(Requirements)) of + true -> + maps:from_list(lists:map(fun normalize_legacy_requirement/1, Requirements)); + false -> + try_into_map(fun normalize_normal_requirement/1, Requirements) + end. + +%% @private +normalize_normal_requirement({Name, Requirement}) -> + {Name, try_into_map(Requirement)}. + +%% @private +normalize_legacy_requirement(Requirement) -> + Map = maps:from_list(Requirement), + Name = maps:get(<<"name">>, Map), + {Name, maps:without([<<"name">>], Map)}. + +%% @private +guess_build_tools(#{<<"build_tools">> := BuildTools} = Metadata) when is_list(BuildTools) -> + Metadata; +guess_build_tools(#{<<"files">> := Filenames} = Metadata) -> + BaseFiles = [ + Filename + || Filename <- Filenames, filename:dirname(binary_to_list(Filename)) == "." + ], + BuildTools = lists:usort([ + Tool + || {Filename, Tool} <- ?BUILD_TOOL_FILES, lists:member(Filename, BaseFiles) + ]), + Metadata#{<<"build_tools">> => BuildTools}; +guess_build_tools(Metadata) -> + Metadata. + +%%==================================================================== +%% Tar Helpers +%%==================================================================== + +%% @private +unpack_tarball(ContentsBinary, memory) -> + hex_erl_tar:extract({binary, ContentsBinary}, [memory, compressed]); +unpack_tarball(ContentsBinary, Output) -> + filelib:ensure_dir(filename:join(Output, "*")), + case hex_erl_tar:extract({binary, ContentsBinary}, [{cwd, Output}, compressed]) of + ok -> + [ + try_updating_mtime(filename:join(Output, Path)) + || Path <- filelib:wildcard("**", Output) + ], + ok; + Other -> + Other + end. + +%% @private +%% let it silently fail for bad symlinks +try_updating_mtime(Path) -> + Time = calendar:universal_time(), + _ = file:write_file_info(Path, #file_info{mtime = Time}, [{time, universal}]), + ok. + +%% @private +create_memory_tarball(Files) -> + Path = tmp_path(), + {ok, Tar} = hex_erl_tar:open(Path, [write]), + + try + add_files(Tar, Files) + after + ok = hex_erl_tar:close(Tar) + end, + {ok, Tarball} = file:read_file(Path), + ok = file:delete(Path), + Tarball. + +%% @private +tmp_path() -> + "tmp_" ++ binary_to_list(encode_base16(crypto:strong_rand_bytes(32))). + +%% @private +add_files(Tar, Files) when is_list(Files) -> + lists:map(fun(File) -> add_file(Tar, File) end, Files). + +%% @private +add_file(Tar, {Filename, Contents}) when is_list(Filename) and is_binary(Contents) -> + ok = hex_erl_tar:add(Tar, Contents, Filename, tar_opts()); +add_file(Tar, Filename) when is_list(Filename) -> + add_file(Tar, {Filename, Filename}); +add_file(Tar, {Filename, AbsFilename}) when is_list(Filename), is_list(AbsFilename) -> + {ok, FileInfo} = file:read_link_info(AbsFilename, []), + + case FileInfo#file_info.type of + symlink -> + ok = hex_erl_tar:add(Tar, {Filename, AbsFilename}, tar_opts()); + directory -> + case file:list_dir(AbsFilename) of + {ok, []} -> + hex_erl_tar:add(Tar, {Filename, AbsFilename}, tar_opts()); + {ok, _} -> + ok + end; + _ -> + Mode = FileInfo#file_info.mode, + {ok, Contents} = file:read_file(AbsFilename), + ok = hex_erl_tar:add(Tar, Contents, Filename, Mode, tar_opts()) + end. + +%% @private +tar_opts() -> + NixEpoch = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}), + Y2kEpoch = calendar:datetime_to_gregorian_seconds({{2000, 1, 1}, {0, 0, 0}}), + Epoch = Y2kEpoch - NixEpoch, + [{atime, Epoch}, {mtime, Epoch}, {ctime, Epoch}, {uid, 0}, {gid, 0}]. + +%% @private +%% Reproducible gzip by not setting mtime and OS +%% +%% From https://tools.ietf.org/html/rfc1952 +%% +%% +---+---+---+---+---+---+---+---+---+---+ +%% |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) +%% +---+---+---+---+---+---+---+---+---+---+ +%% +%% +=======================+ +%% |...compressed blocks...| (more-->) +%% +=======================+ +%% +%% +---+---+---+---+---+---+---+---+ +%% | CRC32 | ISIZE | +%% +---+---+---+---+---+---+---+---+ +gzip(Uncompressed) -> + Compressed = gzip_no_header(Uncompressed), + Header = <<31, 139, 8, 0, 0, 0, 0, 0, 0, 0>>, + Crc = erlang:crc32(Uncompressed), + Size = byte_size(Uncompressed), + Trailer = <>, + iolist_to_binary([Header, Compressed, Trailer]). + +%% @private +gzip_no_header(Uncompressed) -> + Zstream = zlib:open(), + + try + zlib:deflateInit(Zstream, default, deflated, -15, 8, default), + Compressed = zlib:deflate(Zstream, Uncompressed, finish), + zlib:deflateEnd(Zstream), + iolist_to_binary(Compressed) + after + zlib:close(Zstream) + end. + +%%==================================================================== +%% Helpers +%%==================================================================== + +%% @private +valid_size(Binary, infinity) when is_binary(Binary) -> + true; +valid_size(Binary, Limit) when is_binary(Binary) and is_integer(Limit) -> + byte_size(Binary) =< Limit. + +%% @private +binarify(Binary) when is_binary(Binary) -> Binary; +binarify(Number) when is_number(Number) -> Number; +binarify(Atom) when Atom == undefined orelse is_boolean(Atom) -> Atom; +binarify(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8); +binarify(List) when is_list(List) -> + [binarify(E) || E <- List]; +binarify({Key, Value}) -> + {binarify(Key), binarify(Value)}; +binarify(Map) when is_map(Map) -> + List = maps:to_list(Map), + lists:map(fun({K, V}) -> binarify({K, V}) end, List). + +%% @private +diff_keys(Map, RequiredKeys, OptionalKeys) -> + Keys = maps:keys(Map), + MissingKeys = RequiredKeys -- Keys, + UnknownKeys = Keys -- (RequiredKeys ++ OptionalKeys), + + case {MissingKeys, UnknownKeys} of + {[], []} -> + ok; + % Server should validate this but clients should not + % {_, [_ | _]} -> + % {error, {unknown_keys, UnknownKeys}}; + + _ -> + {error, {missing_keys, MissingKeys}} + end. + +%% @private +maybe_update_with(Key, Fun, Map) -> + case maps:find(Key, Map) of + {ok, Value} -> maps:put(Key, Fun(Value), Map); + error -> Map + end. + +%% @private +try_into_map(List) -> + try_into_map(fun(X) -> X end, List). + +%% @private +try_into_map(Fun, Input) -> + case has_map_shape(Input) of + true -> maps:from_list(lists:map(Fun, Input)); + false -> Input + end. + +%% @private +try_into_nested_map(List) -> + try_into_nested_map(fun(X) -> X end, List). + +%% @private +try_into_nested_map(Fun, Input) -> + case has_map_shape(Input) of + true -> + maps:from_list( + lists:map( + fun({Key, Value}) -> + Fun({Key, try_into_nested_map(Fun, Value)}) + end, + Input + ) + ); + false -> + Input + end. + +%% @private +has_map_shape(Input) -> + is_list(Input) andalso + lists:all(fun(E) -> is_tuple(E) andalso (tuple_size(E) == 2) end, Input). + +%% @private +encode_base16(Binary) -> + <> = Binary, + String = string:to_upper(lists:flatten(io_lib:format("~64.16.0b", [X]))), + list_to_binary(String). + +%% Based on https://github.com/goj/base16/blob/master/src/base16.erl +%% (C) 2012, Erlang Solutions Ltd. + +%% @private +decode_base16(Base16) -> + <<<<(unhex(H) bsl 4 + unhex(L))>> || <> <= Base16>>. + +%% @private +unhex(D) when $0 =< D andalso D =< $9 -> + D - $0; +unhex(D) when $a =< D andalso D =< $f -> + 10 + D - $a; +unhex(D) when $A =< D andalso D =< $F -> + 10 + D - $A. diff --git a/deps/eini/_build/default/plugins/hex_core/src/safe_erl_term.xrl b/deps/eini/_build/default/plugins/hex_core/src/safe_erl_term.xrl new file mode 100644 index 0000000000000000000000000000000000000000..8e58653d6e9a3b6788e317abf0c5deeee25dbaf8 --- /dev/null +++ b/deps/eini/_build/default/plugins/hex_core/src/safe_erl_term.xrl @@ -0,0 +1,77 @@ +%%% Author : Robert Virding +%%% Purpose : Token definitions for Erlang. + +Definitions. + +D = [0-9] +U = [A-Z] +L = [a-z] +A = ({U}|{L}|{D}|_|@) +WS = ([\000-\s]) + +Rules. + +{L}{A}* : tokenize_atom(TokenChars, TokenLine). +'(\\\^.|\\.|[^'])*' : tokenize_atom(escape(unquote(TokenChars, TokenLen)), TokenLine). +"(\\\^.|\\.|[^"])*" : {token, {string, TokenLine, escape(unquote(TokenChars, TokenLen))}}. +{D}+ : {token, {integer, TokenLine, list_to_integer(TokenChars)}}. +[\#\[\]}{,+-] : {token, {list_to_atom(TokenChars), TokenLine}}. +(<<|>>|=>) : {token, {list_to_atom(TokenChars), TokenLine}}. +\. : {token, {dot, TokenLine}}. +/ : {token, {'/', TokenLine}}. +{WS}+ : skip_token. + +Erlang code. + +-export([terms/1]). + +terms(Tokens) -> + terms(Tokens, []). + +terms([{dot, _} = H], Buffer) -> + [buffer_to_term([H|Buffer])]; +terms([{dot, _} = H|T], Buffer) -> + [buffer_to_term([H|Buffer])|terms(T, [])]; +terms([H|T], Buffer) -> + terms(T, [H|Buffer]). + +buffer_to_term(Buffer) -> + {ok, Term} = erl_parse:parse_term(lists:reverse(Buffer)), + Term. + +unquote(TokenChars, TokenLen) -> + lists:sublist(TokenChars, 2, TokenLen - 2). + +tokenize_atom(TokenChars, TokenLine) -> + try list_to_existing_atom(TokenChars) of + Atom -> {token, {atom, TokenLine, Atom}} + catch + error:badarg -> {error, "illegal atom " ++ TokenChars} + end. + +escape([$\\|Cs]) -> + do_escape(Cs); +escape([C|Cs]) -> + [C|escape(Cs)]; +escape([]) -> []. + +do_escape([O1,O2,O3|S]) when + O1 >= $0, O1 =< $7, O2 >= $0, O2 =< $7, O3 >= $0, O3 =< $7 -> + [(O1*8 + O2)*8 + O3 - 73*$0|escape(S)]; +do_escape([$^,C|Cs]) -> + [C band 31|escape(Cs)]; +do_escape([C|Cs]) when C >= $\000, C =< $\s -> + escape(Cs); +do_escape([C|Cs]) -> + [escape_char(C)|escape(Cs)]. + +escape_char($n) -> $\n; %\n = LF +escape_char($r) -> $\r; %\r = CR +escape_char($t) -> $\t; %\t = TAB +escape_char($v) -> $\v; %\v = VT +escape_char($b) -> $\b; %\b = BS +escape_char($f) -> $\f; %\f = FF +escape_char($e) -> $\e; %\e = ESC +escape_char($s) -> $\s; %\s = SPC +escape_char($d) -> $\d; %\d = DEL +escape_char(C) -> C. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/LICENSE b/deps/eini/_build/default/plugins/rebar3_hex/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..38975830390bb5b8aa5e9f789cf24cb187d2724f --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/LICENSE @@ -0,0 +1,193 @@ + +All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright (c) 2015, Tristan Sloughter . + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/README.md b/deps/eini/_build/default/plugins/rebar3_hex/README.md new file mode 100644 index 0000000000000000000000000000000000000000..100571f922b5ede84c734603d841adedeb82d6e4 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/README.md @@ -0,0 +1,196 @@ +# rebar3_hex + +[![Build Status](https://github.com/erlef/rebar3_hex/actions/workflows/ci.yml/badge.svg)](https://github.com/erlef/rebar3_hex/actions/workflows/ci.yml) +[![Hex pm](https://img.shields.io/hexpm/v/rebar3_hex.svg)](https://hex.pm/packages/rebar3_hex) +[![Docs](https://img.shields.io/badge/hex-docs-green.svg?style=flat)](https://hexdocs.pm/rebar3_hex) +[![Erlang Versions](https://img.shields.io/badge/Supported%20Erlang%2FOTP-26.0%20to%2028.0-blue)](http://www.erlang.org) + +rebar3_hex is a plugin for [Rebar3](https://www.rebar3.org/) that bundles providers to interact with [Hex](https://hex.pm/). + +> 💡 **rebar3_hex is a tool for package authors** +> If your Erlang project is not meant to be published on Hex, Rebar3 itself should be enough for you. + +## Setup + +Add to your global rebar3 config in `~/.config/rebar3/rebar.config`: + +```erlang +{plugins, [rebar3_hex]}. +``` + +Alternatively, you can add to your project's rebar3 config in project plugins : + +```erlang +{project_plugins, [rebar3_hex]}. +``` + +**NOTE** : Be sure **not** to add `rebar3_hex` to the plugins section within a projects rebar3 config as this will +become a dependency for others downloading your package from hex.pm + +### Documentation + +rebar3_hex by default expects you to configure a documentation provider. We recommend using +[rebar3_ex_doc](https://hexdocs.pm/rebar3_ex_doc/) for publishing documentation along with your package for a +consistent format and style on [hex.pm](https://hex.pm/). + +Example : + +```erlang + +{ex_doc, [ + {extras, ["README.md", "LICENSE"]}, + {main, "README.md"}, + {source_url, "https://github.com/namespace/your_app"} +]}. + +{hex, [{doc, ex_doc}]}. +``` + +Alternatively, or on Erlang versions older than OTP-24, you can use the edoc provider that ships with rebar3 : + +```erlang +{hex, [{doc, edoc}]}. +``` + +## Basic usage + +You should read the [docs](https://hexdocs.pm/rebar3_hex/) for a complete over for each provider, but below is a +brief overview of basic usage. + +### Authenticating User + +If you already have a user for [hex.pm](https://hex.pm) run: + + +```shell +$ rebar3 hex user auth +``` + +Note that this will ask for your hex.pm username and password, as well as a password for encrypting your api token that +has write permissions to the repository. When publishing a package you will have to give this password to decrypt the +token in order to publish. + +See the [docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_user.html) for more information. + +### Building + +The `build` provider is very useful for seeing exactly what would be published using either the `publish` or `cut` task +without any chance of actually publishing the package or docs. Tarballs for the package and docs are written to +`_build//lib/your_app/hex/` by default. + + +``` +$ rebar3 hex build +``` + +See the [docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_build.html) for more information. + +### Publishing + +Two providers are available for publishing packages, `publish` and `cut` + +By default `publish` builds and pushes your package and docs to a repository. See the +[docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_publish.html) for more information. + +``` shell +$ rebar3 hex publish +``` + +`cut` is available to provide some additional functionality around versioning and git tags. See the +[docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_cut.html) for more information. + +``` shell +$ rebar3 hex cut +``` + +In either case, both providers will display the details of what is being published +(what files, the version, dependencies) and ask if it should continue, so be sure to read the +output carefully and make sure it is publishing what you expected. + +### Managing package owners + +Owners can be added, removed, and listed for packages you are an owner of with the `hex owner` command. Packages +can also be transfered to other registered users on hexpm as well. + +``` shell +$ rebar3 hex owner [add | remove | list | transfer] +``` + +See the [docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_owner.html) for more information. + +### Retiring packages + +Packages can be flagged as retired on hexpm via the `retire` provider : + +``` +$ rebar3 hex retire PACKAGE VERSION REASON --message +``` + +They can also be unretired in case a mistake was made : + +``` +$ rebar3 hex retire PACKAGE VERSION --unretire +``` + +See the [docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_retire.html) for more information. + +### Organizations + +rebar3_hex supports working with organizations via the `organization` provider. + +Simply add your organization to either your global rebar.config (i.e., `~/.config/rebar3/rebar.config` ) or a local +project rebar.config. + +```erlang +{hex, [{repos, [#{name => <<"hexpm:your_org">>}]}]}. +``` + +You can then authenticate with with the organization repository. Be sure you have already authenticated with the main +repository first: + +``` +$ rebar3 hex auth # make sure you're authenticated to the main repo first +$ rebar3 hex organization auth hexpm:your_org # authenticate to the org +``` + +Now you can generate, revoke, and list keys for your organizations. See below for an example of generating a key for use +in CI. + +See the [docs](https://hexdocs.pm/rebar3_hex/rebar3_hex_organization.html) for more information. + +#### Read-Only Repo Key for CI + +If you have a private organization or other private repository it is recommended that you use a repo specific +auth token for reading from the repository in CI. To generate a token: + +```shell +$ rebar3 hex organization auth hexpm:myrepo +Successfully authenticated to hexpm:myrepo +``` + +Now you can generate a key to use in CI for your organization + +``` +$ rebar3 hex organization key hexpm:myrepo generate +abc123 +``` + +Then in CI use whatever method is available for setting an environment variable to the token and add this call at the +beginning of your CI runs to add the token to your rebar3 hex config. Below we'll use the environment `REPO_KEY` as an +example. + +```shell +$ rebar3 hex organization auth hexpm:myrepo --key $REPO_KEY +``` + +### Searching hexpm + +A `search` provider is available to search packages across hex.pm as a convenience. + +``` +$ rebar3 hex search +``` + +# Further reading +See [Publishing packages](https://hex.pm/docs/rebar3-publish) on hexpm for more setup and usage instructions. See the +[docs](https://hexdocs.pm/rebar3_hex) for detailed documentation for all available providers. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.app b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.app new file mode 100644 index 0000000000000000000000000000000000000000..3895cd47b26f5b6d941d413ac0257caed1a3130b --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.app @@ -0,0 +1,16 @@ +{application,rebar3_hex, + [{registered,[]}, + {description,"Hex.pm plugin for rebar3"}, + {vsn,"7.1.0"}, + {applications,[kernel,stdlib,hex_core]}, + {maintainers,["Tristan Sloughter","Bryan Paxton"]}, + {licenses,["Apache-2.0"]}, + {links,[{"GitHub","https://github.com/erlef/rebar3_hex"}]}, + {modules,[rebar3_hex,rebar3_hex_app,rebar3_hex_build, + rebar3_hex_client,rebar3_hex_config,rebar3_hex_cut, + rebar3_hex_error,rebar3_hex_file, + rebar3_hex_httpc_adapter,rebar3_hex_io,rebar3_hex_key, + rebar3_hex_organization,rebar3_hex_owner, + rebar3_hex_publish,rebar3_hex_results, + rebar3_hex_retire,rebar3_hex_search,rebar3_hex_user, + rebar3_hex_version]}]}. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.beam new file mode 100644 index 0000000000000000000000000000000000000000..466a7ebaaa743373b6c04a9111a7709682bb13b0 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_app.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_app.beam new file mode 100644 index 0000000000000000000000000000000000000000..adba9a7213632be2d5c23a2f759ec2144067c989 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_app.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_build.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_build.beam new file mode 100644 index 0000000000000000000000000000000000000000..9b4b243db9090c654412912f21140ab0c7055b06 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_build.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_client.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_client.beam new file mode 100644 index 0000000000000000000000000000000000000000..fbbe4c4bfe78389c6564b0c4e6844f867dbb34c4 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_client.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_config.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_config.beam new file mode 100644 index 0000000000000000000000000000000000000000..3c75cb43425c30db88480c0295a006c1947f3563 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_config.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_cut.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_cut.beam new file mode 100644 index 0000000000000000000000000000000000000000..27007ff04e52b30b5c93dd0f40c81fe2c20b0372 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_cut.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_error.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_error.beam new file mode 100644 index 0000000000000000000000000000000000000000..38a3f4728843278003d2ff1a20b0e4bb474f187b Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_error.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_file.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_file.beam new file mode 100644 index 0000000000000000000000000000000000000000..42a244c5dbb521c2f18deacc8a0df5cb1f31e539 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_file.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_httpc_adapter.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_httpc_adapter.beam new file mode 100644 index 0000000000000000000000000000000000000000..d16999d526932a94540f56fc9c0e7e7ec97782e3 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_httpc_adapter.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_io.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_io.beam new file mode 100644 index 0000000000000000000000000000000000000000..eff29cc7bcfb299c6fe15f9516e56c22f98b48af Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_io.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_key.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_key.beam new file mode 100644 index 0000000000000000000000000000000000000000..78eb0248f92838406fdc283b4aeb34d057b0a8c4 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_key.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_organization.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_organization.beam new file mode 100644 index 0000000000000000000000000000000000000000..c5933a9e2ac46841a48a99be054df69a9ea8adc2 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_organization.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_owner.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_owner.beam new file mode 100644 index 0000000000000000000000000000000000000000..66ec6be72225291ab82f384fe03949e7e467db21 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_owner.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_publish.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_publish.beam new file mode 100644 index 0000000000000000000000000000000000000000..76ba5489a68caf0228fd33e90b2f465ba3886627 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_publish.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_results.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_results.beam new file mode 100644 index 0000000000000000000000000000000000000000..ffc2b37665fab9dc6c7900fba50290bbddcc2c32 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_results.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_retire.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_retire.beam new file mode 100644 index 0000000000000000000000000000000000000000..3666f75791684d39b71693f46dc76574f37e1bae Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_retire.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_search.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_search.beam new file mode 100644 index 0000000000000000000000000000000000000000..67b75e7a59946f49061c8d523cb1be001494e53f Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_search.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_user.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_user.beam new file mode 100644 index 0000000000000000000000000000000000000000..4af5af81aa3194eee5b8b704ad297846c0852ed4 Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_user.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_version.beam b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_version.beam new file mode 100644 index 0000000000000000000000000000000000000000..9ffac1d1b5319023c507a3f4bb119ce118410f4f Binary files /dev/null and b/deps/eini/_build/default/plugins/rebar3_hex/ebin/rebar3_hex_version.beam differ diff --git a/deps/eini/_build/default/plugins/rebar3_hex/hex_metadata.config b/deps/eini/_build/default/plugins/rebar3_hex/hex_metadata.config new file mode 100644 index 0000000000000000000000000000000000000000..1406f9261b36b6b6f4f2d90c3a15190d3b30fa1d --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/hex_metadata.config @@ -0,0 +1,29 @@ +{<<"app">>,<<"rebar3_hex">>}. +{<<"build_tools">>,[<<"rebar3">>]}. +{<<"description">>,<<"Hex.pm plugin for rebar3">>}. +{<<"files">>, + [<<"LICENSE">>,<<"README.md">>,<<"rebar.config">>,<<"rebar.lock">>,<<"src">>, + <<"src/rebar3_hex.app.src">>,<<"src/rebar3_hex.erl">>, + <<"src/rebar3_hex.hrl">>,<<"src/rebar3_hex_app.erl">>, + <<"src/rebar3_hex_build.erl">>,<<"src/rebar3_hex_client.erl">>, + <<"src/rebar3_hex_config.erl">>,<<"src/rebar3_hex_cut.erl">>, + <<"src/rebar3_hex_error.erl">>,<<"src/rebar3_hex_file.erl">>, + <<"src/rebar3_hex_httpc_adapter.erl">>,<<"src/rebar3_hex_io.erl">>, + <<"src/rebar3_hex_key.erl">>,<<"src/rebar3_hex_organization.erl">>, + <<"src/rebar3_hex_owner.erl">>,<<"src/rebar3_hex_publish.erl">>, + <<"src/rebar3_hex_results.erl">>,<<"src/rebar3_hex_retire.erl">>, + <<"src/rebar3_hex_search.erl">>,<<"src/rebar3_hex_user.erl">>, + <<"src/rebar3_hex_version.erl">>]}. +{<<"licenses">>,[<<"Apache-2.0">>]}. +{<<"links">>,[{<<"GitHub">>,<<"https://github.com/erlef/rebar3_hex">>}]}. +{<<"name">>,<<"rebar3_hex">>}. +{<<"requirements">>, + [{<<"hex_core">>, + [{<<"app">>,<<"hex_core">>}, + {<<"optional">>,false}, + {<<"requirement">>,<<"0.12.2">>}]}, + {<<"verl">>, + [{<<"app">>,<<"verl">>}, + {<<"optional">>,false}, + {<<"requirement">>,<<"1.1.1">>}]}]}. +{<<"version">>,<<"7.1.0">>}. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/rebar.config b/deps/eini/_build/default/plugins/rebar3_hex/rebar.config new file mode 100644 index 0000000000000000000000000000000000000000..ac883af0fb1b297c7090e2493dc32f7538922fa1 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/rebar.config @@ -0,0 +1,52 @@ +{minimum_otp_vsn, "18"}. + +{erl_opts, [ + debug_info, + {platform_define, "^2[3-9]", 'POST_OTP_22'}, + {platform_define, "^20", 'POST_OTP_19'}, + {platform_define, "^19", 'POST_OTP_18'}, + {platform_define, "^[2-9]", 'POST_OTP_18'} +]}. + +%% Some dependencies don't yet build cleanly with OTP-29. +{overrides, [ + {add, katana_code, [{erl_opts, [nowarn_deprecated_catch]}]} +]}. + +{project_plugins, [{covertool, "2.0.6"}, {rebar3_ex_doc, "0.2.30"}, {rebar3_hank, "1.4.0"}]}. + +{deps, [{hex_core, "0.12.2"}, {verl, "1.1.1"}]}. + +{profiles, [ + {test, [ + {extra_src_dirs, ["test/support"]}, + {deps, [{erlware_commons, "1.7.0"}, {elli, "3.3.0"}, + {jsone, "1.8.1"}, {meck, "0.9.2"}]}, + {erl_opts, [nowarn_export_all]} + ]} +]}. + +{dialyzer, [ + {warnings, [ + error_handling, + no_unknown + ]}, + {plt_extra_apps, [hex_core, verl]} +]}. + +{hank, + [{ignore, + [{"test/**/*.erl", unnecessary_function_arguments}]}]}. + +{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used, + deprecated_function_calls,deprecated_functions]}. + +{alias, [{test, [{ct, "--cover"}, {cover, "-v"}]}]}. + +{hex, [{doc, ex_doc}]}. + +{ex_doc, [ + {source_url, <<"https://github.com/erlef/rebar3_hex">>}, + {extras, [<<"README.md">>, <<"LICENSE">>]}, + {main, <<"readme">>} +]}. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/rebar.lock b/deps/eini/_build/default/plugins/rebar3_hex/rebar.lock new file mode 100644 index 0000000000000000000000000000000000000000..dd00cddcf3e03d21a32d4a1bd3320fda4500a103 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/rebar.lock @@ -0,0 +1,11 @@ +{"1.2.0", +[{<<"hex_core">>,{pkg,<<"hex_core">>,<<"0.12.2">>},0}, + {<<"verl">>,{pkg,<<"verl">>,<<"1.1.1">>},0}]}. +[ +{pkg_hash,[ + {<<"hex_core">>, <<"116F75685E707624BA79B6F6B06BE4F5E14C5FCCECCF31D4EA3ED4FED6134F8C">>}, + {<<"verl">>, <<"98F3EC48B943AA4AE8E29742DE86A7CD752513687911FE07D2E00ECDF3107E45">>}]}, +{pkg_hash_ext,[ + {<<"hex_core">>, <<"00E402C302BF4B8CEDC2D3425E22B55F8C70A2542D69C87A2E5BA7AF2745F6C6">>}, + {<<"verl">>, <<"0925E51CD92A0A8BE271765B02430B2E2CFF8AC30EF24D123BD0D58511E8FB18">>}]} +]. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.app.src b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.app.src new file mode 100644 index 0000000000000000000000000000000000000000..ff78f188c9fa133f32c46965750d23d72f7469d2 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.app.src @@ -0,0 +1,7 @@ +{application,rebar3_hex, + [{description,"Hex.pm plugin for rebar3"}, + {vsn,"7.1.0"}, + {applications,[kernel,stdlib,hex_core]}, + {maintainers,["Tristan Sloughter","Bryan Paxton"]}, + {licenses,["Apache-2.0"]}, + {links,[{"GitHub","https://github.com/erlef/rebar3_hex"}]}]}. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.erl new file mode 100644 index 0000000000000000000000000000000000000000..3f7712b2b7b55394bbe4727c1f104a602481d53e --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.erl @@ -0,0 +1,144 @@ +%% @private +-module(rebar3_hex). + +-export([ init/1 + , get_args/1 + , gather_opts/2 + , get_required/2 + , task_args/1 + , task_state/1 + , task_state/2 + , repo_opt/0 + , help_opt/0 + ]). + +-export([to_atom/1, to_list/1, to_binary/1]). + +-type task() :: #{raw_opts := proplists:proplist(), + raw_args := list(), + args := map(), + repo := map(), + apps := [rebar_app_info:t()], + state := rebar_state:t(), + multi_app := boolean() + }. + +-export_type([task/0]). + +init(State) -> + lists:foldl(fun provider_init/2, {ok, State}, [rebar3_hex_user, + rebar3_hex_build, + rebar3_hex_cut, + rebar3_hex_owner, + rebar3_hex_organization, + rebar3_hex_search, + rebar3_hex_retire, + rebar3_hex_publish]). + +provider_init(Module, {ok, State}) -> + Module:init(State). + +gather_opts(Targets, State) -> + {Args, _} = rebar_state:command_parsed_args(State), + lists:foldl(fun(T, Acc) -> + case proplists:get_value(T, Args, undefined) of + undefined -> + Acc; + V -> + maps:put(T, V, Acc) + end + end, #{}, Targets). + +get_required(Key, Args) -> + case proplists:get_value(Key, Args) of + undefined -> + {error, {required, Key}}; + Value -> + Value + end. + +task_args(State) -> + {Opts, _Args} = rebar_state:command_parsed_args(State), + case proplists:get_value(task, Opts, undefined) of + undefined -> + {undefined, Opts}; + Task -> + {Task, proplists:delete(task, Opts)} + end. + + +%% TODO: A current limitation of rebar3_hex:task_state/1 is it returns strings. +%% This will need to be adjusted to return binaries. For now, we return the opts and args +%% as returned from rebar_state:command_parsed_args/1 as raw_args and raw_opts. +-spec task_state(rebar_state:t()) -> {ok, task()} | {error, term()}. +task_state(State) -> + case rebar3_hex_config:repo(State) of + {ok, Repo} -> + {ok, task_state(State, Repo)}; + Err -> + Err + end. + +-spec task_state(rebar_state:t(), map()) -> task(). +task_state(State, Repo) -> + {Opts0, Args0} = rebar_state:command_parsed_args(State), + Opts = get_args(State), + CurrentTask = maps:get(task, Opts, undefined), + Opts1 = Opts#{task => CurrentTask}, + case rebar_state:project_apps(State) of + [] -> + #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => []}; + [_App] = Apps -> + #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => false, apps => Apps}; + [_|_] = Apps -> + #{raw_opts => Opts0, raw_args => Args0, args => Opts1, repo => Repo, state => State, multi_app => true, apps => Apps} + end. + +-spec get_args(rebar_state:t()) -> map(). +get_args(State) -> + {Opts, Args} = rebar_state:command_parsed_args(State), + Opts1 = lists:foldl(fun (Arg, Acc) -> + case is_atom(Arg) of + true -> + [{Arg, true} | Acc]; + _ -> + case Arg of + {task, Task} -> + [{task, list_to_atom(Task)} | Acc]; + _ -> + [Arg | Acc] + end + end + end, + [], + Opts), + + Opts2 = lists:foldl(fun (Arg, Acc) -> + case is_atom(Arg) of + true -> + [{Arg, true} | Acc]; + _ -> + [{list_to_atom(Arg), true} | Acc] + end + end, + Opts1, + Args), + maps:from_list(Opts2). + +help_opt() -> + {help, $h, "help", undefined, "Help"}. + +repo_opt() -> + {repo, $r, "repo", string, "Repository to use for this command."}. + +to_binary(A) when is_atom(A) -> atom_to_binary(A, unicode); +to_binary(Str) -> unicode:characters_to_binary(Str). + +to_list(A) when is_atom(A) -> atom_to_list(A); +to_list(B) when is_binary(B) -> unicode:characters_to_list(B); +to_list(I) when is_integer(I) -> integer_to_list(I); +to_list(Str) -> unicode:characters_to_list(Str). + +to_atom(B) when is_binary(B) -> binary_to_atom(B, utf8); +to_atom(Str) when is_list(Str) -> list_to_atom(Str); +to_atom(A) when is_atom(A) -> A. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.hrl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.hrl new file mode 100644 index 0000000000000000000000000000000000000000..591fe394f3bc7f07bda458ceb5cce404c20bf11c --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex.hrl @@ -0,0 +1,4 @@ +-define(PRV_ERROR(Reason), + {error, {?MODULE, Reason}}). +-define(RAISE(Reason), erlang:error(?PRV_ERROR(Reason))). +-define(DEFAULT_HEX_REPO, <<"hexpm">>). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_app.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_app.erl new file mode 100644 index 0000000000000000000000000000000000000000..f7eedf351d417f5443ec5f2fa542a09d76b73e0d --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_app.erl @@ -0,0 +1,224 @@ +%% @private +%%% =================================================================== +%%% App utils +%%% =================================================================== +-module(rebar3_hex_app). + +-export([vcs_vsn/2, find/2, get_deps/1, validate/1]). + +-define(VALIDATIONS, [ + has_semver, + has_contributors, + has_maintainers, + has_description, + has_valid_licenses, + has_unstable_deps +]). + +-type app_data() :: #{ + name := string(), + version := string(), + details := list(), + deps := list() +}. + +-type validation_errors() :: #{ + warnings => list(), + errors => list() +}. + +-spec find([rebar_app_info:t()], string()) -> {ok, rebar_app_info:t()} | {error, app_not_found}. +find(Apps, Name) -> + Pred = fun(App) -> + rebar_app_info:name(App) =:= rebar_utils:to_binary(Name) + end, + case lists:filter(Pred, Apps) of + [App] -> + {ok, App}; + _ -> + {error, app_not_found} + end. + +-spec get_deps(list()) -> {ok, list()} | {error, {non_hex_deps, list()}}. +get_deps(Deps) -> + Top = locks_to_deps(Deps), + Excluded = [rebar_utils:to_list(N) || {N, {T, _, _, _}, 0} <- Deps, T =/= pkg], + Excluded1 = [rebar_utils:to_list(N) || {N, {T, _, _}, 0} <- Deps, T =/= pkg], + + case Excluded ++ Excluded1 of + [] -> + {ok, Top}; + Forbidden -> + {error, {non_hex_deps, Forbidden}} + end. + +locks_to_deps(Deps) -> + lists:foldl(fun(D, Acc) -> lock_to_dep(D, Acc) end, [], Deps). + +lock_to_dep({A, {pkg, N, V, _, _}, 0}, Acc) -> + [{N, [{<<"app">>, A}, {<<"optional">>, false}, {<<"requirement">>, V}]} | Acc]; +lock_to_dep({A, {pkg, N, V, _}, 0}, Acc) -> + [{N, [{<<"app">>, A}, {<<"optional">>, false}, {<<"requirement">>, V}]} | Acc]; +lock_to_dep(_, Acc) -> + Acc. + +-spec validate(app_data()) -> ok | {error, validation_errors()}. +validate(AppData) -> + F = fun(K, Acc) -> + case validate_app(K, AppData) of + ok -> + Acc; + {warn, Warn} -> + #{warnings := WarnList} = Acc, + maps:put(warnings, [Warn | WarnList], Acc); + {error, Error} -> + #{errors := ErrList} = Acc, + maps:put(errors, [Error | ErrList], Acc) + end + end, + case lists:foldl(F, #{warnings => [], errors => []}, ?VALIDATIONS) of + [] -> + ok; + Errors -> + {error, Errors} + end. + +validate_app(has_unstable_deps, #{deps := Deps}) -> + case lists:foldl(fun(Dep, Acc) -> is_unstable_dep(Dep, Acc) end, [], Deps) of + [] -> + ok; + PreDeps -> + {warn, {has_unstable_deps, PreDeps}} + end; +validate_app(has_semver, #{name := Name, version := Ver}) -> + case rebar3_hex_version:parse(Ver) of + {error, invalid_version} -> + {error, {invalid_semver, {Name, Ver}}}; + _ -> + ok + end; +validate_app(has_contributors, #{name := Name, details := AppDetails}) -> + case proplists:is_defined(contributors, AppDetails) of + true -> + {warn, {has_contributors, Name}}; + false -> + ok + end; +validate_app(has_maintainers, #{name := Name, details := AppDetails}) -> + case proplists:is_defined(maintainers, AppDetails) of + true -> + {warn, {has_maintainers, Name}}; + false -> + ok + end; +validate_app(has_description, #{name := Name, details := AppDetails}) -> + case is_empty_prop(description, AppDetails) of + true -> + {warn, {no_description, Name}}; + false -> + ok + end; +validate_app(has_valid_licenses, #{name := Name, details := AppDetails}) -> + case is_empty_prop(licenses, AppDetails) of + true -> + {warn, {no_license, Name}}; + _ -> + Licenses = proplists:get_value(licenses, AppDetails), + case lists:filter(fun(L) -> not hex_licenses:valid(rebar_utils:to_binary(L)) end, Licenses) of + [] -> + ok; + [_|_] = Invalids -> + {warn, {invalid_licenses, Invalids, Name}} + end + end. + +is_empty_prop(K, PropList) -> + Prop = proplists:get_value(K, PropList), + case Prop of + Empty when Empty =:= [] orelse Empty =:= undefined -> + true; + _ -> + false + end. + +is_unstable_dep({_, {pkg, Pkg, Ver, _, _}, _}, Acc) -> + case rebar3_hex_version:parse(Ver) of + {ok, #{pre := Pre}} when Pre =/= [] -> + [{Pkg, Ver} | Acc]; + _ -> + Acc + end; +is_unstable_dep(_, Acc) -> + Acc. + +-spec vcs_vsn(rebar_state:t(), rebar_app_info:t()) -> string(). +vcs_vsn(State, App) -> + Version = rebar_app_info:original_vsn(App), + AppDir = rebar_app_info:dir(App), + Resources = rebar_state:resources(State), + vcs_vsn(Version, AppDir, Resources). + +vcs_vsn(OriginalVsn, Dir, Resources) when is_list(Dir), is_list(Resources) -> + FakeState = rebar_state:new(), + case rebar_app_info:new(fake, OriginalVsn, Dir) of + {ok, AppInfo} -> + vcs_vsn( + AppInfo, + OriginalVsn, + rebar_state:set_resources(FakeState, Resources) + ); + Error -> + Error + end; +vcs_vsn(AppInfo, Vcs, State) -> + case vcs_vsn_cmd(AppInfo, Vcs, State) of + {plain, VsnString} -> + VsnString; + {cmd, CmdString} -> + cmd_vsn_invoke(CmdString, rebar_app_info:dir(AppInfo)); + unknown -> + rebar_utils:abort("vcs_vsn: Unknown vsn format: ~p", [Vcs]); + {error, Reason} -> + rebar_utils:abort("vcs_vsn: ~ts", [Reason]) + end. + +%% Temp work around for repos like relx that use "semver" +vcs_vsn_cmd(_, Vsn, _) when is_binary(Vsn) -> + {plain, Vsn}; +vcs_vsn_cmd(AppInfo, VCS, State) when VCS =:= semver; VCS =:= "semver" -> + vcs_vsn_cmd(AppInfo, git, State); +vcs_vsn_cmd(_AppInfo, {cmd, _Cmd} = Custom, _) -> + Custom; +vcs_vsn_cmd(AppInfo, {file, File}, _) -> + Path = filename:join(rebar_app_info:dir(AppInfo), File), + case file:read_file(Path) of + {ok, Vsn} -> + {plain, rebar_utils:to_list(rebar_string:trim(Vsn))}; + Error -> + Error + end; +vcs_vsn_cmd(AppInfo, VCS, State) when is_atom(VCS) -> + rebar_resource_v2:make_vsn(AppInfo, VCS, State); +vcs_vsn_cmd(AppInfo, {VCS, _} = V, State) when is_atom(VCS) -> + rebar_resource_v2:make_vsn(AppInfo, V, State); +vcs_vsn_cmd(AppInfo, VCS, State) when is_list(VCS) -> + try list_to_existing_atom(VCS) of + AVCS -> + case vcs_vsn_cmd(AppInfo, AVCS, State) of + unknown -> {plain, VCS}; + Other -> Other + end + catch + error:badarg -> + {plain, VCS} + end; +vcs_vsn_cmd(_, _, _) -> + unknown. + +cmd_vsn_invoke(Cmd, Dir) -> + case rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]) of + {ok, VsnString} -> + rebar_string:trim(VsnString, trailing, "\n"); + Error -> + Error + end. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_build.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_build.erl new file mode 100644 index 0000000000000000000000000000000000000000..f805845df18ba9b869ce158fd81e682b421666fa --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_build.erl @@ -0,0 +1,646 @@ +% @doc `rebar3 hex build' - Build packages and docs +% +%% Builds a new local version of your package. +%% +%% By default this provider will build both a package tarball and docs tarball. +%% +%% The package and docs .tar files are created in the current directory, but is not pushed to the repository. An app +%% named foo at version 1.2.3 will be built as foo-1.2.3.tar. Likewise the docs .tar would be built as +%% foo-1.2.4-docs.tar. +%% +%% ``` +%% $ rebar3 hex build +%% ''' +%% +%% You may also build only a package or docs tarball utilizing the same available command line options. +%% +%% ``` +%% $ rebar3 hex build package +%% ''' +%% +%% ``` +%% $ rebar3 hex build docs +%% ''' +%% +%%

Configuration

+%% Packages are configured via `src/.app.src' attributes. +%% +%% == Required configuration == +%% +%%
    +%%
  • +%% `application' - application name. This is required per Erlang/OTP thus it should always be present anyway. +%%
  • +%
  • +% `vsn' - must be a valid semantic version identifier. +%
  • +%%
  • +%% `licenses' - A list of licenses the project is licensed under. This attribute is required and must be a valid +%% spdx identifier. +%%
  • +%%
+%% +%% +%% == Optional configuration == +%% In addition, the following meta attributes are supported and highly recommended : +%% +%%
    +%%
  • +%% `description' - a brief description about your application. +%%
  • +%% +%%
  • +%% `pkg_name' - The name of the package in case you want to publish the package with a different name than the +%% application name. +%%
  • +%% +%%
  • +%% `links' - A map where the key is a link name and the value is the link URL. Optional but highly +%% recommended. +%%
  • +%% +%%
  • `files' - A list of files and directories to include in the package. Defaults to standard project directories, +%% so you usually don't need to set this property. +%%
  • +%%
  • +%% `include_paths' - A list of paths containing files you wish to include in a release. +%%
  • +%%
  • +%% `exclude_paths' - A list of paths containing files you wish to exclude in a release. +%%
  • +%%
  • +%% `exclude_patterns' - A list of regular expressions used to exclude files that may have been accumulated via +%% `files' and `include_paths' and standard project paths. +%%
  • +%%
  • +%% `build_tools' - List of build tools that can build the package. It's very rare that you need to set this. +%%
  • +%%
+%% +%% Below is an example : +%% +%% ``` +%% {application, myapp, +%% [{description, "An Erlang/OTP application"}, +%% {vsn, "0.1.0"}, +%% {modules, []}, +%% {registered, []}, +%% {applications, [kernel, +%% stdlib, +%% ]}, +%% {licenses, ["Apache-2.0"]}, +%% {links, [{"GitHub", "https://github.com/my_name/myapp"}]}]}. +%% ''' +%% +%%

Command line options

+%% +%%
    +%%
  • `-r', `--repo' - Specify the repository to work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must +%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Defaults to `hexpm'. +%%
  • +%%
  • `-u', `--unpack' - Builds the tarball and unpacks contents into a directory. Useful for making sure the tarball +%% contains all needed files before publishing. See --output below for setting the output path. +%%
  • +%%
  • `-o', `--output' - Sets output path. When used with --unpack it means the directory +%% (Default: `-'). Otherwise, it specifies tarball path (Default: `-.tar'). +%% Artifacts will be written to `_build//lib//' by default. +%%
  • +%%
+ +-module(rebar3_hex_build). + +-export([create_package/2, create_docs/3, create_docs/4]). + +-include("rebar3_hex.hrl"). + +-define(DEFAULT_FILES, [ + "src", + "c_src", + "include", + "rebar.config.script", + "priv", + "rebar.config", + "rebar.lock", + "CHANGELOG*", + "changelog*", + "README*", + "readme*", + "LICENSE*", + "license*", + "NOTICE" +]). + +-define(DEPS, [{default, compile}, {default, lock}]). +-define(PROVIDER, build). +-define(DEFAULT_DOC_DIR, "doc"). + +-export([ + init/1, + do/1, + format_error/1 +]). + +%% Helpers +-export([doc_opts/2]). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([ + {name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex build"}, + {short_desc, "Builds a new local version of your package and docs."}, + {desc, ""}, + {opts, [ + rebar3_hex:repo_opt(), + {app, $a, "app", {string, undefined}, "Specify the app to build."}, + {output_dir, $o, "output", {string, undefined}, "Specify the directory to output artifacts to."}, + {unpack, $u, "unpack", {boolean, false}, "Unpack the contents of tarballs generated vs writing them out to the filesystem."} + ]} + ]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + Task = rebar3_hex:task_state(State, get_repo(State)), + handle_task(Task). + +get_repo(State) -> + {Args, _} = rebar_state:command_parsed_args(State), + case proplists:get_value(repo, Args, undefined) of + undefined -> + rebar3_hex_config:default_repo(State); + RepoName -> + rebar3_hex_config:repo(State, RepoName) + end. + +%% @private +-spec format_error(any()) -> iolist(). +format_error({build_package, Error}) when is_list(Error) -> + io_lib:format("Error building package : ~ts", [Error]); + +format_error({build_package, {error, Error}}) when is_list(Error) -> + io_lib:format("Error building package : ~ts", [Error]); + +format_error({build_package,{error,{non_hex_deps,Deps}}}) -> + DepsStr = lists:join(",", Deps), + Error = "Some dependencies were excluded from the package; only Hex packages can be dependencies: ~s", + io_lib:format(Error, [DepsStr]); + +format_error({build_docs, {error, no_doc_config}}) -> + no_doc_config_messsage(); + +format_error({build_docs, {error, {doc_provider_not_found, PrvName}}}) -> + doc_provider_not_found(PrvName); + +format_error({build_docs, {error, missing_doc_index}}) -> + doc_missing_index_message(); + +format_error({build_docs, Error}) when is_list(Error) -> + io_lib:format("Error building docs : ~ts", [Error]); + +format_error({create_package, no_lock_file, default}) -> + "No lockfile detected."; + +format_error({create_package, no_lock_file, CurrentProfiles}) -> + case lists:any(fun(P) -> P =:= lock end, CurrentProfiles) of + true -> + "No lockfile detected."; + false -> + Err = "No lockfile detected and one can not be generated running under the current profile.~n~n" + ++ "Be sure to run rebar3 deps, rebar3 lock, or rebar3 hex build under the default ~n" + ++ "profile prior to building or publishing under an alternative profile.~n", + io_lib:format(Err, []) + end; + +format_error(repo_required_for_docs) -> + Str = "Error :~n\tA repo argument is required when building docs if multiple repos exist" + " and at least one has doc configuration.~n\tSpecify a repo argument or run" + " rebar3 hex build package if you only need to build a package.", + io_lib:format(Str, []); + +format_error({app_not_found, AppName}) -> + io_lib:format("App ~s specified with --app switch not found in project", [AppName]); + +format_error(app_switch_required) -> + "--app switch is required when building packages or docs in a umbrella with multiple apps"; + +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +no_doc_config_messsage() -> + "No doc provider has been specified in your hex config.\n" + "Be sure to add a doc provider to the hex config you rebar configuration file.\n\n" + "Example : {hex, [{doc, ex_doc}]\n". + +doc_missing_index_message() -> + "An index.html file was not found in docs after running docs provider.\n" + "Be sure the docs provider is configured correctly and double check it by running it on its own\n". + +doc_provider_not_found(Provider) -> + io_lib:format("The doc provider ~ts specified in your hex config could not be found", [Provider]). + +handle_task(#{apps := [_,_|_] = Apps, args := #{app := AppName}} = T) -> + case rebar3_hex_app:find(Apps, AppName) of + {ok, App} -> + handle_task(T#{apps := [App]}); + _Error -> + ?RAISE({app_not_found, AppName}) + end; + +handle_task(#{apps := [_,_|_]}) -> + ?RAISE(app_switch_required); + +handle_task(#{state := State, repo := Repo, apps := [App], args := #{task := docs} = Args}) -> + case create_docs(State, Repo, App) of + {ok, Docs} -> + AbsDir = write_or_unpack(App, Docs, Args), + rebar3_hex_io:say("Your docs can be inspected at ~ts", [AbsDir]), + {ok, State}; + Error -> + ?RAISE({build_docs, Error}) + end; + +handle_task(#{state := State, apps := [App], args := #{task := package} = Args}) -> + case create_package(State, App) of + {ok, Pkg} -> + AbsDir = write_or_unpack(App, Pkg, Args), + rebar3_hex_io:say("Your package contents can be inspected at ~ts", [AbsDir]), + {ok, State}; + Error -> + ?RAISE({build_package, Error}) + end; + +handle_task(#{state := State, repo := Repo, apps := [App], args := Args}) -> + case create_package(State, App) of + {ok, Pkg} -> + AbsOutput = write_or_unpack(App, Pkg, Args), + rebar3_hex_io:say("Your package tarball is available at ~ts", [AbsOutput]), + case create_docs(State, Repo, App) of + {ok, Docs} -> + AbsFile = write_or_unpack(App, Docs, Args), + rebar3_hex_io:say("Your docs tarball is available at ~ts", [AbsFile]), + {ok, State}; + {error, no_doc_config} -> + rebar_api:warn(no_doc_config_messsage(), []), + {ok, State}; + {error, {doc_provider_not_found, PrvName}} -> + rebar_api:warn(doc_provider_not_found(PrvName), []), + {ok, State}; + {error, missing_doc_index} -> + rebar_api:warn(doc_missing_index_message(), []), + {ok, State}; + Error -> + ?RAISE({build_docs, Error}) + end; + Error -> + ?RAISE({build_package, Error}) + end. + +output_path(docs, Name, Version, #{unpack := true}) -> + io_lib:format("~ts-~ts-docs", [Name, Version]); +output_path(docs, Name, Version, _Args) -> + io_lib:format("~ts-~ts-docs.tar", [Name, Version]); +output_path(package, Name, Version, #{unpack := true}) -> + io_lib:format("~ts-~ts", [Name, Version]); +output_path(package, Name, Version, _Args) -> + io_lib:format("~ts-~ts.tar", [Name, Version]). + +write_or_unpack(App, #{type := Type, tarball := Tarball, name := Name, version := Version}, Args) -> + OutputDir = output_dir(App, Args), + Out = output_path(Type, Name, Version, Args), + AbsOut = filename:join(OutputDir, Out), + case Args of + #{unpack := true} -> + file:make_dir(AbsOut), + case Type of + docs -> + hex_tarball:unpack_docs(Tarball, AbsOut); + package -> + hex_tarball:unpack(Tarball, AbsOut) + end; + _ -> + file:write_file(AbsOut, Tarball) + end, + AbsOut. + +%% We are exploiting a feature of ensuredir that that creates all +%% directories up to the last element in the filename, then ignores +%% that last element. This way we ensure that the dir is created +%% and not have any worries about path names +output_dir(App, #{output_dir := undefined}) -> + Dir = filename:join([rebar_app_info:out_dir(App), "hex"]), + filelib:ensure_dir(filename:join(Dir, "tmp")), + Dir; +output_dir(_App, #{output_dir := Output}) -> + Dir = filename:join(filename:absname(Output), "tmp"), + filelib:ensure_dir(Dir), + Dir; +output_dir(App, _) -> + Dir = filename:join([rebar_app_info:out_dir(App), "hex"]), + filelib:ensure_dir(filename:join(Dir, "tmp")), + Dir. + +lock_file_exists(State) -> + Dir = rebar_state:dir(State), + LockFile = filename:join(Dir, "rebar.lock"), + filelib:is_regular(LockFile). + +%% @private +create_package(State, App) -> + Name = rebar_app_info:name(App), + Version = rebar3_hex_app:vcs_vsn(State, App), + {application, _, AppDetails} = rebar3_hex_file:update_app_src(App, Version), + + lock_file_exists(State) orelse ?RAISE({create_package, no_lock_file, rebar_state:current_profiles(State)}), + + LockDeps = rebar_state:get(State, {locks, default}, []), + case rebar3_hex_app:get_deps(LockDeps) of + {ok, TopLevel} -> + AppDir = rebar_app_info:dir(App), + Config = rebar_config:consult(AppDir), + ConfigDeps = proplists:get_value(deps, Config, []), + Deps1 = update_versions(ConfigDeps, TopLevel), + Description = proplists:get_value(description, AppDetails, ""), + PackageFiles = include_files(Name, AppDir, AppDetails), + Licenses = proplists:get_value(licenses, AppDetails, []), + Links = proplists:get_value(links, AppDetails, []), + BuildTools = proplists:get_value(build_tools, AppDetails, [<<"rebar3">>]), + + %% We check the app file for the 'pkg' key which allows us to select + %% a package name other then the app name, if it is not set we default + %% back to the app name. + PkgName = binarify(proplists:get_value(pkg_name, AppDetails, Name)), + + Optional = [ + {<<"app">>, Name}, + {<<"parameters">>, []}, + {<<"description">>, binarify(Description)}, + {<<"files">>, [binarify(File) || {File, _} <- PackageFiles]}, + {<<"licenses">>, binarify(Licenses)}, + {<<"links">>, to_map(binarify(Links))}, + {<<"build_tools">>, binarify(BuildTools)} + ], + OptionalFiltered = [{Key, Value} || {Key, Value} <- Optional, Value =/= []], + Metadata = maps:from_list([ + {<<"name">>, PkgName}, + {<<"version">>, binarify(Version)}, + {<<"requirements">>, maps:from_list(Deps1)} + | OptionalFiltered + ]), + + case create_package_tarball(Metadata, PackageFiles) of + {error, _} = Err -> + Err; + Tarball -> + Package = #{ + type => package, + name => PkgName, + deps => Deps1, + version => Version, + metadata => Metadata, + files => PackageFiles, + tarball => Tarball, + has_checkouts => has_checkouts(State) + }, + {ok, Package} + end; + Error -> + Error + end. + +update_versions(ConfigDeps, LockDeps) -> + [ + begin + case lists:keyfind(binary_to_atom(N, utf8), 1, ConfigDeps) of + {_, V} when is_binary(V) -> + Req = {<<"requirement">>, V}, + {N, maps:from_list(lists:keyreplace(<<"requirement">>, 1, M, Req))}; + {_, V} when is_list(V) -> + Req = {<<"requirement">>, binarify(V)}, + {N, maps:from_list(lists:keyreplace(<<"requirement">>, 1, M, Req))}; + _ -> + %% using version from lock. prepend ~> to make it looser + {_, Version} = lists:keyfind(<<"requirement">>, 1, M), + Req = {<<"requirement">>, <<"~>", Version/binary>>}, + {N, maps:from_list(lists:keyreplace(<<"requirement">>, 1, M, Req))} + end + end + || {N, M} <- LockDeps + ]. + +include_files(Name, AppDir, AppDetails) -> + AppSrc = {application, to_atom(Name), AppDetails}, + FilePaths = proplists:get_value(files, AppDetails, ?DEFAULT_FILES), + %% In versions prior to v7 the name of the for including paths and excluding paths was include_files and + %% exclude_files. We don't document this anymore, but we do support it to avoid breaking changes. However, + %% users should be instructed to use *_paths. Likewise for exclude_regexps which is now documented as + %% exclude_patterns. + maybe_warn_about(include_files, proplists:get_value(include_files, AppDetails, undefined)), + maybe_warn_about(exclude_regexps, proplists:get_value(exclude_regexps, AppDetails, undefined)), + IncludePaths = proplists:get_value(include_paths, AppDetails, proplists:get_value(include_files, AppDetails, [])), + ExcludePaths = proplists:get_value(exclude_paths, AppDetails, proplists:get_value(exclude_files, AppDetails, [])), + ExcludeRes = proplists:get_value(exclude_patterns, AppDetails, proplists:get_value(exclude_regexps, AppDetails, [])), + + AllFiles = lists:ukeysort(2, rebar3_hex_file:expand_paths(FilePaths, AppDir)), + IncludeFiles = lists:ukeysort(2, rebar3_hex_file:expand_paths(IncludePaths, AppDir)), + ExcludeFiles = lists:ukeysort(2, rebar3_hex_file:expand_paths(ExcludePaths, AppDir)), + + %% We filter first and then include, that way glob excludes can be + %% overwritten be explict includes + FilterExcluded = lists:filter( + fun({_, Path}) -> + not exclude_file(Path, ExcludeFiles, ExcludeRes) + end, + AllFiles + ), + WithIncludes = lists:ukeymerge(2, FilterExcluded, IncludeFiles), + + AppFileSrc = filename:join("src", rebar_utils:to_list(Name) ++ ".app.src"), + AppSrcBinary = binarify(lists:flatten(io_lib:format("~tp.\n", [AppSrc]))), + lists:keystore(AppFileSrc, 1, WithIncludes, {AppFileSrc, AppSrcBinary}). + +maybe_warn_about(_, undefined) -> ok; +maybe_warn_about(include_files, _) -> + Deprecation = "include_files has been deprecated, and will be " + ++ "removed in a later version of rebar3_hex. " + ++ "You should use include_paths instead. See " + ++ "\"rebar3 help hex build\" or \"rebar3_hex_build\" " + ++ "module docs for more info.", + rebar_api:warn(Deprecation, []); +maybe_warn_about(exclude_regexps, _) -> + Deprecation = "exclude_regexps has been deprecated, and will be " + ++ "removed in a later version of rebar3_hex. " + ++ "You should use exclude_paths instead. See " + ++ "\"rebar3 help hex build\" or \"rebar3_hex_build\" " + ++ "module docs for more info.", + rebar_api:warn(Deprecation, []). + +exclude_file(Path, ExcludeFiles, ExcludeRe) -> + lists:keymember(Path, 2, ExcludeFiles) orelse + known_exclude_file(Path, ExcludeRe). + +known_exclude_file(Path, ExcludeRe) -> + KnownExcludes = [ + %% emacs temp files + "~$", + %% c object files + "\\.o$", + %% compiled nif libraries + "\\.so$", + %% vim swap files + "\\.swp$" + ], + lists:foldl( + fun + (_, true) -> true; + (RE, false) -> re:run(Path, RE) =/= nomatch + end, + false, + KnownExcludes ++ ExcludeRe + ). + +%% Note that we return a list +has_checkouts(State) -> + filelib:is_dir(rebar_dir:checkouts_dir(State)). + +%% @private +create_docs(State, Repo, App) -> + create_docs(State, Repo, App, #{doc_dir => undefined}). + +%% @private +create_docs(State, Repo, App, Args) -> + case maybe_gen_docs(State, Repo, App, Args) of + {ok, DocDir} -> + case docs_detected(DocDir) of + true -> + AppDetails = rebar_app_info:app_details(App), + Files = rebar3_hex_file:expand_paths([DocDir], DocDir), + Name = rebar_utils:to_list(rebar_app_info:name(App)), + PkgName = rebar_utils:to_list(proplists:get_value(pkg_name, AppDetails, Name)), + OriginalVsn = rebar_app_info:original_vsn(App), + Vsn = rebar_utils:vcs_vsn(App, OriginalVsn, State), + case hex_tarball:create_docs(Files) of + {ok, Tarball} -> + {ok, #{ + type => docs, tarball => Tarball, name => binarify(PkgName), version => binarify(Vsn) + }}; + {error, Reason} -> + {error, hex_tarball:format_error(Reason)} + end; + false -> + {error, missing_doc_index} + end; + {error, _} = Err -> + Err + end. + +maybe_gen_docs(_State, _Repo, App, #{doc_dir := DocDir}) when is_list(DocDir) -> + AppDir = rebar_app_info:dir(App), + {ok, filename:absname(filename:join(AppDir, DocDir))}; +maybe_gen_docs(State, Repo, App, _Args) -> + case doc_opts(State, Repo) of + {ok, PrvName} -> + case providers:get_provider(PrvName, rebar_state:providers(State)) of + not_found -> + {error, {doc_provider_not_found, PrvName}}; + Prv -> + case providers:do(Prv, State) of + {ok, _State1} -> + {ok, resolve_dir(App, PrvName)}; + _ -> + {error, {doc_provider_failed, PrvName}} + end + end; + _ -> + {error, no_doc_config} + end. + +resolve_dir(App, PrvName) -> + AppDir = rebar_app_info:dir(App), + AppOpts = rebar_app_info:opts(App), + DocOpts = + case PrvName of + edoc -> + rebar_opts:get(AppOpts, edoc_opts, []); + _ -> + rebar_opts:get(AppOpts, PrvName, []) + end, + DocDir = proplists:get_value(dir, DocOpts, ?DEFAULT_DOC_DIR), + filename:absname(filename:join(AppDir, DocDir)). + +docs_detected(DocDir) -> + filelib:is_file(DocDir ++ "/index.html"). + +-spec doc_opts(rebar_state:t(), map()) -> {ok, atom()} | undefined. +doc_opts(State, Repo) -> + case Repo of + #{doc := #{provider := PrvName}} when is_atom(PrvName) -> + Deprecation = "Setting doc options in repo configuration has been deprecated." + " You should configure a docmentation provider in top level hex " + " configuration now.", + rebar_api:warn(Deprecation, []), + {ok, PrvName}; + _ -> + Opts = rebar_state:opts(State), + case proplists:get_value(doc, rebar_opts:get(Opts, hex, []), undefined) of + undefined -> undefined; + PrvName when is_atom(PrvName) -> {ok, PrvName}; + #{provider := PrvName} -> {ok, PrvName}; + _ -> undefined + end + end. + +binarify(Term) when is_boolean(Term) -> + Term; +binarify(Term) when is_atom(Term) -> + atom_to_binary(Term, utf8); +binarify([]) -> + []; +binarify(Map) when is_map(Map) -> + maps:from_list(binarify(maps:to_list(Map))); +binarify(Term) when is_list(Term) -> + case io_lib:printable_unicode_list(Term) of + true -> + rebar_utils:to_binary(Term); + false -> + [binarify(X) || X <- Term] + end; +binarify({Key, Value}) -> + {binarify(Key), binarify(Value)}; +binarify(Term) -> + Term. + +create_package_tarball(Metadata, Files) -> + case hex_tarball:create(Metadata, Files) of + {ok, #{tarball := Tarball, inner_checksum := _Checksum}} -> + Tarball; + {error, Reason} -> + {error, hex_tarball:format_error(Reason)} + end. + +-spec to_atom(atom() | string() | binary() | integer() | float()) -> + atom(). +to_atom(X) when erlang:is_atom(X) -> + X; +to_atom(X) when erlang:is_list(X) -> + list_to_existing_atom(X); +to_atom(X) -> + to_atom(rebar_utils:to_list(X)). + +to_map(Map) when is_map(Map) -> + Map; +to_map(List) when is_list(List) -> + maps:from_list(List). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_client.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_client.erl new file mode 100644 index 0000000000000000000000000000000000000000..c0f446d14c9bb22b1223f5d6227b02cdfde4de73 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_client.erl @@ -0,0 +1,166 @@ +%% @private +-module(rebar3_hex_client). + +-export([ is_success/1 + , create_user/4 + , delete_release/3 + , me/1 + , key_add/3 + , key_get/2 + , key_delete/2 + , key_delete_all/1 + , key_list/1 + , publish/3 + , publish_docs/4 + , delete_docs/3 + , test_key/2 + , member_of/1 + , pretty_print_status/1 + , pretty_print_errors/1 + , reset_password/2 + , retire/5 + , unretire/3 + ]). + +-include("rebar3_hex.hrl"). + +-define(is_success(N), N >= 200 andalso N =< 299). + +create_user(HexConfig, Username, Password, Email) -> + Res = hex_api_user:create(HexConfig, Username, Password, Email), + response(Res). + +reset_password(HexConfig, User) -> + Res = hex_api_user:reset_password(HexConfig, User), + response(Res). + +me(HexConfig) -> + Res = hex_api_user:me(to_hex_core_config(HexConfig)), + response(Res). + +key_add(HexConfig, <>, Perms) -> + Res = hex_api_key:add(HexConfig, KeyName, Perms), + response(Res); +key_add(HexConfig, KeyName, Perms) -> + key_add(HexConfig, to_binary(KeyName), Perms). + +key_get(HexConfig, <>) -> + Res = hex_api_key:get(HexConfig, KeyName), + response(Res); +key_get(HexConfig, KeyName) -> + key_get(HexConfig, to_binary(KeyName)). + +member_of(HexConfig) -> + Res = hex_api_organization:list(HexConfig), + response(Res). + +key_list(HexConfig) -> + Res = hex_api_key:list(HexConfig), + response(Res). + +key_delete(HexConfig, <>) -> + Res = hex_api_key:delete(HexConfig, KeyName), + response(Res); +key_delete(HexConfig, KeyName) -> + key_delete(HexConfig, to_binary(KeyName)). + +key_delete_all(HexConfig) -> + Res = hex_api_key:delete_all(HexConfig), + response(Res). + +test_key(HexConfig, Perms) -> + Res = hex_api_auth:test(to_hex_core_config(HexConfig), Perms), + response(Res). + +publish(HexConfig, Tarball, Opts) -> + Res = hex_api_release:publish(to_hex_core_config(HexConfig), Tarball, Opts), + response(Res). + +delete_release(HexConfig, Name, Version) -> + Res = hex_api_release:delete(HexConfig, Name, Version), + response(Res). + +publish_docs(Config, Name, Version, Tarball) -> + TarballContentType = "application/octet-stream", + + Headers = maps:get(http_headers, Config, #{}), + Headers1 = maps:put(<<"content-length">>, integer_to_binary(byte_size(Tarball)), Headers), + Config2 = maps:put(http_headers, Headers1, Config), + Path = hex_api:build_repository_path(Config2, ["packages", Name, "releases", Version, "docs"]), + Body = {TarballContentType, Tarball}, + Res = hex_api:post(Config2, Path, Body), + response(Res). + +delete_docs(Config, Name, Version) -> + Res = hex_api:delete(Config, ["packages", Name, "releases", Version, "docs"]), + response(Res). + +retire(Config, Package, Version, Reason, Message) -> + Msg = #{<<"reason">> => Reason, + <<"message">> => Message + }, + Res = hex_api_release:retire(Config, Package, Version, Msg), + response(Res). + +unretire(Config, Package, Version) -> + Res = hex_api_release:unretire(Config, Package, Version), + response(Res). + +response({ok, {201, _Headers, Res}}) -> + {ok, Res}; +response({ok, {204, _Headers, Res}}) -> + {ok, Res}; +response({ok, {N, _Headers, Res}}) when ?is_success(N) -> + {ok, Res}; +response({ok, {401, _Headers, Res}}) -> + {error, Res}; +response({ok, {403, _Headers, Res}}) -> + {error, Res}; +response({ok, {404, _Headers, Res}}) -> + {error, Res}; +response({ok, {422, _Headers, #{<<"message">> := <<"Validation error(s)">>} = Res}}) -> + {error, Res}; +response({ok, {422, _Headers, Res}}) -> + {error, Res}; +response({ok, {500, _Headers, Res}}) -> + {error, Res}; +response({_, _} = Unknown) -> + Unknown. + +is_success(N) when ?is_success(N) -> true; +is_success(_N) -> false. + +pretty_print_status(401) -> "Authentication failed (401)"; +pretty_print_status(403) -> "Forbidden (403)"; +pretty_print_status(404) -> "Entity not found (404)"; +pretty_print_status(422) -> "Validation failed (422)"; +pretty_print_status(Code) -> io_lib:format("HTTP status code: ~p", [Code]). + +pretty_print_errors(Errors) -> + L = maps:fold(fun(K,V,Acc) -> + case is_map(V) of + true -> + Acc ++ [pretty_print_errors(V)]; + false -> + Acc ++ [<>] + end + end, + [], + Errors), + binary:list_to_bin(join_lists(", ", L)). + +-ifdef(POST_OTP_18). +join_lists(Sep, List) -> lists:join(Sep, List). +-else. +join_lists(_Sep, []) -> []; +join_lists(Sep, List) -> + [Last | AllButLast] = lists:reverse(List), + lists:foldl(fun (Elem,Acc) -> [Elem,Sep|Acc] end, [Last], AllButLast). +-endif. + +to_binary(Subject) -> + rebar_utils:to_binary(Subject). + +to_hex_core_config(#{name := Name} = HexConfig) -> + NewHexConfig = HexConfig#{repo_name := Name}, + maps:remove(name, NewHexConfig). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_config.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_config.erl new file mode 100644 index 0000000000000000000000000000000000000000..760a06635be736e311d854133fbdd45d997c5187 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_config.erl @@ -0,0 +1,254 @@ +%% @private +-module(rebar3_hex_config). + +-export([ api_key_name/1 + , api_key_name/2 + , all_repos/1 + , encrypt_write_key/3 + , decrypt_write_key/3 + , repos_key_name/0 + , org_key_name/2 + , parent_repos/1 + , get_hex_config/3 + , default_repo/1 + , repo/1 + , repo/2 + , update_auth_config/2 + ]). + +-include("rebar3_hex.hrl"). + +-type repo_error() :: {not_valid_repo, string()} | no_repo_in_state | {required, repo}. +-export_type([repo_error/0]). + +-spec api_key_name(binary()) -> binary(). +api_key_name(Key) -> + Prefix = key_name_prefix(Key), + key_name(Prefix, <<"-api">>). + +-spec api_key_name(binary(), binary()) -> binary(). +api_key_name(Key, Suffix) -> + Prefix = key_name_prefix(Key), + key_name(Prefix, <<"-api-">>, Suffix). + +-ifdef(POST_OTP_22). +-spec encrypt_write_key(binary(), binary(), binary()) -> {binary(), {binary(), binary()}}. +encrypt_write_key(Username, LocalPassword, WriteKey) -> + AAD = Username, + IV = crypto:strong_rand_bytes(16), + Key = pad(LocalPassword), + {IV, crypto:crypto_one_time_aead(cipher(Key), Key, IV, WriteKey, AAD, true)}. +-else. +-spec encrypt_write_key(binary(), binary(), binary()) -> {binary(), {binary(), binary()}}. +encrypt_write_key(Username, LocalPassword, WriteKey) -> + AAD = Username, + IV = crypto:strong_rand_bytes(16), + {IV, crypto:block_encrypt(aes_gcm, pad(LocalPassword), IV, {AAD, WriteKey})}. +-endif. + +-ifdef(POST_OTP_22). +decrypt_write_key(Username, LocalPassword, {IV, {CipherText, CipherTag}}) -> + Key = pad(LocalPassword), + crypto:crypto_one_time_aead(cipher(Key), Key, IV, CipherText, Username, CipherTag, false). +-else. +decrypt_write_key(Username, LocalPassword, {IV, {CipherText, CipherTag}}) -> + crypto:block_decrypt(aes_gcm, pad(LocalPassword), IV, {Username, CipherText, CipherTag}). +-endif. + +-ifdef(POST_OTP_22). +cipher(Key) when byte_size(Key) == 16 -> aes_128_gcm; +cipher(Key) when byte_size(Key) == 24 -> aes_192_gcm; +cipher(Key) when byte_size(Key) == 32 -> aes_256_gcm. +-endif. + +pad(Binary) -> + case byte_size(Binary) of + Size when Size =< 16 -> + <>; + Size when Size =< 24 -> + <>; + Size when Size =< 32 -> + <> + end. + +-spec repos_key_name() -> binary(). +repos_key_name() -> + key_name(hostname(), <<"-repositories">>). + +-spec org_key_name(binary(), binary()) -> binary(). +org_key_name(Key, Org) -> + Prefix = key_name_prefix(Key), + key_name(Prefix, <<"-repository-">>, Org). + +-spec hostname() -> binary(). +hostname() -> + {ok, Name} = inet:gethostname(), + list_to_binary(Name). + +key_name(Prefix, Suffix) -> + <>. + +key_name(Prefix, Interfix, Suffix) -> + <>. + +key_name_prefix(undefined) -> hostname(); +key_name_prefix(Key) -> Key. + +update_auth_config(Config, State) -> + rebar_hex_repos:update_auth_config(Config, State). + +all_repos(State) -> + Resources = rebar_state:resources(State), + #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources), + Repos. + +-spec repo(rebar_state:t()) -> {ok, map()} | {error, repo_error()}. +repo(State) -> + {Args, _} = rebar_state:command_parsed_args(State), + Repos = all_repos(State), + case proplists:get_value(repo, Args, undefined) of + undefined -> + Res = [R || R <- Repos, maps:get(name, R) =/= ?DEFAULT_HEX_REPO], + case Res of + [] -> + case rebar_hex_repos:get_repo_config(?DEFAULT_HEX_REPO, Repos) of + {ok, Repo} -> + {ok, set_http_adapter(Repo)}; + _ -> + {error, no_repo_in_state} + end; + [_Repo|_Rest] -> + {error, {required, repo}} + end; + RepoName -> + repo(State, RepoName) + end. + +repo(State, RepoName) -> + BinName = rebar_utils:to_binary(RepoName), + Repos = all_repos(State), + MaybeFound1 = get_repo(BinName, all_repos(State)), + MaybeParentRepo = <<"hexpm:">>, + MaybeFound2 = get_repo(<>, Repos), + case {MaybeFound1, MaybeFound2} of + {{ok, Repo1}, undefined} -> + Repo2 = set_http_adapter(merge_with_env(Repo1)), + Repo3 = maybe_set_api_organization(Repo2), + {ok, maybe_set_api_repository(Repo3)}; + {undefined, {ok, Repo2}} -> + Repo3 = set_http_adapter(merge_with_env(Repo2)), + Repo4 = maybe_set_api_organization(Repo3), + {ok, maybe_set_api_repository(Repo4)}; + {undefined, undefined} -> + {error, {not_valid_repo, RepoName}} + end. + + +-define( ENV_VARS + , [ {"HEX_API_KEY", {api_key, {string, undefined}}} + , {"HEX_API_URL", {api_url, {string, undefined}}} + , {"HEX_UNSAFE_REGISTRY", {repo_verify, {boolean, false}}} + , {"HEX_NO_VERIFY_REPO_ORIGIN", {repo_verify_origin, {boolean, true}}} + ] + ). + +merge_with_env(Repo) -> + lists:foldl(fun({EnvName, {Key, _} = Default}, Acc) -> + Val = maybe_env_val(EnvName, Default), + maybe_put_key(Key, Val, Acc) + end, Repo, ?ENV_VARS). + +maybe_put_key(_Key, undefined, Repo) -> + Repo; +maybe_put_key(Key, Val, Repo) -> + case maps:get(Key, Repo, undefined) of + Val -> + Repo; + _ -> + Repo#{Key => Val} + end. + +maybe_env_val(K, {_, {Type, Default}}) -> + case {os:getenv(K), {Type, Default}} of + {false, {_, Default}} -> + Default; + {"", {_, Default}} -> + Default; + {Val, {boolean, _}} -> + to_bool(string:to_lower(Val)); + {Val, {string, _}} -> + rebar_utils:to_binary(Val) + end. + +set_http_adapter(Repo) -> + Repo#{http_adapter => {rebar3_hex_httpc_adapter, #{profile => rebar}}}. + +to_bool("0") -> false; +to_bool("false") -> false; +to_bool(_) -> true. + +parent_repos(State) -> + Fun = fun(#{name := Name} = Repo, Acc) -> + [Parent|_] = rebar3_hex_io:str_split(Name, <<":">>), + case maps:is_key(Parent, Acc) of + true -> + Acc; + false -> + maps:put(name, Repo, Acc) + end + end, + Map = lists:foldl(Fun, #{}, all_repos(State)), + maps:values(Map). + +default_repo(State) -> + rebar_hex_repos:get_repo_config(?DEFAULT_HEX_REPO, all_repos(State)). + +get_repo(BinaryName, Repos) -> + try rebar_hex_repos:get_repo_config(BinaryName, Repos) of + Name -> + Name + catch + {error,{rebar_hex_repos,{repo_not_found,BinaryName}}} -> undefined + end. + +-spec get_hex_config(module(), map(), read | write) -> map(). +get_hex_config(Module, Repo, Mode) -> + case hex_config(Repo, Mode) of + {ok, HexConfig} -> + HexConfig; + {error, Reason} -> + erlang:error({error, {Module, {get_hex_config, Reason}}}) + end. + +hex_config(Repo, read) -> + hex_config_read(Repo); +hex_config(Repo, write) -> + hex_config_write(Repo). + +hex_config_write(#{api_key := Key} = HexConfig) when is_binary(Key) -> + {ok, set_http_adapter(HexConfig)}; +hex_config_write(#{write_key := undefined}) -> + {error, no_write_key}; +hex_config_write(#{write_key := WriteKey, username := Username} = HexConfig) -> + DecryptedWriteKey = rebar3_hex_user:decrypt_write_key(Username, WriteKey), + {ok, set_http_adapter(HexConfig#{api_key => DecryptedWriteKey})}; +hex_config_write(_) -> + {error, no_write_key}. + +hex_config_read(#{read_key := ReadKey} = HexConfig) -> + {ok, set_http_adapter(HexConfig#{api_key => ReadKey})}; +hex_config_read(_Config) -> + {error, no_read_key}. + +maybe_set_api_organization(#{name := Name} = Repo) -> + case binary:split(Name, <<":">>) of + [_] -> + Repo#{api_organization => undefined}; + [_,Org] -> + Repo#{api_organization => Org} + end. + +maybe_set_api_repository(#{api_repository := _} = Repo) -> + Repo; +maybe_set_api_repository(#{} = Repo) -> + Repo#{api_repository => undefined}. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_cut.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_cut.erl new file mode 100644 index 0000000000000000000000000000000000000000..25837c66b933851886c8600818a3d313889eabe2 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_cut.erl @@ -0,0 +1,296 @@ +%% @doc `rebar3 hex cut' - Publish with git tag and version bump features +%% +%% Increments tags and publishes. +%% +%% Incrementing and tagging are both optional features of this provider. +%% +%% By default you'll be prompted what type of increment to make to the version or it can be supplied as an argument to +%% the command `-i', `--increment' switch. +%% +%% `cut' will also optionally create version bump commit, create a tag with a name corresponding to the new version, and +%% prompt you if you'd like to push the tag up to your git repository. +%% +%% You may opt-out of prefixing tags and commits with a `v' prefix (i.e., v1.2.3) using +%% `--prefix-tag false' switch. +%% +%% Below is a full example of `cut' in action : +%% +%% ``` +%% rebar3 hex cut +%% ===> Analyzing applications... +%% ===> Verifying dependencies... +%% Select semver increment or other (Current 0.1.3): +%% 1) patch +%% 2) minor +%% 3) major +%% 4) other +%% [1-4] > 1 +%% Create 'v0.1.4' commit? ("Y")> +%% Push master to origin master? ("N")> +%% Local Password: +%% Publishing myapp 0.1.4 to hexpm:myrepo +%% Description: My Application +%% Dependencies: +%% relx ~>4.5.0 +%% Included files: +%% LICENSE +%% README.md +%% rebar.config +%% src/myapp.app.src +%% src/myapp.erl +%% Licenses: Apache-2.0 +%% Links: +%% github: https://github.com/myname/myapp +%% Build tools: rebar3 +%% Before publishing, please read Hex CoC: https://hex.pm/policies/codeofconduct +%% Proceed (with warnings)? ("Y")> +%% ===> Published myapp 0.1.4 +%% ===> Analyzing applications... +%% ===> Compiling myapp +%% ===> Running edoc for myapp +%% ===> Running ex_doc for myapp +%% ===> Published docs for myapp 0.1.4 +%% Create new git tag v0.1.4? ("Y")> +%% ===> Creating new tag v0.1.4... +%% Push new tag to origin? ("Y")> +%% ===> Pushing new tag v0.1.4... +%% ''' +%% +%%
    +%%
  • `--repo' - Specify the repository to work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must +%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Defaults to `hexpm'. +%%
  • +%%
  • `-i', `--increment' - Specify the type of version increment to perform without being prompted at runtime. +%% Supported types are : +%%
      +%%
    • major
    • +%%
    • minor
    • +%%
    • patch
    • +%%
    +%%
  • +%%
+-module(rebar3_hex_cut). + +-export([init/1, + do/1, + format_error/1]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, cut). +-define(DEPS, [{default, lock}]). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([ + {name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex cut"}, + {short_desc, "Increment version number and publish package"}, + {desc, ""}, + {opts, [{increment, $i, "increment", {string, undefined}, + "Type of semver increment: major, minor or patch"}, + {prefix_tag, $p, "prefix-tag", {boolean, true}, + "Prefix tags with v (i.e., v1.2.3) "}, + rebar3_hex:repo_opt()]} + ]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + case rebar3_hex:task_state(State) of + {ok, Task} -> + handle_task(Task); + {error, Reason} -> + ?RAISE(Reason) + end. + +%% default path - maybe tag, maybe commit, maybe push commit, publish, maybe push tag + +handle_task(#{args := Args} = Task) -> + #{repo := Repo, state := State, apps := Apps} = Task, + Selected = rebar3_hex_io:select_apps(Apps), + lists:foreach(fun(App) -> cut(State, Repo, App, Args) end, Selected), + {ok, State}. + +%% @private +-spec format_error(any()) -> iolist(). +format_error({no_write_key, RepoName}) -> + io_lib:format("No api key with permissions to write to the repository ~ts was found.", [RepoName]); +format_error({bad_increment, Type}) -> + io_lib:format("Increment must be major, minor or patch. ~s is not valid.", [Type]); +format_error({invalid_semver, Version}) -> + Err = "non-semantic version number \"~ts\" found", + io_lib:format(Err, [Version]); +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +%% =================================================================== +%% Public API +%% =================================================================== + +cut(State, Repo, App, #{} = Args) -> + {Version, ResolvedVersion} = version_info(State, App), + MaybeType = maps:get(increment, Args, undefined), + MaybePrefix = maps:get(prefix_tag, Args, true), + Type = get_increment(MaybeType, ResolvedVersion), + NewVersion = increment_version(Type, ResolvedVersion), + MaybePrefixedVersion = maybe_prefix_version(NewVersion, MaybePrefix), + AppSrcFile = rebar_app_info:app_file_src(App), + + case Version of + _Git when Version =:= git orelse Version =:= "git" -> + create_tag(MaybePrefixedVersion), + + case try_publish(State, Repo, App, Args) of + {ok, _State} -> + maybe_push_tag(MaybePrefixedVersion); + _ -> + delete_tag(MaybePrefixedVersion), + {ok, State} + end; + _ -> + Spec = rebar3_hex_file:update_app_src(App, NewVersion), + NewAppSrcFile = io_lib:format("~tp.\n", [Spec]), + ok = rebar_file_utils:write_file_if_contents_differ(AppSrcFile, NewAppSrcFile), + ask_commit_and_push(MaybePrefixedVersion), + case try_publish(State, Repo, rebar_app_info:original_vsn(App, NewVersion), Args) of + {ok, _} -> + maybe_create_and_push_tag(MaybePrefixedVersion), + {ok, State}; + {error, publish_failed} -> + delete_tag(MaybePrefixedVersion), + {ok, State} + end + + end. + +maybe_prefix_version(Vsn, true) -> + io_lib:format("v~s", [Vsn]); +maybe_prefix_version(Vsn, false) -> + Vsn. + +maybe_create_and_push_tag(Version) -> + PromptStr = io_lib:format("Create new git tag ~s?", [Version]), + case rebar3_hex_io:ask(PromptStr, boolean, "Y") of + true -> + create_tag(Version), + maybe_push_tag(Version); + false -> + ok + end. + +create_tag(Version) -> + rebar_api:info("Creating new tag ~s...", [Version]), + rebar_utils:sh(io_lib:format("git tag ~s", [Version]), []). + +maybe_push_tag(Version) -> + case rebar3_hex_io:ask("Push new tag to origin?", boolean, "Y") of + true -> + push_tag(Version); + false -> + ok + end. + +push_tag(Version) -> + rebar_api:info("Pushing new tag ~s...", [Version]), + rebar_utils:sh(io_lib:format("git push origin ~s", [Version]), []). + +delete_tag(Version) -> + rebar_api:info("Deleting new tag ~s...", [Version]), + rebar_utils:sh(io_lib:format("git tag -d ~s", [Version]), []). + +try_publish(State, Repo, App, Args) -> + try rebar3_hex_publish:publish(State, Repo, App, Args) of + {ok, _} -> + {ok, State} + catch + error:{error, {rebar3_hex_publish, Err}} -> + ErrStr = rebar3_hex_publish:format_error(Err), + rebar_api:error(ErrStr, []), + {error, publish_failed} + end. + +increment_version(other, _CurrentVersion) -> + CustomVersion = rebar3_hex_io:ask("New Version ", string), + _parsed = parse_version(CustomVersion), + rebar_utils:to_binary(CustomVersion); + +increment_version(Type, VersionStr) when is_list(VersionStr) orelse is_binary(VersionStr) -> + Parsed = parse_version(VersionStr), + increment_version(Type, Parsed); + +increment_version(Type, Version) -> + Inc = rebar3_hex_version:increment(Type, Version), + rebar3_hex_version:format(Inc). + +get_increment(undefined, Version) -> + rebar3_hex_io:say("Select semver increment or other (Current ~s):", [Version]), + rebar3_hex_io:say("1) patch", []), + rebar3_hex_io:say("2) minor", []), + rebar3_hex_io:say("3) major", []), + rebar3_hex_io:say("4) other", []), + case rebar3_hex_io:ask("[1-4] ", number) of + 4 -> + other; + TypeInt -> + case int_to_increment(TypeInt) of + error -> + rebar_api:error("Invalid number given, try again~n", []), + get_increment(undefined, Version); + Type -> + Type + end + end; + +get_increment(Type, _) -> normalize_increment(Type). + +parse_version(Version) -> + case rebar3_hex_version:parse(Version) of + {ok, Parsed} -> + Parsed; + _Err -> + ?RAISE({invalid_semver, Version}) + end. + +int_to_increment(1) -> patch; +int_to_increment(2) -> minor; +int_to_increment(3) -> major; +int_to_increment(_) -> error. + +version_info(State, App) -> + Version = rebar_app_info:original_vsn(App), + Resolved = rebar3_hex_app:vcs_vsn(State, App), + {Version, Resolved}. + +normalize_increment("patch") -> patch; +normalize_increment("minor") -> minor; +normalize_increment("major") -> major; +normalize_increment(_) -> error. + +ask_commit_and_push(NewVersion) -> + case rebar3_hex_io:ask(io_lib:format("Create '~s' commit?", [NewVersion]), boolean, "Y") of + true -> + rebar_utils:sh(io_lib:format("git commit -a -m '~s'", [NewVersion]), []), + case rebar3_hex_io:ask("Push master to origin master?", boolean, "N") of + true -> + rebar_utils:sh("git push origin master:master", []); + false -> + ok + end; + false -> + ok + end. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_error.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_error.erl new file mode 100644 index 0000000000000000000000000000000000000000..81ac56689e67728f7787b90908b3d9218a5c4a63 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_error.erl @@ -0,0 +1,40 @@ +%% @private +-module(rebar3_hex_error). + +-export([format_error/1]). + +format_error({required, repo}) -> + "A repository argument is required for this command."; + +format_error({not_valid_repo, RepoName}) -> + io_lib:format("Could not find ~ts in repo configuration. Be sure to authenticate first with rebar3 hex user auth.", + [RepoName]); + +format_error({get_hex_config, no_read_key}) -> + "No read key found for user. Be sure to authenticate first with:" + " rebar3 hex user auth"; + +format_error({get_hex_config, no_write_key}) -> + "No write key found for user. Be sure to authenticate first with:" + " rebar3 hex user auth"; + +format_error({Cmd, unsupported_params}) -> + io_lib:format("Either some or all of the parameters supplied for the ~ts command are ", [Cmd]) + ++ " invalid or form an invalid combination of parameters."; + +format_error({Cmd, missing_required_params}) -> + io_lib:format("Required parameters for the ~ts command have not been supplied.", [Cmd]); + +format_error({Cmd, {error, {failed_connect, [{to_address,_}, + {inet,[inet],econnrefused}]} = Err}}) -> + rebar_log:log(diagnostic, "Failed to connect to hex repository : ~p , context : ~ts", [Err, Cmd]), + io_lib:format("Error connecting to hex repository api. Run with DIAGNOSTIC=1 for more details", []); + +format_error(Reason) -> + rebar_log:log(diagnostic, "Unknown error: ~p", [Reason]), + case rebar_log:get_level() of + 4 -> + "An unknown error was encountered"; + _ -> + "An unknown error was encountered. Run with DIAGNOSTIC=1 for more details." + end. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_file.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_file.erl new file mode 100644 index 0000000000000000000000000000000000000000..5c5cfbe529565dc78aa120666a9f20b53d692bda --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_file.erl @@ -0,0 +1,93 @@ +%% @private +-module(rebar3_hex_file). + +-include_lib("kernel/include/file.hrl"). + +-export([ + expand_paths/2, + update_app_src/2 +]). + +expand_paths(Paths, Dir) -> + AbsDir = expand(rebar3_hex:to_binary(Dir)), + Files1 = [filename:join(AbsDir, rebar3_hex:to_binary(P)) || P <- Paths], + Files2 = lists:flatmap( + fun(F) -> + [rebar3_hex:to_binary(F1) || F1 <- filelib:wildcard(rebar3_hex:to_list(F))] + end, + Files1 + ), + Files3 = lists:flatmap(fun dir_files/1, Files2), + case lists:map(fun expand/1, Files3) of + [] -> + []; + Files4 -> + [ + {rebar3_hex:to_list(relative_to(F, AbsDir)), rebar3_hex:to_list(F)} + || F <- uniq(Files4) + ] + end. + +update_app_src(App, Version) -> + AppSrcFile = rebar_app_info:app_file_src(App), + AppSrc = rebar_file_utils:try_consult(AppSrcFile), + [{application, Name, Details}] = AppSrc, + NewDetails = lists:keyreplace(vsn, 1, Details, {vsn, rebar3_hex:to_list(Version)}), + {application, Name, NewDetails}. + +relative_to(Path, From) when is_binary(Path) andalso is_binary(From) -> + relative_to(filename:split(Path), filename:split(From), Path). + +relative_to(Path1, Path2, _Original) when Path1 =:= Path2 -> + <<".">>; +relative_to([_H | T1], [_H1 | T2], Original) -> + relative_to(T1, T2, Original); +relative_to([_ | _] = L1, [], _Original1) -> + filename:join(L1); +relative_to(_, _, Original) -> + Original. + +dir_files(Path) -> + case file:read_link_info(Path, [{time, universal}]) of + {ok, FileInfo} -> + case FileInfo#file_info.type of + directory -> + {ok, More} = file:list_dir(Path), + Paths = [filename:join(Path, F) || F <- More], + NewPaths = lists:flatmap(fun dir_files/1, Paths), + [Path | NewPaths]; + _ -> + [Path] + end; + _ -> + [Path] + end. + +uniq(List) -> + maps:keys(lists:foldl(fun(E, Acc) -> Acc#{E => true} end, #{}, List)). + +expand(Path) -> + expand_dot(filename:absname(Path)). + +expand_dot(<<"/", Rest/binary>>) -> + <<"/", (do_expand_dot(Rest))/binary>>; +expand_dot(<>) when is_integer(Letter) andalso Letter >= 97 andalso Letter =< 122 -> + <>; +expand_dot(Path) -> + do_expand_dot(Path). + +do_expand_dot(Path) -> + do_expand_dot(binary:split(Path, <<"/">>, [global]), []). + +do_expand_dot([<<"..">> | T], [_, _ | Acc]) -> + do_expand_dot(T, Acc); +do_expand_dot([<<"..">> | T], []) -> + do_expand_dot(T, []); +do_expand_dot([<<".">> | T], Acc) -> + do_expand_dot(T, Acc); +do_expand_dot([H | T], Acc) -> + do_expand_dot(T, [<<"/">>, H | Acc]); +do_expand_dot([], []) -> + <<>>; +do_expand_dot([], [<<"/">> | Acc]) -> + iolist_to_binary(lists:reverse(Acc)). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_httpc_adapter.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_httpc_adapter.erl new file mode 100644 index 0000000000000000000000000000000000000000..49ebe67de038520da600c49a293a9fcea57a85ef --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_httpc_adapter.erl @@ -0,0 +1,42 @@ +%% @private +%% Derived from rebar3_httpc_adapter, which was derived from hex_core v0.7.1 for extra flexibility. + +-module(rebar3_hex_httpc_adapter). +-behaviour(hex_http). +-export([request/5]). + +%%==================================================================== +%% API functions +%%==================================================================== + +request(Method, URI, ReqHeaders, Body, AdapterConfig) -> + Profile = maps:get(profile, AdapterConfig, default), + Request = build_request(URI, ReqHeaders, Body), + SSLOpts = [{ssl, rebar_utils:ssl_opts(URI)}], + case httpc:request(Method, Request, SSLOpts, [{body_format, binary}], Profile) of + {ok, {{_, StatusCode, _}, RespHeaders, RespBody}} -> + RespHeaders2 = load_headers(RespHeaders), + {ok, {StatusCode, RespHeaders2, RespBody}}; + {error, Reason} -> {error, Reason} + end. + +%%==================================================================== +%% Internal functions +%%==================================================================== + +build_request(URI, ReqHeaders, Body) -> + build_request2(binary_to_list(URI), dump_headers(ReqHeaders), Body). + +build_request2(URI, ReqHeaders, undefined) -> + {URI, ReqHeaders}; +build_request2(URI, ReqHeaders, {ContentType, Body}) -> + {URI, ReqHeaders, ContentType, Body}. + +dump_headers(Map) -> + maps:fold(fun(K, V, Acc) -> + [{binary_to_list(K), binary_to_list(V)} | Acc] end, [], Map). + +load_headers(List) -> + lists:foldl(fun({K, V}, Acc) -> + maps:put(list_to_binary(K), list_to_binary(V), Acc) end, #{}, List). + diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_io.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_io.erl new file mode 100644 index 0000000000000000000000000000000000000000..a09c082a89cbe85fcd597bdf6d32a443fad98e70 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_io.erl @@ -0,0 +1,165 @@ +%% @private +-module(rebar3_hex_io). + +-export([ + get_password/1, + say/1, + say/2, + ask/2, + ask/3, + select_apps/1, + str_split/2 + ]). + + + +-ifdef(POST_OTP_19). +str_split(Str, Pattern) -> + string:split(Str, Pattern). +-else. +str_split(Str, Pattern) -> + Bin = unicode:characters_to_binary(Str), + Bpat = unicode:characters_to_binary(Pattern), + Blist = binary:split(Bin, Bpat), + lists:map(fun(B) -> unicode:characters_to_list(B) end, Blist). +-endif. +-include("rebar3_hex.hrl"). + +select_apps([App]) -> + [App]; +select_apps(Apps) -> + io:format("Select application(s):~n", []), + lists:foldl(fun(App, Idx) -> + io:format("~p) ~s~n", [Idx, rebar_app_info:name(App)]), + Idx+1 + end, 1, Apps), + io:format("------------~n", []), + io:format("A) All~n", []), + case ask(io_lib:format("[1-~p] or (A)ll ", [length(Apps)]), string, "A") of + "A" -> + Apps; + Index -> + [lists:nth(list_to_integer(Index), Apps)] + end. + +get_password(Prompt) -> + ok = io:setopts([binary]), + Overwriter = fun() -> + prompt_password(Prompt), + receive + {done, _Pid, _Ref} -> + ok + end + end, + Pid = spawn_link(Overwriter), + PwLine = try + io:get_line(Prompt) + after + Ref = make_ref(), + Pid ! {done, self(), Ref}, + receive + {done, Pid, Ref} -> + ok + after + timer:seconds(5) -> + throw(?PRV_ERROR(win32_prompt_timeout)) + end + end, + [Pw | _] = binary:split(PwLine, <<"\n">>), + Pw. + +prompt_password(Prompt) -> + % This is spawned to continually overwrite the prompt the user is + % entering data on, in order to hide characters typed. + ClearLine = "\e[2K", + receive + {done, Parent, Ref} -> + Parent ! {done, self(), Ref}, + Spaces = lists:duplicate(byte_size(Prompt) + 24, $ ), + io:fwrite(standard_error, "~ts\r~ts\r", [ClearLine, Spaces]) + after + 1 -> + Spaces = lists:duplicate(24, $ ), + io:fwrite(standard_error, "~ts\r~ts~ts\r~ts", [ClearLine, Prompt, Spaces, Prompt]), + prompt_password(Prompt) + end. + +ask(Prompt, Type) -> + ask_convert(Prompt, fun get/2, Type, none). + +ask(Prompt, Type, Default) -> + ask_convert(Prompt, fun get/2, Type, Default). + +ask_convert(Prompt, TransFun, Type, Default) -> + DefaultPrompt = erlang:iolist_to_binary([Prompt, default(Default), "> "]), + NewPrompt = erlang:binary_to_list(DefaultPrompt), + Data = trim(trim(io:get_line(NewPrompt)), both, [$\n]), + case TransFun(Type, Data) of + no_data -> + maybe_continue(Prompt, TransFun, Type, Default); + no_clue -> + continue(Prompt, TransFun, Type, Default); + Ret -> + Ret + end. + +maybe_continue(Prompt, TransFun, Type, Default) -> + case Default of + none -> + continue(Prompt, TransFun, Type, Default); + Default -> + TransFun(Type, Default) + end. + +continue(Prompt, TransFun, Type, Default) -> + say("I didn't understand that. A ~p is expected.~n", [Type]), + ask_convert(Prompt, TransFun, Type, Default). + +default(none) -> + []; +default(Default) -> + [" (", io_lib:format("~p", [Default]) , ")"]. + +get(boolean, []) -> + no_data; +get(boolean, [In | _]) when In =:= $Y orelse In =:= $y -> + true; +get(boolean, [In | _]) when In =:= $N orelse In =:= $n -> + false; +get(boolean, _) -> + no_clue; +get(integer, []) -> + no_data; +get(number, String) -> + get(integer, String); +get(integer, String) -> + try list_to_integer(String) + catch _:_ -> no_clue + end; +get(string, []) -> + no_data; +get(string, String) -> + case is_list(String) of + true -> + String; + false -> + no_clue + end. + +-ifdef(unicode_str). +trim(Str, right, Chars) -> string:trim(Str, trailing, Chars); +trim(Str, left, Chars) -> string:trim(Str, leading, Chars); +trim(Str, both, Chars) -> string:trim(Str, both, Chars). +-else. +trim(Str) -> string:strip(rebar_utils:to_list(Str)). +trim(Str, Dir, [Chars|_]) -> string:strip(rebar_utils:to_list(Str), Dir, Chars). +-endif. + +say(Say) -> + io:format(lists:flatten([Say, "~n"])). + +-spec say(string(), [term()] | term()) -> ok. +say(Say, Args) when is_list(Args) -> + io:format(lists:flatten([Say, "~n"]), Args); +say(Say, Args) -> + io:format(lists:flatten([Say, "~n"]), [Args]). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_key.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_key.erl new file mode 100644 index 0000000000000000000000000000000000000000..fe63edacfddaefe28972bcf1f8a49e29b94f70b2 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_key.erl @@ -0,0 +1,115 @@ +%% @private +-module(rebar3_hex_key). + +-export([convert_permissions/2, fetch/2, format_error/1, generate/3, revoke/2, revoke_all/1, list/1]). + +generate(HexConfig, KeyName, Perms) -> + case rebar3_hex_client:key_add(HexConfig, KeyName, Perms) of + {ok, _Res} = Ret -> + Ret; + Error -> + Error + end. + +fetch(HexConfig, KeyName) -> + case rebar3_hex_client:key_get(HexConfig, KeyName) of + {ok, Res} -> + print_key_details(Res); + Error -> + Error + end. + +revoke(HexConfig, KeyName) -> + case rebar3_hex_client:key_delete(HexConfig, KeyName) of + {ok, _Res} -> + ok; + Error -> + Error + end. + +revoke_all(HexConfig) -> + case rebar3_hex_client:key_delete_all(HexConfig) of + {ok, _Res} -> + ok; + Error -> + Error + end. + +list(HexConfig) -> + case rebar3_hex_client:key_list(HexConfig) of + {ok, Res} -> + print_results(Res); + Error -> + Error + end. + +-spec convert_permissions([string()], [map()]) -> [map()]. +convert_permissions([], Defaults) -> + Defaults; +convert_permissions(Perms, _) -> + lists:foldl(fun (Name, Acc) -> + case binary:split(rebar_utils:to_binary(Name), <<":">>) of + [Domain] -> + [#{<<"domain">> => Domain, <<"resource">> => nil}] ++ Acc; + + [Domain, Resource] -> + [#{<<"domain">> => Domain, <<"resource">> => Resource}] ++ Acc + end + end, + [], + Perms). + +print_results(Res) -> + Header = ["Name", "Created"], + Rows = lists:map(fun (#{<<"name">> := Name, <<"inserted_at">> := Created}) -> + [binary_to_list(Name), binary_to_list(Created)] + end, + Res), + ok = rebar3_hex_results:print_table([Header] ++ Rows), + ok. + + + +print_key_details(#{<<"name">> := Name, + <<"inserted_at">> := Created, + <<"updated_at">> := Updated, + <<"last_use">> := + #{<<"ip">> := Addr, <<"used_at">> := Used, <<"user_agent">> := _Agent}}) -> + Header = ["Name", "Created", "Updated", "LastUsed", "LastUsedBy"], + Row = [binary_to_list(Name), + binary_to_list(Created), + binary_to_list(Updated), + binary_to_list(Used), + binary_to_list(Addr)], + ok = rebar3_hex_results:print_table([Header] ++ [Row]), + ok; + +print_key_details(#{<<"name">> := Name, + <<"inserted_at">> := Created, + <<"updated_at">> := Updated}) -> + Header = ["Name", "Created", "Updated", "LastUsed", "LastUsedBy"], + Row = [binary_to_list(Name), + binary_to_list(Created), + binary_to_list(Updated), + "never", + "n/a"], + ok = rebar3_hex_results:print_table([Header] ++ [Row]), + ok. + +-spec format_error(any()) -> iolist(). +format_error({list, {unauthorized, _Res}}) -> + "Error while attempting to perform list : Not authorized"; +format_error({list, {error, #{<<"message">> := Msg}}}) -> + "Error while attempting to perform list : " ++ Msg; +format_error({revoke, {not_found, _Res}}) -> + "Error while revoking key : key not found"; +format_error({generate, + {validation_errors, #{<<"errors">> := Errors, <<"message">> := Message}}}) -> + ErrorString = rebar3_hex_results:errors_to_string(Errors), + io_lib:format("~ts~n\t~ts", [Message, ErrorString]); +format_error(bad_command) -> + "Unknown command. Command must be fetch, generate, list, or " + "revoke"; +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_organization.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_organization.erl new file mode 100644 index 0000000000000000000000000000000000000000..85c2ba8664d7fb1ae01930e1d592944c356519d5 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_organization.erl @@ -0,0 +1,412 @@ +%% @doc +%% `rebar3_hex_organization' - Manage organizations +%% +%% Manages the list of authorized hex organizations. +%% +%% Note that all commands that require a `NAME' argument expect a qualified repository name for the +%% argument (i.e., `hexpm:my_org'). +%% +%% == About Organizations == +%% +%% Organizations are feature provided by hexpm that allows you group packages, public and private alike. Organizations +%% are treated as repositories that have a parent. The parent is found as the first part of a repository's name, +%% separated from the organization by a `:'. So for the organization `your_org' on the main repository `hexpm' +%% the fully qualified name would be `hexpm:your_org'. +%% +%% Be sure to add your organization to either your global rebar.config `~/.config/rebar3/rebar.config' or +%% within an projects `rebar.config'. Below is an example: +%% +%% ``` +%% {hex, [{repos, [ #{name => <<"hexpm:your_org">>}]}]}. +%% ''' +%% +%% == Authorize an organization == +%% +%% This command will generate an API key used to authenticate access to the organization. See the `rebar3_hex_user' +%% tasks to list and control all your active API keys. +%% +%% ``` +%% $ rebar3 hex organization auth NAME [--key KEY] [--key-name KEY_NAME] +%% ''' +%% +%% == Deauthorize and remove an organization == +%% +%% ``` +%% $ rebar3 hex organization deauth NAME +%% ''' +%% +%% == List all authorized organizations == +%% +%% This command will only list organizations you have authorized with this task, it will not list organizations you +%% have access to by having authorized with `rebar3 hex user auth'. +%% +%% == Generate organization key == +%% This command is useful to pre-generate keys for use with `rebar3 hex organization auth NAME --key KEY' on CI +%% servers or similar systems. It returns the hash of the generated key that you can pass to auth NAME `--key' KEY. +%% Unlike the `hex user' key commands, a key generated with this command is owned by the organization directly, +%% and not the user that generated it. This makes it ideal for shared environments such as CI where you don't +%% want to give access to user-specific resources and the user's organization membership status won't affect key. By +%% default this command sets the organization permission which allows read-only access to the organization, it can be +%% overridden with the `--permission' flag. +%% +%% +%% ``` +%% $ rebar3 hex organization key NAME generate [--key-name KEY_NAME] [--permission PERMISSION] +%% ''' +%% +%% == Revoke key == +%% Removes a given key from a organization. +%% +%% ``` +%% $ rebar3 hex organization key NAME revoke KEY_NAME +%% ''' +%% +%% == List keys == +%% Lists all keys associated with the organization. +%% +%% ``` +%% $ rebar3 hex organization key NAME list +%% ''' +%% +%% == Command line options == +%% +%%
    +%%
  • `--all' - Used for revoking all keys for authorized organization. Only valid with the `revoke` task.
  • +%%
  • `--key KEY' - Hash of key used to authenticate HTTP requests to organization, if omitted will generate a new key +%% with your account credentials. This flag is useful if you have a key pre-generated with +%% `rebar3 hex organization key' and want to authenticate on a CI server or similar system.
  • +%%
    +%%
  • `--key-name KEY_NAME' - By default Hex will base the key name on your machine's hostname and the organization +%% name, use this option to give your own name.
  • +%%
    +%%
  • `--permission PERMISSION' - Sets the permissions on the key, this option can be given multiple times, possibly +%% values are: +%%
      +%%
      +%%
    • `api:read' - API read access.
    • +%%
    • `api:write' - API write access.
    • +%%
    • `repository' - Access to the repository (this is the default permission).
    • +%%
    +%%
  • +%%
+ +-module(rebar3_hex_organization). + +-export([ + init/1, + do/1, + format_error/1 +]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, organization). +-define(DEPS, []). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([ + {name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex organization auth my_org --key 1234"}, + {short_desc, "Add, remove or list configured organizations and their auth keys"}, + {desc, ""}, + {opts, [ + {all, undefined, "all", boolean, "Specifies all keys. Only recognized when used with the revoke task."}, + {key, $k, "key", string, "Authentication key for an organization that already exists at the repository."}, + {key_name, undefined, "key-name", string, "Specifies a key name to use when generating or revoking a key."}, + {permission, $p, "permission", list, "Colon delimited permission. This option may be given multiple times."} + ]} + ]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + case rebar_state:command_args(State) of + ["auth", OrgName | _] -> + auth(State, to_binary(OrgName)); + ["deauth", OrgName | _] -> + deauth(State, to_binary(OrgName)); + ["key", OrgName, "generate" | _] -> + generate(State, to_binary(OrgName)); + ["key", OrgName, "revoke", "--all" | _] -> + revoke_all(State, to_binary(OrgName)); + ["key", OrgName, "revoke" | _] -> + revoke(State, to_binary(OrgName)); + ["key", OrgName, "list" | _] -> + list_org_keys(State, to_binary(OrgName)); + ["list" | _] -> + list_orgs(State); + _ -> + ?RAISE(bad_command) + end. + +%% @private +-spec format_error(any()) -> iolist(). +format_error(no_repo) -> + "Authenticate and generate commands require repository name as argument"; +format_error(auth_no_key) -> + "Repo authenticate command requires key"; + +format_error({auth, Reason}) when is_binary(Reason) -> + io_lib:format("Error authenticating organization : ~ts", [Reason]); +format_error({auth, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Error authenticating organization : ~ts", [Reason]); + +format_error({generate_key, Reason}) when is_binary(Reason) -> + io_lib:format("Error generating organization key: ~ts", [Reason]); +format_error({generate_key, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Error generating organization key: ~ts", [Reason]); + +format_error({key_generate, Reason}) when is_binary(Reason) -> + io_lib:format("Error generating organization key: ~ts", [Reason]); +format_error({key_generate, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Error generating organization key: ~ts", [Reason]); + +format_error({key_revoke_all, Reason}) when is_binary(Reason) -> + io_lib:format("Error revoking all organization keys: ~ts", [Reason]); +format_error({key_revoke_all, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Error revoking all organization keys: ~ts", [Reason]); + +format_error({key_list, Reason}) when is_binary(Reason) -> + io_lib:format("Error listing organization keys: ~ts", [Reason]); +format_error({key_list, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Error listing organization keys: ~ts", [Reason]); + +format_error(bad_command) -> + "Invalid arguments, expected one of:\n\n" + "rebar3 hex organization auth ORG_NAME auth\n" + "rebar3 hex organization deauth ORG_NAME deauth\n" + "rebar3 hex organization key ORG_NAME generate\n" + "rebar3 hex organization key ORG_NAME revoke --key-name NAME\n" + "rebar3 hex organization key ORG_NAME revoke --all\n" + "rebar3 hex organization key ORG_NAME list\n" + "rebar3 hex organization list\n"; + +format_error(not_a_valid_repo_name) -> + "Invalid organization repository: organization name arguments must be given as a fully qualified " + "repository name (i.e, hexpm:my_org)"; + +format_error({get_parent_repo_and_org_name, Error, Name}) -> + Str = "Error getting the parent repo for ~ts. Be sure to authenticate first with: rebar3 hex user", + rebar_log:log(diagnostic, "Error getting parent repo and org name: ~p", [Error]), + io_lib:format(Str, [Name]); +format_error({get_repo_by_name, {error,{not_valid_repo,ParentName}}}) -> + Str = io_lib:format("You do not appear to be authenticated as a user to the ~ts repository.", [ParentName]), + Str ++ " " ++ "Run rebar3 hex user auth and try this command again."; + +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +-spec auth(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +auth(State, RepoName) -> + {Opts, _} = rebar_state:command_parsed_args(State), + {ParentRepo, OrgName} = get_parent_repo_and_org_name(State, RepoName), + Key = + case proplists:get_value(key, Opts, undefined) of + undefined -> + Config = rebar3_hex_config:get_hex_config(?MODULE, ParentRepo, write), + Config1 = Config#{api_organization => OrgName}, + KeyName = proplists:get_value(key_name, Opts, rebar3_hex_config:repos_key_name()), + generate_key(Config1, KeyName, default_perms(OrgName)); + ProvidedKey -> + TestPerms = #{domain => <<"repository">>, resource => OrgName}, + Config = ParentRepo#{api_key => to_binary(ProvidedKey), + api_repository => OrgName, + api_organization => OrgName + }, + case rebar3_hex_client:test_key(Config, TestPerms) of + {ok, _} -> + ProvidedKey; + Error -> + ?RAISE({auth, Error}) + end + end, + rebar3_hex_config:update_auth_config(#{RepoName => #{name => RepoName, repo_key => Key}}, State), + rebar3_hex_io:say("Successfully authenticated to ~ts", [RepoName]), + {ok, State}. + +-spec deauth(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +deauth(State, RepoName) -> + ok = rebar_hex_repos:remove_from_auth_config(RepoName, State), + rebar3_hex_io:say("Successfully deauthorized ~ts", [RepoName]), + {ok, State}. + +-spec generate(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +generate(State, RepoName) -> + {Repo, OrgName} = get_parent_repo_and_org_name(State, RepoName), + {Opts, _} = rebar_state:command_parsed_args(State), + KeyName = proplists:get_value(key_name, Opts, rebar3_hex_config:repos_key_name()), + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + PermOpts = proplists:get_all_values(permission, Opts), + Perms = rebar3_hex_key:convert_permissions(PermOpts, default_perms(OrgName)), + Key = generate_key(Config#{api_organization => OrgName}, KeyName, Perms), + rebar3_hex_io:say("~ts", [Key]), + {ok, State}. + +-spec list_org_keys(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +list_org_keys(State, RepoName) -> + {Repo, OrgName} = get_parent_repo_and_org_name(State, RepoName), + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, read), + case rebar3_hex_key:list(Config#{api_organization => OrgName}) of + ok -> + {ok, State}; + {error, #{<<"errors">> := Errors}} -> + ?RAISE({key_list, Errors}); + {error, #{<<"message">> := Message}} -> + ?RAISE({key_list, Message}); + Error -> + ?RAISE({key_list, Error}) + end. + +-spec revoke(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +revoke(State, RepoName) -> + {Repo, OrgName} = get_parent_repo_and_org_name(State, RepoName), + {Opts, _} = rebar_state:command_parsed_args(State), + KeyName = case proplists:get_value(key_name, Opts, undefined) of + undefined -> + ?RAISE(bad_command); + K -> + K + end, + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_key:revoke(Config#{api_organization => OrgName}, KeyName) of + ok -> + rebar3_hex_io:say("Key successfully revoked", []), + {ok, State}; + {error, #{<<"errors">> := Errors}} -> + ?RAISE({key_revoke, Errors}); + {error, #{<<"message">> := Message}} -> + ?RAISE({key_revoke, Message}); + Error -> + ?RAISE({key_revoke, Error}) + end. + +-spec revoke_all(rebar_state:t(), binary()) -> {ok, rebar_state:t()}. +revoke_all(State, RepoName) -> + {Repo, OrgName} = get_parent_repo_and_org_name(State, RepoName), + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_key:revoke_all(Config#{api_organization => OrgName}) of + ok -> + rebar3_hex_io:say("All keys successfully revoked", []), + {ok, State}; + {error, #{<<"errors">> := Errors}} -> + ?RAISE({key_revoke_all, Errors}); + {error, #{<<"message">> := Message}} -> + ?RAISE({key_revoke_all, Message}); + Error -> + ?RAISE({key_revoke_all, Error}) + end. + +-spec list_orgs(rebar_state:t()) -> {ok, rebar_state:t()}. +list_orgs(State) -> + Resources = rebar_state:resources(State), + #{repos := Repos} = rebar_resource_v2:find_resource_state(pkg, Resources), + Headers = ["Name", "URL", "Public Key"], + Orgs = lists:foldl( + fun(#{name := Name} = Repo, Acc) -> + case binary:split(Name, <<":">>) of + [_, _] -> + [Repo | Acc]; + _ -> + Acc + end + end, + [], + Repos + ), + + Rows = lists:map( + fun(Repo) -> + #{ + name := Name, + api_organization := Org, + repo_url := Url, + repo_public_key := PubKey + } = Repo, + [ + binary_to_list(Name), + org_url(Org, Url), + printable_public_key(PubKey) + ] + end, + Orgs + ), + rebar3_hex_results:print_table([Headers] ++ Rows), + {ok, State}. + +-spec default_perms(binary()) -> [map()]. +default_perms(OrgName) -> + [#{<<"domain">> => <<"repository">>, <<"resource">> => OrgName}]. + +-spec generate_key(map(), binary() | undefined, [map()]) -> binary(). +generate_key(HexConfig, KeyName, Perms) -> + case rebar3_hex_key:generate(HexConfig, KeyName, Perms) of + {ok, #{<<"secret">> := Secret}} -> + Secret; + {error, #{<<"errors">> := Errors}} -> + ?RAISE({generate_key, Errors}); + {error, #{<<"message">> := Message}} -> + ?RAISE({generate_key, Message}); + Error -> + ?RAISE({generate_key, Error}) + end. + +-spec printable_public_key(binary()) -> nonempty_string(). +printable_public_key(PubKey) -> + [Pem] = public_key:pem_decode(PubKey), + Public = public_key:pem_entry_decode(Pem), + Hash = crypto:hash(sha256, ssh_encode(Public)), + Encoded = string:substr(base64:encode_to_string(Hash), 1, 43), + "SHA256:" ++ Encoded. + + +-ifdef(OTP_RELEASE). % OTP >= 21 +-if(?OTP_RELEASE >= 24). +-spec ssh_encode(binary()) -> binary(). +ssh_encode(InData) -> + ssh_file:encode(InData, ssh2_pubkey). +-else. % OTP < 24 +-spec ssh_encode(binary()) -> binary(). +ssh_encode(InData) -> + public_key:ssh_encode(InData, ssh2_pubkey). +-endif. +-else. % OTP < 21 +-spec ssh_encode(binary()) -> binary(). +ssh_encode(InData) -> + public_key:ssh_encode(InData, ssh2_pubkey). +-endif. + +to_binary(Name) -> + rebar_utils:to_binary(Name). + +-spec org_url(binary(), binary()) -> [byte(), ...]. +org_url(Org, Url) -> binary_to_list(Url) ++ "/repos/" ++ binary_to_list(Org). + +get_parent_repo_and_org_name(State, RepoName) -> + case binary:split(RepoName, <<":">>) of + [Parent, Org] -> + case rebar3_hex_config:repo(State, Parent) of + {ok, Repo} -> + {Repo, Org}; + Error -> + ?RAISE({get_parent_repo_and_org_name, Error, RepoName}) + end; + [_] -> + ?RAISE(not_a_valid_repo_name) + end. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_owner.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_owner.erl new file mode 100644 index 0000000000000000000000000000000000000000..f3e1f07bfcb03962eae3a47362db578a8813e934 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_owner.erl @@ -0,0 +1,257 @@ +%% @doc `rebar3 hex owner' - Manage package owners +%% +%% Adds, removes or lists package owners. +%% +%% Package owners have full permissions to the package. They can publish and revert releases and even remove +%% other package owners. +%% +%%

Add a owner

+%% Adds an owner to package by specifying the package name and email or username of the new owner. +%% ``` +%% $ rebar3 hex owner add PACKAGE EMAIL_OR_USERNAME +%% ''' +%% +%%

Transfer ownership

+%% Like `rebar3 hex owner add` add but also removes all existing owners of the package. This task is required to use +%% when transferring ownership of the package to an organization. +%% +%% ``` +%% $ rebar3 hex owner transfer PACKAGE EMAIL_OR_USERNAME +%% ''' +%% +%%

Remove owner

+%% +%% Removes an owner to package by specifying the package name and email or username of the new owner. +%% +%% ``` +%% $ rebar3 hex owner remove PACKAGE EMAIL_OR_USERNAME +%% ''' +%% +%%

List owners

+%% Lists all owners of given package. +%% +%% ``` +%% $ rebar3 hex owner list PACKAGE +%% ''' +%% +%%

List owned packages

+%% Lists all packages owned by the current user. +%% +%% ``` +%% $ rebar3 hex owner list packages +%% ''' +%% +%%

Command line options

+%% +%%
    +%%
  • `--repo' - Specify the repository to work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must +%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Defaults to `hexpm'. +%%
  • +%%
  • `--level' - Specify the ownership level, either `full' or `maintainer'. Both ownership levels allow publishing +%% and retiring of packages. However, only an owner with `full' access may add, remove other owners, or transfer a +%% package to another owner. +%% Defaults to `full'. +%%
  • +%%
+ +-module(rebar3_hex_owner). + +-export([init/1, + do/1, + format_error/1]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, owner). +-define(DEPS, []). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex owner"}, + {short_desc, "Add, remove, transfer or list package owners"}, + {desc, support()}, + {opts, [rebar3_hex:repo_opt(), + {level, $l, "level", {string, "full"}, "Ownership level."}, + {transfer, $t, "transfer", {boolean, false}, "Transfer Package"} + ]}]), + + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + case rebar3_hex_config:repo(State) of + {ok, Repo} -> + {ok, handle_command(State, Repo)}; + {error, Reason} -> + ?RAISE(Reason) + end. + +handle_command(State, Repo) -> + case command_args(State) of + {"add", Package, UsernameOrEmail, Level, Transfer} -> + case valid_level(Level) of + true -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + add(Config, Package, UsernameOrEmail, Level, Transfer, State), + ok = rebar3_hex_io:say("Added ~ts to ~ts", [UsernameOrEmail, Package]), + State; + false -> + ?RAISE({error, "level must be one of full or maintainer"}) + end; + {"remove", Package, UsernameOrEmail} -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + remove(Config, Package, UsernameOrEmail, State), + ok = rebar3_hex_io:say("Removed ~ts to ~ts", [UsernameOrEmail, Package]), + State; + {"transfer", Package, UsernameOrEmail} -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + add(Config, Package, UsernameOrEmail, <<"full">>, true, State), + ok = rebar3_hex_io:say("Transferred ~ts to ~ts", [Package, UsernameOrEmail]), + State; + {"list", Package} -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, read), + list(Config, Package, State); + _Command -> + ?RAISE(bad_command) + end. + +command_args(State) -> + case get_args(rebar_state:command_args(State)) of + {"list", Package} -> + {"list", rebar_utils:to_binary(Package)}; + + {"add", Package, UserOrEmail} -> + {AllArgs, _} = rebar_state:command_parsed_args(State), + Level = proplists:get_value(level, AllArgs, "full"), + Transfer = proplists:get_value(transfer, AllArgs, false), + {"add", rebar_utils:to_binary(Package), rebar_utils:to_binary(UserOrEmail), rebar_utils:to_binary(Level), Transfer}; + + {Command, Package, UserOrEmail} -> + {Command, rebar_utils:to_binary(Package), rebar_utils:to_binary(UserOrEmail)}; + + BadCommand -> + BadCommand + end. + +get_args(["list", Package]) -> + {"list", Package}; +get_args(["list", Package| _Rest]) -> + {"list", Package}; +get_args([Task, Package, Username]) when Task =:= "transfer" -> + {Task, Package, Username}; +get_args([Task, Package, UserName | _Rest]) when Task =:= "add" orelse Task =:= "remove" -> + {Task, Package, UserName}; +get_args([Task, Package, UserName, "-r", _]) -> + {Task, Package, UserName}; +get_args(BadCommand) -> + BadCommand. + +support() -> + "Adds, removes or lists package owners.~n~n" + "Package owners have full permissions to the package. They can " + "publish and revert releases and even remove other package owners.~n~n" + "Supported command combinations: ~n~n" + " rebar3 hex owner add ~n~n" + " rebar3 hex owner add --level ~n~n" + " rebar3 hex owner list ~n~n" + " rebar3 hex owner remove ~n~n" + " rebar3 hex owner transfer ~n~n" + "Argument descriptions: ~n ~n" + " - a valid hex username or email address for a hex user~n~n" + " - a valid hex package name~n~n" + " - one of full or maintainer~n~n". + +%% @private +-spec format_error(any()) -> iolist(). +format_error(bad_command) -> + S = "Invalid command ~n~n", + support(), + io_lib:format(S, []); +format_error({validation_errors, Cmd, Package, User, Errors, Message}) -> + ErrorString = rebar3_hex_results:errors_to_string(Errors), + Action = verb_to_gerund(Cmd), + io_lib:format("Error ~ts ~ts as owner of package ~ts : ~ts~n\t~ts", [Action, User, Package, Message, ErrorString]); +format_error({error, Package, Reason}) -> + io_lib:format("Error listing owners of package ~ts: ~p", [Package, Reason]); +format_error({status, Status, Package}) -> + io_lib:format("Error listing owners of package ~ts: ~ts", + [Package, rebar3_hex_client:pretty_print_status(Status)]); +format_error({error, Package, UsernameOrEmail, Reason}) -> + io_lib:format("Error adding ~ts as owner of package ~ts: ~p", [UsernameOrEmail, Package, Reason]); +format_error({status, Status, Package, UsernameOrEmail}) -> + io_lib:format("Error adding ~ts as owner of package ~ts: ~ts", + [UsernameOrEmail, Package, rebar3_hex_client:pretty_print_status(Status)]); +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +valid_level(<<"full">>) -> true; +valid_level(<<"maintainer">>) -> true; +valid_level(_) -> false. + +add(HexConfig, Package, UsernameOrEmail, Level, Transfer, State) -> + case hex_api_package_owner:add(HexConfig, Package, UsernameOrEmail, Level, Transfer) of + {ok, {Code, _Headers, _Body}} when Code =:= 204 orelse Code =:= 201-> + State; + {ok, {422, _Headers, #{<<"errors">> := Errors, <<"message">> := Message}}} -> + ?RAISE({validation_errors, add, Package, UsernameOrEmail, Errors, Message}); + {ok, {Status, _Headers, _Body}} -> + ?RAISE({status, Status, Package, UsernameOrEmail}); + {error, Reason} -> + ?RAISE({error, Package, UsernameOrEmail, Reason}) + end. + +remove(HexConfig, Package, UsernameOrEmail, State) -> + case hex_api_package_owner:delete(HexConfig, Package, UsernameOrEmail) of + {ok, {204, _Headers, _Body}} -> + State; + {ok, {Status, _Headers, _Body}} -> + ?RAISE({status, Status, Package, UsernameOrEmail}); + {error, Reason} -> + ?RAISE({error, Package, UsernameOrEmail, Reason}) + end. + +list(HexConfig, Package, State) -> + case hex_api_package_owner:list(HexConfig, Package) of + {ok, {200, _Headers, List}} -> + Owners = [owner(Owner) || Owner <- List], + OwnersString = rebar_string:join(Owners, "\n"), + rebar3_hex_io:say("~s", [OwnersString]), + State; + {ok, {Status, _Headers, _Body}} -> + ?RAISE({status, Status, Package}); + {error, Reason} -> + ?RAISE({error, Package, Reason}) + end. + +owner(Owner) -> + Name0 = maps:get(<<"username">>, Owner, nil), + Email0 = maps:get(<<"email">>, Owner, nil), + {Name, Email} = case {Name0, Email0} of + _ when is_binary(Name0), is_binary(Email0) -> + {Name0, Email0}; + _ when is_binary(Name0) -> + {Name0, <<"unspecified">>}; + _ when is_binary(Email0) -> + {<<"unspecified">>, Email0}; + _ -> + {<<"unspecified">>, <<"unspecified">>} + end, + binary_to_list(Name) ++ " (" ++ binary_to_list(Email) ++ ")". + +verb_to_gerund(add) -> "adding"; +verb_to_gerund(remove) -> "removing"; +verb_to_gerund(list) -> "listing". diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_publish.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_publish.erl new file mode 100644 index 0000000000000000000000000000000000000000..74ecd4e4346e07e8799177fd2179b6053bee02e5 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_publish.erl @@ -0,0 +1,690 @@ +% @doc `rebar3 hex publish' - publish packages and docs +% +%% Builds and publishing a new version of a package and docs. +%% +%% ``` +%% $ rebar3 hex publish +%% ''' +%% +%% The current authenticated user will be the package owner. Only package owners can publish the package, +%% new owners can be added with the `rebar3 hex owner' task. +%% +%% Packages and documentation sizes are limited to 8mb compressed, and 64mb uncompressed. +%% By default this provider will build both a package tarball and docs tarball. Before attempting to +%% publish your package see the section below on documentation. +%% +%%

Publishing Documentation

+%% +%% By default rebar3_hex will not generate or publish docs. You must add a doc provider to your the hex config in either +%% your global `rebar.config' (i.e., `~/.config/rebar3/rebar.config') or locally in a projects `rebar.config'. +%% +%% We recommend using rebar3_ex_doc for publishing documentation along +%% with your package for a consistent format and style on hexpm. +%% +%% Example : +%% +%% ``` +%% {ex_doc, [ +%% {source_url, <<"https://github.com/namespace/your_app">>}, +%% {extras, [<<"README.md">>, <<"LICENSE">>]}, +%% {main, <<"readme">>} +%% ]}. +%% +%% {hex, [{doc, ex_doc}]}. +%% ''' +%% +%% Alternatively you can use the edoc provider that ships with rebar3 : +%% +%% ```erlang +%% {hex, [{doc, edoc}]}. +%% ''' +%% +%% The expected result of the task is the generated documentation located in the either `doc/' directory with an +%% `index.html' file or the directory you have configured the documentation provider to use. +%% +%% The documentation will be accessible at `https://hexdocs.pm/my_package/1.0.0', `https://hexdocs.pm/my_package' will always redirect to the latest published version. +%% +%% When a doc provider is configured documentation will be built and published automatically. To publish a package +%% without documentation run `mix rebar3 hex publish package' or to only publish documentation +%% run `rebar3 hex publish docs'. +%% +%%

Reverting a package

+%% +%% A new package can be reverted or updated within 24 hours of it's initial publish, a new version of an existing +%% package can be reverted or updated within one hour. Documentation have no limitations on when it can be updated. +%% +%% To update the package simply run the `rebar hex publish' task again. +%% To revert run `rebar3 hex publish --revert VERSION' or to only revert the documentation +%% run `rebar3 hex publish docs --revert VERSION'. +%% +%% If the last version is reverted, the package is removed. +%% +%%

Command line options

+%% +%%
    +%%
  • `-a', `--app' - Specify which app you want to publish without being prompted to choose. This +%% option is required when reverting a package, otherwise it's only useful in the context of an umbrella.
  • +%%
  • `-r', `--repo' - Specify the repository work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must +%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Defaults to `hexpm'. +%%
  • +%%
  • `-y', `--yes' - Publishes the package without any confirmation prompts
  • +%%
  • `--replace' - Allows overwriting an existing package version if it exists. Private packages can always be +%% overwritten, public packages can only be overwritten within one hour after they were initially +%% published.
  • +%%
  • `--revert VERSION' - Revert the given version. If the last version is reverted, the package is removed.
  • +%%
  • `--dry-run' - Performs a dry run of the publish task (i.e., it won't actually publish).
  • +%%
  • `--doc-dir' - The option may be used in case there is no doc provider available for your desired method of +%% generating documentation. Instead of finding and running a doc provider, rebar3_hex will simply gather +%% the files specified in the directory given to this option. Be sure your docs are up to date before publishing +%% with this option. +%%
  • +%%
+ + +-module(rebar3_hex_publish). + +-export([ init/1 + , do/1 + , format_error/1 + ]). + +-export([ + publish/4, + publish_package/4 + , publish_docs/4 + ]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, publish). +-define(DEPS, [{default, lock}]). + +%% =================================================================== +%% Public API +%% =================================================================== +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex publish"}, + {short_desc, "Publish a new version of your package and update the package"}, + {desc, support()}, + {opts, [rebar3_hex:repo_opt(), + {yes, $y, "yes", {boolean, false}, help(yes)}, + {app, $a, "app", {string, undefined}, help(app)}, + {doc_dir, undefined, "doc-dir", {string, undefined}, help(yes)}, + {dry_run, undefined, "dry-run", {boolean, false}, help(dry_run)}, + {replace, undefined, "replace", {boolean, false}, help(replace)}, + {revert, undefined, "revert", string, help(revert)}]}]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, term()}. +do(State) -> + case rebar3_hex:task_state(State) of + {ok, Task} -> + handle_task(Task); + {error, Reason} -> + ?RAISE(Reason) + end. + +%% TODO: Move me somewhere else +-spec format_error(any()) -> iolist(). +format_error(ErrList) when is_list(ErrList) -> + F = fun(Err, Acc) -> + ErrStr = format_error(Err), + Acc ++ " " ++ ErrStr ++ "\n" + end, + More = "\n Please see https://hex.pm/docs/rebar3_publish for more info.\n", + lists:foldl(F, "Validator Errors:\n", ErrList) ++ More; + +format_error(no_apps_found) -> + "publish can not continue, no apps were found."; + +%% Option errors +format_error({app_not_found, AppName}) -> + io_lib:format("App ~s specified with --app switch not found in project", [AppName]); +format_error({publish_package, app_switch_required}) -> + "--app required when publishing with the package argument in a umbrella"; +format_error({publish_docs, app_switch_required}) -> + "--app required when publishing with the docs argument in a umbrella"; +format_error({revert, app_switch_required}) -> + "--app required when reverting in a umbrella with multiple apps"; +format_error({required, repo}) -> + "publish requires a repo name argument to identify the repo to publish to"; +format_error({not_valid_repo, RepoName}) -> + io_lib:format("No configuration for repository ~ts found.", [RepoName]); + + +%% Validation errors +format_error({validation_errors, Errs}) -> + lists:map(fun(E) -> format_error(E) end, Errs); +format_error({has_contributors, AppName}) -> + Err = "~ts.app.src : deprecated field contributors found", + io_lib:format(Err, [AppName]); +format_error({has_maintainers, AppName}) -> + Err = "~ts.app.src : deprecated field maintainers found", + io_lib:format(Err, [AppName]); +format_error({no_description, AppName}) -> + Err = "~ts.app.src : missing or empty description property", + io_lib:format(Err, [AppName]); +format_error({no_license, AppName}) -> + Err = "~ts.app.src : missing or empty licenses property", + io_lib:format(Err, [AppName]); +format_error({invalid_licenses, Invalids, AppName}) -> + InvalidLicenses = string:join([ "'" ++ L ++ "'" || L <- Invalids], ", "), + Url = "See https://spdx.org/licenses/ for a list of valid license identifiers", + Err = "~ts.app.src : invalid license types detected - ~ts~n~5c~ts~n", + io_lib:format(Err, [AppName, InvalidLicenses, 32, Url]); +format_error({invalid_semver, {AppName, Version}}) -> + Err = "~ts.app.src : non-semantic version number \"~ts\" found", + io_lib:format(Err, [AppName, Version]); +format_error({invalid_semver_arg, Vsn}) -> + io_lib:format("The version argument provided \"~s\" is not a valid semantic version.", [Vsn]); +format_error({has_unstable_deps, Deps}) -> + MainMsg = "The following pre-release dependencies were found : ", + DepList = [io_lib:format("~s - ~s ", [Pkg, Ver]) || {Pkg, Ver} <- Deps], + Msg = [ + "In the future packages with pre-release dependencies will be considered unstable ", + "and will be prevented from being published. ", + "We recommend you upgrade your these dependencies as soon as possible" + ], + io_lib:format("~s~n~n~s~n~n~s~n", [MainMsg, DepList, Msg]); + +format_error({non_hex_deps, Excluded}) -> + Err = "Can not publish package because the following deps are not available" + ++ " in hex: ~s", + io_lib:format(Err, [string:join(Excluded, ", ")]); + +%% create package errors +format_error({create_package, {error, Err}}) when is_list(Err) -> + io_lib:format("Error creating package : ~ts", [Err]); + +format_error({create_package,{error,{non_hex_deps, _}} = Error}) -> + rebar3_hex_build:format_error({build_package, Error}); + +%% create docs errors +format_error({create_docs, {error, {doc_provider_not_found, PrvName}}}) -> + io_lib:format("The ~ts documentation provider could not be found", [PrvName]); +format_error({create_docs, {error, {doc_provider_failed, PrvName}}}) -> + io_lib:format("The ~ts documentation provider failed", [PrvName]); +format_error({create_docs, {error, missing_doc_index}}) -> + "No index.html file was found in expected docs directory.\n" + "If you provided --doc-dir option ensure that your docs were generated before running this task.\n" + "Otherwise, check that your preferred doc provider is properly generating docs outside the scope of this task.\n" + "Once resolved, run rebar3 hex publish docs to publish only the docs for this version of your package.\n"; + +%% publish package errors +format_error({publish_package, Name, Version, {error, #{<<"errors">> := Errors, <<"message">> := Message}}}) -> + ErrorString = errors_to_string(Errors), + io_lib:format("Failed to publish package ~ts - ~ts : ~ts~n\t~ts", [Name, Version, Message, ErrorString]); +format_error({publish_package, Name, Version, {error, #{<<"message">> := Message}}}) -> + io_lib:format("Failed to publish package ~ts - ~ts : ~ts", [Name, Version, Message]); + +%% publish docs errors +format_error({publish_docs, Name, Version, {error, #{<<"errors">> := Errors, <<"message">> := Message}}}) -> + ErrorString = errors_to_string(Errors), + io_lib:format("Failed to publish docs for ~ts - ~ts : ~ts~n\t~ts", [Name, Version, Message, ErrorString]); +format_error({publish_docs, Name, Version, {error, #{<<"message">> := Message}}}) -> + Reason = case Message of + <<"Page not found">> -> + io_lib:format("the ~ts package at version ~ts could not be found.", [Name, Version]); + Other -> + Other + end, + io_lib:format("Failed to publish docs for ~ts - ~ts : ~ts", [Name, Version, Reason]); + +%% revert package errors +format_error({revert_package, Name, Version, {error, #{<<"errors">> := Errors, <<"message">> := Message}}}) -> + ErrorString = errors_to_string(Errors), + io_lib:format("Failed to revert package ~ts - ~ts : ~ts~n\t~ts", [Name, Version, Message, ErrorString]); +format_error({revert_package, Name, Version, {error, #{<<"message">> := Message}}}) -> + io_lib:format("Failed to revert package ~ts - ~ts : ~ts", [Name, Version, Message]); + +%% revert docs errors +format_error({revert_docs, Name, Version, {error, #{<<"errors">> := Errors, <<"message">> := Message}}}) -> + ErrorString = errors_to_string(Errors), + io_lib:format("Failed to revert docs for ~ts - ~ts : ~ts~n\t~ts", [Name, Version, Message, ErrorString]); +format_error({revert_docs, Name, Version, {error, #{<<"message">> := Message}}}) -> + io_lib:format("Failed to revert docs for ~ts - ~ts : ~ts", [Name, Version, Message]); + + +%% TODO: Check if this is dead code +%% Server errors +format_error(undefined_server_error) -> + "Unknown server error"; +format_error({status, Status}) -> + rebar3_hex_client:pretty_print_status(Status); +format_error({status, Status, undefined_server_error}) -> + "Unknown server error: " ++ rebar3_hex_client:pretty_print_status(Status); +format_error({status, Status, Error}) -> + Message = maps:get(<<"message">>, Error, ""), + Errors = maps:get(<<"errors">>, Error, ""), + ErrorString = errors_to_string(Errors), + Data = [rebar3_hex_client:pretty_print_status(Status), Message, ErrorString], + io_lib:format("Status Code: ~s~nHex Error: ~s~n\t~s", Data); + +format_error(bad_command) -> + "Invalid arguments, expected one of:\n\n" + "rebar3 hex publish\n" + "rebar3 hex publish package\n" + "rebar3 hex publish docs\n"; + +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +%% =================================================================== +%% Private +%% =================================================================== + +%% =================================================================== +%% Publish package only operations +%% =================================================================== +handle_task(#{apps := []}) -> + ?RAISE(no_apps_found); + +handle_task(#{args := #{task := package, app := undefined}, multi_app := true}) -> + ?RAISE({publish_package, app_switch_required}); + +handle_task(#{args := #{task := package, revert := Vsn}, apps := [App]} = Task) -> + #{repo := Repo, state := State} = Task, + AppName = rebar_app_info:name(App), + revert_package(State, Repo, AppName, Vsn); + +handle_task(#{args := #{task := package}, apps := [App]} = Task) -> + maybe_warn_about_single_app_args(Task), + #{args := Args, repo := Repo, state := State} = Task, + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + rebar_api:info("package argument given, will not publish docs", []), + publish_package(State, HexConfig, App, Args); + +handle_task(#{args := #{task := package, app := AppName}, apps := Apps} = Task) -> + #{args := Args, repo := Repo, state := State} = Task, + case rebar3_hex_app:find(Apps, AppName) of + {error, app_not_found} -> + ?RAISE({app_not_found, AppName}); + {ok, App} -> + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + rebar_api:info("package argument given, will not publish docs", []), + publish_package(State, HexConfig, App, Args) + end, + {ok, State}; + +%% =================================================================== +%% Publish docs only operations +%% =================================================================== +handle_task(#{args := #{task := docs, app := undefined}, multi_app := true}) -> + ?RAISE({publish_docs, app_switch_required}); + +handle_task(#{args := #{task := docs, revert := Vsn}, apps := [App]} = Task) -> + #{repo := Repo, state := State} = Task, + AppName = rebar_app_info:name(App), + revert_docs(State, Repo, AppName, Vsn); + +handle_task(#{args := #{task := docs}, apps := [App]} = Task) -> + #{args := Args, repo := Repo, state := State} = Task, + rebar_api:info("docs argument given, will not publish package", []), + publish_docs(State, Repo, App, Args), + {ok, State}; + +handle_task(#{args := #{task := docs, app := AppName}, apps := Apps} = Task) -> + case rebar3_hex_app:find(Apps, AppName) of + {error, app_not_found} -> + ?RAISE({app_not_found, AppName}); + {ok, App} -> + #{args := Args, repo := Repo, state := State} = Task, + rebar_api:info("docs argument given, will not publish package", []), + publish_docs(State, Repo, App, Args), + {ok, State} + end; + +%% =================================================================== +%% Revert operations +%% =================================================================== +handle_task(#{args := #{revert := _, app := undefined}, multi_app := true}) -> + ?RAISE({revert, app_switch_required}); + +handle_task(#{args := #{revert := Vsn}, apps := [App]} = Task) -> + #{repo := Repo, state := State} = Task, + AppName = rebar_app_info:name(App), + revert_package(State, Repo, AppName, Vsn); + +handle_task(#{args := #{revert := Vsn, app := AppName}, apps := Apps} = Task) -> + #{repo := Repo, state := State} = Task, + case rebar3_hex_app:find(Apps, AppName) of + {error, app_not_found} -> + ?RAISE({app_not_found, AppName}); + {ok, _App} -> + revert_package(State, Repo, AppName, Vsn) + end; + +%% =================================================================== +%% Publish package and docs (the default path) +%% =================================================================== + +handle_task(#{args := #{task := undefined, app := undefined}, repo := Repo, state := State, apps := Apps} = Task) -> + #{args := Args} = Task, + maybe_warn_about_single_app_args(Task), + Selected = rebar3_hex_io:select_apps(Apps), + lists:foreach(fun(App) -> publish(State, Repo, App, Args) end, Selected), + {ok, State}; + +handle_task(#{args := #{task := undefined, app := AppName}, apps := Apps, multi_app := true} = Task) -> + case rebar3_hex_app:find(Apps, AppName) of + {error, app_not_found} -> + ?RAISE({app_not_found, AppName}); + {ok, App} -> + #{args := Args, repo := Repo, state := State} = Task, + publish(State, Repo, App, Args) + end; + +handle_task(_) -> + ?RAISE(bad_command). + +publish(State, Repo, App, Args) -> + maybe_warn_about_doc_config(State, Repo), + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case publish_package(State, HexConfig, App, Args) of + abort -> + {ok, State}; + _ -> + publish_docs(State, HexConfig, App, Args) + end. + + +%%% =================================================================== +%%% package publishing and related functions +%%% =================================================================== + +publish_package(State, Repo, App, Args) -> + assert_valid_app(State, App), + Package = create_package(State, App), + maybe_print_checkouts_warnings(App, Package), + print_package_info(Package, Repo), + maybe_say_coc(Repo), + MaybeCheckoutWarnings = maybe_checkout_warnings(Package), + case maybe_prompt(Args, "Proceed" ++ MaybeCheckoutWarnings ++ "?") of + proceed -> + HexOpts = hex_opts(Args), + #{tarball := Tarball} = Package, + case Args of + #{dry_run := true} -> + rebar_api:info("--dry-run enabled : will not publish package.", []), + {ok, State}; + _ -> + case rebar3_hex_client:publish(Repo, Tarball, HexOpts) of + {ok, _Res} -> + #{name := Name, version := Version} = Package, + rebar_api:info("Published ~ts ~ts", [Name, Version]), + {ok, State}; + Error -> + #{name := Name, version := Version} = Package, + ?RAISE({publish_package, Name, Version, Error}) + end + end; + abort -> + rebar3_hex_io:say("Goodbye..."), + abort + end. + +create_package(State, App) -> + case rebar3_hex_build:create_package(State, App) of + {ok, Package} -> + Package; + Err -> + ?RAISE({create_package, Err}) + end. + +print_package_info(Package, #{name := RepoName} = _Repo) -> + #{metadata := Meta, files := Files, deps := Deps, name := Name, version := Version} = Package, + rebar3_hex_io:say("Publishing ~ts ~ts to ~ts", [Name, Version, RepoName]), + rebar3_hex_io:say(" Description: ~ts", [rebar_utils:to_list(maps:get(<<"description">>, Meta, <<"">>))]), + rebar3_hex_io:say(" Dependencies:~n ~ts", [format_deps(Deps)]), + rebar3_hex_io:say(" Included files:~n ~ts", [string:join([F || {F, _} <- Files], "\n ")]), + rebar3_hex_io:say(" Licenses: ~ts", [format_licenses(maps:get(<<"licenses">>, Meta, []))]), + rebar3_hex_io:say(" Links:~n ~ts", [format_links(maps:get(<<"links">>, Meta, []))]), + rebar3_hex_io:say(" Build tools: ~ts", [format_build_tools(maps:get(<<"build_tools">>, Meta))]). + +format_build_tools(BuildTools) -> + string:join([io_lib:format("~ts", [Tool]) || Tool <- BuildTools], ", "). + +format_deps(Deps) -> + Res = [rebar_utils:to_list(<>) || {N, #{<<"requirement">> := V}} <- Deps], + string:join(Res, "\n "). + +format_licenses(Licenses) -> + string:join([rebar_utils:to_list(L) || L <- Licenses], ", "). + +format_links(Links) -> + Links1 = maps:to_list(Links), + LinksList = [lists:flatten([rebar_utils:to_list(Name), ": ", rebar_utils:to_list(Url)]) || {Name, Url} <- Links1], + string:join(LinksList, "\n "). + +%% if publishing to the public repo or to a private organization link to the code of conduct +maybe_say_coc(#{parent := <<"hexpm">>}) -> + rebar3_hex_io:say("Before publishing, please read Hex CoC: https://hex.pm/policies/codeofconduct", []); +maybe_say_coc(#{name := <<"hexpm">>}) -> + rebar3_hex_io:say("Be aware, you are publishing to the public Hexpm repository.", []), + rebar3_hex_io:say("Before publishing, please read Hex CoC: https://hex.pm/policies/codeofconduct", []); +maybe_say_coc(_) -> + ok. + +maybe_checkout_warnings(#{has_checkouts := false}) -> ""; +maybe_checkout_warnings(#{has_checkouts := true}) -> " (with warnings)". + +maybe_print_checkouts_warnings(_App, #{has_checkouts := false}) -> ok; +maybe_print_checkouts_warnings(App, #{has_checkouts := true}) -> + AppDir = rebar_app_info:dir(App), + Checkouts = filename:join(AppDir, "_checkouts"), + rebar_log:log(warn, "~p directory found; this might interfere with publishing", [Checkouts]). + +maybe_prompt(#{yes := true}, _Message) -> + proceed; + +maybe_prompt(_Args, Message) -> + case rebar3_hex_io:ask(Message, boolean, "Y") of + true -> + proceed; + _ -> + abort + end. + +maybe_warn_about_doc_config(State, Repo) -> + case rebar3_hex_build:doc_opts(State, Repo) of + undefined -> + Warning = "No doc provider configuration was found, therefore docs can not be published.~n~n" + "You may resolve this by adding a doc provider property to your projects hex config.~n~n" + "To configure rebar3_ex_doc as your doc provider (recommended but requires >= OTP 24) ~n~n" + "Add the following configuration to your rebar.config : ~n~n" + "{project_plugins, [rebar3_ex_doc]}.~n~n" + "{hex, [{doc, ex_doc}]}.~n~n" + "~s~n" + "~10.s~s~n" + "~10.s~s~n" + "~10.s~s~n~n" + "Alternatively if using OTP < 24 or you prefer edoc, add the following to your rebar.config :~n~n" + "{hex, [{doc, edoc}]}.~n~n" + "If you always intend to publish packages without docs and wish to silence this warning " + "you should use : ~n~nrebar3 hex publish package~n~n" + "Note : In version 7.1 this warning will be treated as an error~n", + rebar_api:warn(Warning, [ + "{ex_doc, [", + " ", + "{source_url, <<\"https://github.com/namespace/your_app\">>},", + " ", + "{extras, [<<\"README.md\">>, <<\"LICENSE.md\">>]},", + " ", + "{main, <<\"readme\">>}]}." + ] + ); + _ -> + ok + end. + +hex_opts(Opts) -> + lists:filter(fun({replace, _}) -> true; + ({_,_}) -> false + end, + maps:to_list(Opts)). + +%%% =================================================================== +%%% doc publishing and related functions +%%% =================================================================== + +publish_docs(State, Repo, App, Args) -> + case create_docs(State, Repo, App, Args) of + #{tarball := Tar, name := Name, version := Vsn} -> + case Args of + #{dry_run := true} -> + rebar_api:info("--dry-run enabled : will not publish docs.", []), + {ok, State}; + _ -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_client:publish_docs(Config, Name, Vsn, Tar) of + {ok, _} -> + rebar_api:info("Published docs for ~ts ~ts", [Name, Vsn]), + {ok, State}; + Reason -> + ?RAISE({publish_docs, Name, Vsn, Reason}) + end + end; + ok -> + {ok, State} + end. + +create_docs(State, Repo, App, Args) -> + case rebar3_hex_build:create_docs(State, Repo, App, Args) of + {ok, Docs} -> + Docs; + {error, no_doc_config} -> + rebar_api:warn("No documentation provider was configured, docs will not be generated.", []); + Err -> + ?RAISE({create_docs, Err}) + end. + +%%% =================================================================== +%%% package and doc reversion functions +%%% =================================================================== + +revert_package(State, Repo, AppName, Vsn) -> + BinAppName = rebar_utils:to_binary(AppName), + BinVsn = rebar_utils:to_binary(Vsn), + assert_valid_version_arg(BinVsn), + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_client:delete_release(HexConfig, BinAppName, BinVsn) of + {ok, _} -> + rebar_api:info("Successfully deleted package ~ts ~ts", [AppName, Vsn]), + Prompt = io_lib:format("Also delete tag v~ts?", [Vsn]), + case rebar3_hex_io:ask(Prompt, boolean, "N") of + true -> + rebar_utils:sh(io_lib:format("git tag -d v~ts", [Vsn]), []); + _ -> + {ok, State} + end; + Reason -> + ?RAISE({revert_package, BinAppName, BinVsn, Reason}) + end. + +revert_docs(State, Repo, AppName, Vsn) -> + BinAppName = rebar_utils:to_binary(AppName), + BinVsn = rebar_utils:to_binary(Vsn), + assert_valid_version_arg(BinVsn), + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_client:delete_docs(Config, BinAppName, BinVsn) of + {ok, _} -> + rebar_api:info("Successfully deleted docs for ~ts ~ts", [AppName, Vsn]), + {ok, State}; + Reason -> + ?RAISE({revert_docs, BinAppName, BinVsn, Reason}) + end. + +%% =================================================================== +%% General purpose helpers +%% =================================================================== + +assert_valid_app(State, App) -> + Name = rebar_app_info:name(App), + Version = rebar_app_info:original_vsn(App), + ResolvedVersion = rebar_utils:vcs_vsn(App, Version, State), + {application, _, AppDetails} = rebar3_hex_file:update_app_src(App, ResolvedVersion), + Deps = rebar_state:get(State, {locks, default}, []), + AppData = #{name => Name, version => ResolvedVersion, details => AppDetails, deps => Deps}, + case rebar3_hex_app:validate(AppData) of + ok -> + {ok, State}; + {error, #{warnings := Warnings, errors := Errors}} -> + lists:foreach(fun(W) -> rebar_log:log(warn, format_error(W), []) end, Warnings), + case Errors of + [] -> + {ok, State}; + Errs -> + ?RAISE({validation_errors, Errs}) + end + end. + +assert_valid_version_arg(Vsn) -> + case verl:parse(Vsn) of + {ok, _} -> + ok; + _ -> + ?RAISE({invalid_semver_arg, Vsn}) + end. + +errors_to_string(Value) when is_binary(Value) -> + Value; +errors_to_string(Map) when is_map(Map) -> + errors_to_string(maps:to_list(Map)); +errors_to_string({<<"inserted_at">>, E}) -> + lists:flatten(io_lib:format("Inserted At: ~s~n", [E])); +errors_to_string({<<"requirements">>, Rs}) -> + lists:flatten(["Requirements could not be computed\n", + [io_lib:format("~s\n~20.20c\n~s\n",[P,$-, R]) || {P, R} <- maps:to_list(Rs)]]); +errors_to_string({Key, Value}) -> + io_lib:format("~s: ~s", [Key, errors_to_string(Value)]); +errors_to_string(Errors) when is_list(Errors) -> + lists:flatten([io_lib:format("~s", [errors_to_string(Values)]) || Values <- Errors]). + +help(app) -> + "Specifies the app to use with the publish command, currently only utilized for publish and revert operations" + "Note that the app switch and value only have to be provided if you are publishing within an umbrella."; +help(dry_run) -> + "Generates docs (if configured) but does not publish the docs. Useful for inspecting docs before publishing."; +help(revert) -> + "Revert given version, if the last version is reverted the package is removed"; +help(replace) -> + "Allows overwriting an existing package version if it exists. Private " + "packages can always be overwritten, publicpackages can only be " + "overwritten within one hour after they were initially published."; +help(yes) -> + "Publishes the package without any confirmation prompts". + +maybe_warn_about_single_app_args(#{args := #{app := AppName}, apps := [_]}) when AppName =/= undefined -> + rebar_api:error("--app switch has no effect in single app projects", []); +maybe_warn_about_single_app_args(_) -> ok. + +support() -> + "Publishes a new version of a package with options to revert and replace existing packages~n~n" + "Supported command combinations:~n~n" + " rebar3 hex publish~n~n" + " rebar3 hex publish package~n~n" + " rebar3 hex publish --yes~n~n" + " rebar3 hex publish package~n~n" + " rebar3 hex publish docs~n~n" + " rebar3 hex publish --dry-run~n~n" + " rebar3 hex publish --repo ~n~n" + " rebar3 hex publish --repo --yes~n~n" + " rebar3 hex publish --revert ~n~n" + " rebar3 hex publish --revert --yes~n~n" + " rebar3 hex publish --revert --app ~n~n" + " rebar3 hex publish --revert --app --yes~n~n" + " rebar3 hex publish --replace~n~n" + " rebar3 hex publish --replace --yes~n~n" + "Argument descriptions:~n~n" + " - a valid repository, only required when multiple repositories are configured~n~n" + " - a valid version string, currently only utilized with --revert switch~n~n". + diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_results.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_results.erl new file mode 100644 index 0000000000000000000000000000000000000000..df25d974aabab5b0c59422d713b0e9809bd57523 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_results.erl @@ -0,0 +1,68 @@ +%% @private +-module(rebar3_hex_results). + +-export([errors_to_string/1, print_table/1]). + +-include("rebar3_hex.hrl"). + +errors_to_string(Value) when is_binary(Value) -> + Value; +errors_to_string(Map) when is_map(Map) -> + errors_to_string(maps:to_list(Map)); +errors_to_string({<<"inserted_at">>, E}) -> + lists:flatten(io_lib:format("Inserted At: ~s~n", [E])); +errors_to_string({<<"requirements">>, Rs}) -> + lists:flatten(["Requirements could not be computed\n", + [io_lib:format("~s\n~20.20c\n~s\n",[P,$-, R]) || {P, R} <- maps:to_list(Rs)]]); +errors_to_string({Key, Value}) -> + io_lib:format("~s: ~s", [Key, errors_to_string(Value)]); +errors_to_string(Errors) when is_list(Errors) -> + lists:flatten([io_lib:format("~s", [errors_to_string(Values)]) || Values <- Errors]). + +print_table(Rows) -> + Table = table(Rows), + io:fwrite(Table), + ok. + +underline_emphasis(Item) -> + io_lib:format("\e[1m\e[00m\e[4m~ts\e[24m", [Item]). + +% Returns a str, expects first row to be a header +table([Headers | Body]) -> + Headers1 = [H ++ "|" || H <- Headers], + [Headers2 | Body1] = align_rows([Headers1 | Body]), + Table = [pretty_header(Headers2), ""] ++ Body1, + lists:foldl(fun(Row, Acc) -> + Acc ++ [io_lib:fwrite("~s~n", [lists:flatten(Row)])] + end, + [], + Table). + +pretty_header(Header) -> + lists:map(fun(W) -> + [Value, Space] = rebar3_hex_io:str_split(W, "|"), + underline_emphasis(Value) ++ " " ++ Space end, + Header). + +align_rows(Rows) -> + WidestCells = widest_cells(Rows), + [align_cells(R, WidestCells) || R <- Rows]. + +align_cells(Row, WidestCells) -> + Padded = rpad_row(Row, length(WidestCells), ""), + [ string:left(Cell, Length + 2, $\s) + || {Cell, Length} <- lists:zip(Padded, WidestCells)]. + +widest_cells(Rows) -> + lists:foldl( fun(Row, Acc) -> + CellLengths = [length(C) || C <- Row ], + Widest = lists:max([length(Acc), length(CellLengths)]), + Padded = rpad_row(CellLengths, Widest, 0), + WidestPadded = rpad_row(Acc, Widest, 0), + [ lists:max([A, B]) || {A, B} <- lists:zip(Padded, WidestPadded)] + end, + [], + Rows). + +rpad_row(L, Length, Elem) -> + L ++ lists:duplicate(Length - length(L), Elem). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_retire.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_retire.erl new file mode 100644 index 0000000000000000000000000000000000000000..07b2277f3dc9fe1e057acd3d8df0ad7316fef115 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_retire.erl @@ -0,0 +1,141 @@ +%% @doc `rebar3 hex retire' - retire and unretire packages +%% +%% Retires a package version. +%% +%% ``` +%% $ rebar3 hex retire PACKAGE VERSION REASON --message +%% $ rebar3 hex retire PACKAGE VERSION --unretire +%% ''' +%% +%% Mark a package as retired when you no longer recommend it's usage. A retired package is still resolvable and usable +%% but it will be flagged as retired in the repository and a message will be displayed to users when they use the +%% package. +%% +%%

Retirement reasons

+%% +%%
    +%%
  • renamed - The package has been renamed, including the new package name in the message.
  • +%%
  • deprecated - The package has been deprecated, if there's a replacing package include it in the message
  • +%%
  • security - There are security issues with this package
  • +%%
  • invalid - The package is invalid, for example it does not compile correctly
  • +%%
  • other - Any other reason not included above, clarify the reason in the message
  • +%%
+%% +%%

Command line options

+%% +%%
    +%%
  • `--repo' - Specify the repository to work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must +%% be a fully qualified repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%%
  • +%%
+ +-module(rebar3_hex_retire). + +-export([init/1, + do/1, + format_error/1]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, retire). +-define(DEPS, []). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex retire some_pkg 0.3.0 invalid --message Clarifying message"}, + {short_desc, "Mark a package as deprecated."}, + {desc, ""}, + {opts, [ + {message, $m, "message", string, "Clarifying message for retirement"}, + rebar3_hex:repo_opt()]}]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, {?MODULE, rebar3_hex_config:repo_error()}}. +do(State) -> + case rebar3_hex_config:repo(State) of + {ok, Repo} -> + case rebar_state:command_args(State) of + [Pkg, Version, Reason|_] -> + {Opts, _} = rebar_state:command_parsed_args(State), + Message = rebar_utils:to_binary(get_required_or_raise(message, Opts)), + PkgName = rebar_utils:to_binary(Pkg), + VersionBin = rebar_utils:to_binary(Version), + ReasonBin = rebar_utils:to_binary(Reason), + MessageBin = rebar_utils:to_binary(Message), + retire(State, PkgName, VersionBin, Repo, ReasonBin, MessageBin); + _ -> + ?RAISE(bad_command) + end; + + {error, Reason} -> + ?RAISE(Reason) + end. + +get_required_or_raise(Key, Args) -> + case rebar3_hex:get_required(Key, Args) of + {error, Err} -> + ?RAISE(Err); + Res -> + Res + end. + +errors_to_string(Value) when is_binary(Value) -> + Value; +errors_to_string(Map) when is_map(Map) -> + errors_to_string(maps:to_list(Map)); +errors_to_string({<<"reason">> = Key, <<"is invalid">> = Value}) -> + ValidVals = "must be one of other, invalid, security, deprecated or renamed", + io_lib:format("~s: ~s - ~s", [Key, errors_to_string(Value), ValidVals]); +errors_to_string({Key, Value}) -> + io_lib:format("~s: ~s", [Key, errors_to_string(Value)]); +errors_to_string(Errors) when is_list(Errors) -> + lists:flatten([io_lib:format("~s", [errors_to_string(Values)]) || Values <- Errors]). + +%% @private +format_error({validation_errors, Errors, Message}) -> + ErrorString = errors_to_string(Errors), + io_lib:format("Failed to retire package: ~ts~n\t~ts", [Message, ErrorString]); +format_error({api_error, PkgName, Version, Reason}) -> + io_lib:format("Unable to delete package ~ts ~ts: ~ts", [PkgName, Version, Reason]); +format_error({required, pkg}) -> + "retire requires a package name argument to identify the package to delete"; +format_error({required, vsn}) -> + "retire requires a version number argument to identify the package to delete"; +format_error({required, reason}) -> + "retire requires a reason with value of either other, invalid, security, deprecated or renamed"; +format_error({required, message}) -> + "retire requires a message to clarify the reason for the retirement of the package"; +format_error(bad_command) -> + "Invalid arguments, expected one of:\n\n" + "rebar3 hex retire PACKAGE VERSION REASON --message MESSAGE\n"; +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +retire(State, PkgName, Version, Repo, RetireReason, RetireMessage) -> + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + Msg = #{<<"reason">> => RetireReason, + <<"message">> => RetireMessage}, + case hex_api_release:retire(HexConfig, PkgName, Version, Msg) of + {ok, {204, _Headers, _Body}} -> + rebar_api:info("Successfully retired package ~ts ~ts", [PkgName, Version]), + {ok, State}; + {ok, {422, _Headers, #{<<"errors">> := Errors, <<"message">> := Message}}} -> + ?RAISE({validation_errors, Errors, Message}); + {ok, {Code, _Headers, _Body}} -> + ?RAISE({api_error, PkgName, Version, rebar3_hex_client:pretty_print_status(Code)}); + {error, Reason} -> + ?RAISE({api_error, PkgName, Version, io_lib:format("~p", [Reason])}) + end. diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_search.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_search.erl new file mode 100644 index 0000000000000000000000000000000000000000..769f262ea245e1b3341848e602cab320110b25dd --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_search.erl @@ -0,0 +1,148 @@ +%% @doc `rebar3 hex search' - search for packages on hexpm. +%% +%% Displays packages matching the given search query. +%% +%% If you are authenticated it will additionally search all organizations you are member of. +%% +%% ``` +%% $ rebar3 hex search PACKAGE +%% ''' +%% +%%

Command line options

+%% +%%
    +%%
  • `--repo' - Specify the repository to work with. This option is required when you +%% have multiple repositories configured, including organizations. The argument must be a fully qualified repository +%% name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Defaults to `hexpm'. +%%
  • +%%
+-module(rebar3_hex_search). + +-export([init/1, + do/1, + format_error/1]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, search). +-define(DEPS, []). + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([ + {name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex search "}, + {short_desc, "Display packages matching the given search query"}, + {desc, ""}, + {opts, [{term, undefined, undefined, string, "Search term."}, + rebar3_hex:repo_opt()]} + ]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + {Args, _} = rebar_state:command_parsed_args(State), + Term = proplists:get_value(term, Args, ""), + Parents = rebar3_hex_config:parent_repos(State), + lists:foreach(fun(Repo) -> search(State, Repo, Term) end, Parents), + {ok, State}. + +search(State, Repo, Term) -> + HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, read), + case hex_api_package:search(HexConfig, rebar_utils:to_binary(Term), []) of + {ok, {200, _Headers, []}} -> + io:format("No Results~n"), + {ok, State}; + {ok, {200, _Headers, Packages}} -> + Header = ["Name", "Version", "Description", "URL"], + Rows = lists:map(fun(Package) -> + #{<<"name">> := Name, + <<"meta">> := #{<<"description">> := Description}, + <<"releases">> := Releases, + <<"html_url">> := Url + } = Package, + + Descrip = truncate_description(Description), + [binary_to_list(Name), + latest_stable(Releases), Descrip, unicode:characters_to_list(Url)] + + end, sort_by_downloads(Packages)), + ok = rebar3_hex_results:print_table([Header] ++ Rows), + {ok, State}; + {ok, {Status, _Headers, _Body}} -> + throw(?PRV_ERROR({status, Status})); + {error, Reason} -> + throw(?PRV_ERROR({error, Reason})) + end. + + +truncate_description(Description) -> + Descrip = string:sub_string( + string:strip( + string:strip( + unicode:characters_to_list(Description), both, $\n) + ), 1, 50), + Blist = binary:split(unicode:characters_to_binary(Descrip), <<"\n">>, [global]), + Slist = lists:map(fun(B) -> unicode:characters_to_list(B) end, Blist), + Dstr = string:join(Slist, ""), + case size(Description) of + N when N >= 50 -> + Dstr ++ "..."; + _ -> + Dstr + end. + +sort_by_downloads(Packages) -> + {Unused, Popular} = lists:partition(fun(P) -> maps:get(<<"downloads">>, P) == #{} end, Packages), + lists:sort(fun(#{<<"downloads">> := #{<<"all">> := A}}, + #{<<"downloads">> := #{<<"all">> := B}}) -> + A > B + end, + Popular) ++ Unused. + +latest_stable(Releases) -> + case gather_stable_releases(Releases) of + [] -> + ""; + [Latest | _Rest] -> + binary_to_list(maps:get(<<"version">>, Latest)) + end. + +gather_stable_releases(Releases) -> + version_sort(lists:filter(fun(#{<<"version">> := Ver}) -> + {ok, V} = verl:parse(Ver), + case V of + #{pre := []} -> + true; + _ -> + false + end + end, + Releases + )). + +version_sort(Releases) -> + lists:sort(fun(#{<<"version">> := A}, #{<<"version">> := B}) -> + At = list_to_tuple(binary:split(A, <<".">>, [global])), + Bt = list_to_tuple(binary:split(B, <<".">>, [global])), + At >= Bt + end, + Releases). + +%% @private +-spec format_error(any()) -> iolist(). +format_error({status, Status}) -> + io_lib:format("Error searching for packages: ~ts", + [rebar3_hex_client:pretty_print_status(Status)]); +format_error({error, Reason}) -> + io_lib:format("Error searching for packages: ~p", [Reason]); +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_user.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_user.erl new file mode 100644 index 0000000000000000000000000000000000000000..a661b93e1fd07d1478b07a21ac4890b958506dc2 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_user.erl @@ -0,0 +1,520 @@ +%% @doc `rebar3 hex user' - Hex user tasks. +%% +%%

Register a user

+%% +%% ``` +%% $ rebar3 hex user register +%% ''' +%% +%%

Print the current user

+%% +%% ``` +%% $ rebar3 hex user whoami +%% ''' +%% +%%

Authorize a new user

+%% +%% ``` +%% $ rebar3 hex user auth [--key-name KEY_NAME] +%% ''' +%% +%%

Deauthorize the user

+%% +%% Deauthorizes the user from the local machine by removing the API key from the Hex config. +%% +%% ``` +%% $ rebar3 hex user deauth +%% ''' +%% +%%

Generate user key

+%% +%% Generates an unencrypted API key for your account. Keys generated by this command will be owned by you and will +%% give access to your private resources, do not share this key with anyone. For keys that will be shared by +%% organization members use `rebar3 hex organization key' instead. By default this command sets the api:write +%% permission which allows write access to the API, it can be overridden with the --permission flag. +%% +%% ``` +%% $ rebar3 hex user key generate [--key-name KEY_NAME] [--permission PERMISSION] +%% ''' +%% +%%

Revoke key

+%% Removes given key from account. +%% The key can no longer be used to authenticate API requests. +%% +%% ``` +%% $ rebar3 hex user key revoke NAME KEY_NAME +%% ''' +%% +%% == Revoke all keys == +%% Revoke all keys from your account. +%% +%% ``` +%% $ rebar3 hex user key revoke --all +%% ''' +%% +%%

List keys

+%% Lists all keys associated with the organization. +%% +%% ``` +%% $ rebar3 hex user key list +%% ''' +%% +%%

Reset user account password

+%% +%% Starts the process for resetting account password. +%% +%% ``` +%% rebar3 hex user reset_password account +%% ''' +%% +%%

Reset local password

+%% +%% ``` +%% rebar3 hex user reset_password local +%% ''' +%% +%%

Command line options

+%% +%%
    +%%
  • +%% `--repo' - Specify the repository to work with. This option is required when +%% you have multiple repositories configured, including organizations. The argument must be a fully qualified +%% repository name (e.g, `hexpm', `hexpm:my_org', `my_own_hexpm'). +%% Default to `hexpm'. +%%
  • +%%
  • +%% `--message "MESSAGE"' - Required message (up to 140 characters) clarifying the retirement reason +%%
  • +%%
  • +%% `--key-name KEY_NAME' - By default Hex will base the key name on your machine's hostname and the organization +%% name, use this option to give your own name. +%%
  • +%%
  • +%% `--permission PERMISSION' - Sets the permissions on the key, this option can be given multiple times, +%% possible values are: +%%
      +%%
      +%%
    • `api:read' - API read access.
    • +%%
    • `api:write' - API write access.
    • +%%
    • `repository:ORGANIZATION_NAME' - Access to the repository (this is the default permission).
    • +%%
    • `repositories' - Access to repositories for all organizations you are member of.
    • +%%
    +%%
  • +%%
+ +-module(rebar3_hex_user). + +-export([init/1, + do/1, + format_error/1]). + +-export([encrypt_write_key/3, + decrypt_write_key/2]). + +-include("rebar3_hex.hrl"). + +-define(PROVIDER, user). +-define(DEPS, [{default, lock}]). + +%% =================================================================== +%% Public API +%% =================================================================== + +%% @private +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + Provider = providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, hex}, + {bare, true}, + {deps, ?DEPS}, + {example, "rebar3 hex user "}, + {short_desc, "Hex user tasks"}, + {desc, ""}, + {opts, [ + rebar3_hex:repo_opt(), + {all, $a, "all", boolean, "all."}, + {key_name, $k, "key-name", string, "key-name"}, + {permission, $p, "permission", list, "perms."} + ] + }]), + State1 = rebar_state:add_provider(State, Provider), + {ok, State1}. + +%% @private +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + case rebar3_hex:task_state(State) of + {ok, Task} -> + handle_task(Task); + {error, Reason} -> + ?RAISE(Reason) + end. + +%% @private +-spec format_error(any()) -> iolist(). +format_error({decrypt_write_key, no_write_key}) -> + "No write key found for user in this repository. " + "Be sure you have authenticated first with : rebar3 hex user auth"; + +format_error({whoami, Reason}) when is_binary(Reason) -> + io_lib:format("Fetching currently authenticated user failed: ~ts", [Reason]); +format_error({input_required, InputName}) -> + Str = io_lib:format("The task you are attempting to run requires a ~ts. ", [InputName]), + Str ++ io_lib:format("Try running this again and be sure to give a ~ts when prompted.", [InputName]); +format_error(bad_local_password) -> + "Failure to decrypt write key: bad local password"; +format_error({registration_failure, Errors}) when is_map(Errors) -> + Reason = rebar3_hex_client:pretty_print_errors(Errors), + io_lib:format("Registration of user failed: ~ts", [Reason]); +format_error({generate_key, Reason}) when is_binary(Reason) -> + io_lib:format("Failure generating authentication tokens: ~ts", [Reason]); +format_error({key_revoke, {error, #{<<"status">> := 404}}}) -> + "The key you tried to revoke was not found"; +format_error({key_revoke_all, {error, #{<<"message">> := Msg}}}) -> + io_lib:format("Error revoking all keys : ~ts", [Msg]); +format_error({key_list, {error, #{<<"message">> := Msg}}}) -> + io_lib:format("Error listing keys : ~ts", [Msg]); +format_error(passwords_do_not_match) -> + "Password confirmation failed. The passwords must match."; +format_error(local_password_too_big) -> + "Local passwords can not exceed 32 characters."; +format_error({reset_account_password, Reason}) when is_binary(Reason) -> + io_lib:format("Error reseting account password: ~ts", [Reason]); +format_error(not_authenticated) -> + "Not authenticated as any user currently for this repository"; +format_error(bad_command) -> + "Invalid arguments, expected one of:\n\n" + "rebar3 hex user register\n" + "rebar3 hex user auth\n" + "rebar3 hex user deauth\n" + "rebar3 hex user whoami\n" + "rebar3 hex key generate\n" + "rebar3 hex key revoke --key-name KEY_NAME\n" + "rebar3 hex key revoke --all\n" + "rebar3 hex key list\n" + "rebar3 hex key fetch --key-name KEY_NAME\n" + "rebar3 hex reset_password account\n" + "rebar3 hex reset_password local\n"; +format_error(Reason) -> + rebar3_hex_error:format_error(Reason). + +handle_task(#{args := #{task := register}} = Task) -> + #{repo := Repo, state := State} = Task, + rebar3_hex_io:say("By registering an account on Hex.pm you accept all our " + "policies and terms of service found at https://hex.pm/policies\n"), + Username = get_string_input("Username"), + Email = get_string_input("Email"), + Password = get_password(account), + rebar3_hex_io:say("Registering..."), + create_user(Username, Email, Password, Repo, State); + +handle_task(#{args := #{task := auth}} = Task) -> + #{repo := #{repo_name := RepoName} = Repo, state := State} = Task, + Username = get_string_input("Username"), + Password = get_password(account), + + Auth = base64:encode_to_string(<>), + RepoConfig0 = Repo#{api_key => rebar_utils:to_binary("Basic " ++ Auth)}, + + %% write key + WriteKeyName = api_key_name(), + WritePermissions = [#{<<"domain">> => <<"api">>}], + WriteKey = generate_key(RepoConfig0, WriteKeyName, WritePermissions), + + rebar3_hex_io:say("You have authenticated on Hex using your account password. However, " + "Hex requires you to have a local password that applies only to this machine for security " + "purposes. Please enter it."), + + + LocalPassword = get_password(local), + rebar3_hex_io:say("Generating keys..."), + + WriteKeyEncrypted = encrypt_write_key(Username, LocalPassword, WriteKey), + + %% read key + RepoConfig1 = Repo#{api_key => WriteKey}, + ReadKeyName = api_key_name("read"), + ReadPermissions = [#{<<"domain">> => <<"api">>, <<"resource">> => <<"read">>}], + ReadKey = generate_key(RepoConfig1, ReadKeyName, ReadPermissions), + + %% repo key + ReposKeyName = repos_key_name(), + ReposPermissions = [#{<<"domain">> => <<"repositories">>}], + ReposKey = generate_key(RepoConfig1, ReposKeyName, ReposPermissions), + + % By default a repositories key is created which gives user access to all repositories + % that they are granted access to server side. + rebar3_hex_config:update_auth_config(#{RepoName => #{ + username => Username, + write_key => WriteKeyEncrypted, + read_key => ReadKey, + repo_key => ReposKey}}, State), + rebar3_hex_io:say("You are now ready to interact with your hex repositories."), + {ok, State}; + +handle_task(#{args := #{task := deauth}} = Task) -> + #{repo := Repo, state := State} = Task, + case Repo of + #{username := Username, name := RepoName} -> + rebar3_hex_config:update_auth_config(#{RepoName => #{}}, State), + rebar3_hex_io:say("User `~s` removed from the local machine. " + "To authenticate again, run `rebar3 hex user auth` " + "or create a new user with `rebar3 hex user register`", [Username]), + {ok, State}; + _ -> + rebar3_hex_io:say("Not authenticated as any user currently for this repository"), + {ok, State} + end; + +handle_task(#{args := #{task := reset_password, account := true}} = Task) -> + #{repo := Repo, state := State} = Task, + User = get_string_input("Username or Email"), + case rebar3_hex_client:reset_password(Repo, rebar_utils:to_binary(User)) of + {ok, _} -> + rebar3_hex_io:say("Email with reset link sent", []), + {ok, State}; + {error, #{<<"message">> := Message}} -> + ?RAISE({reset_account_password, Message}); + Error -> + ?RAISE({reset_account_password, Error}) + end; + +%% TODO: Write a test +handle_task(#{args := #{task := reset_password, local := true}} = Task) -> + #{repo := Repo, state := State} = Task, + case Repo of + #{username := Username, write_key := EncryptedWriteKey, read_key := ReadKey, repo_key := ReposKey} -> + DecryptedWriteKey = decrypt_write_key(Username, EncryptedWriteKey), + LocalPassword = get_password(new_local), + NewEncryptedWriteKey = encrypt_write_key(Username, LocalPassword, DecryptedWriteKey), + rebar3_hex_config:update_auth_config(#{?DEFAULT_HEX_REPO => #{ + username => Username, + write_key => NewEncryptedWriteKey, + read_key => ReadKey, + repo_key => ReposKey}}, State), + + {ok, State}; + _ -> + rebar3_hex_io:say("Not authenticated as any user currently for this repository"), + {ok, State} + end; + +handle_task(#{args := #{task := whoami}} = Task) -> + #{repo := Repo, state := State} = Task, + whoami(Repo, State), + {ok, State}; + +handle_task(#{args := #{task := key, generate := true} = Args} = Task) -> + #{raw_opts := Opts, repo := Repo, state := State} = Task, + KeyName = maps:get(key_name, Args, undefined), + Username = get_string_input("Username"), + Password = get_password(account), + Auth = base64:encode_to_string(<>), + Config = Repo#{api_key => rebar_utils:to_binary("Basic " ++ Auth)}, + PermOpts = proplists:get_all_values(permission, Opts), + Perms = rebar3_hex_key:convert_permissions(PermOpts, [#{<<"domain">> => <<"api">>}]), + _ = generate_key(Config, KeyName, Perms), + rebar3_hex_io:say("Key successfully created", []), + {ok, State}; + +handle_task(#{args := #{task := key, revoke := true, all := true}} = Task) -> + #{repo := Repo, state := State} = Task, + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_key:revoke_all(Config) of + ok -> + rebar3_hex_io:say("All keys successfully revoked", []), + {ok, State}; + Error -> + ?RAISE({key_revoke_all, Error}) + end; + +handle_task(#{args := #{task := key, revoke := true, key_name := KeyName}} = Task) -> + #{repo := Repo, state := State} = Task, + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, write), + case rebar3_hex_key:revoke(Config, KeyName) of + ok -> + rebar3_hex_io:say("Key successfully revoked", []), + {ok, State}; + Error -> + ?RAISE({key_revoke, Error}) + end; + +handle_task(#{repo := Repo, state := State, args := #{task := key, list := true}}) -> + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, read), + case rebar3_hex_key:list(Config) of + ok -> + {ok, State}; + Error -> + ?RAISE({key_list, Error}) + end; + +handle_task(#{args := #{task := key, fetch := true, key_name := KeyName}} = Task) -> + #{repo := Repo, state := State} = Task, + Config = rebar3_hex_config:get_hex_config(?MODULE, Repo, read), + case rebar3_hex_key:fetch(Config, KeyName) of + ok -> + {ok, State}; + Error -> + ?RAISE({key_list, Error}) + end; + +handle_task(_) -> + ?RAISE(bad_command). + +whoami(#{name := Name} = Repo, State) -> + case maps:get(read_key, Repo, undefined) of + undefined -> + ?RAISE(not_authenticated); + ReadKey -> + case rebar3_hex_client:me(Repo#{api_key => ReadKey}) of + {ok, #{<<"username">> := UserName} = Res} -> + Header = ["Repo", "User Name", "Full Name", "Email"], + FullName = maps:get(<<"full_name">>, Res, <<"private">>), + Email = maps:get(<<"email">>, Res, <<"private">>), + Body = [binary_to_list(Name), binary_to_list(UserName), binary_to_list(FullName), binary_to_list(Email)], + ok = rebar3_hex_results:print_table([Header] ++ [Body]), + {ok, State}; + {error, #{<<"message">> := Message}} -> + ?RAISE({whoami, Message}); + Err -> + ?RAISE({whoami, Err}) + end + end. + +get_string_input(Prompt) -> + MaxRetries = 3, + do_get_string_input(Prompt, MaxRetries). + +do_get_string_input(Prompt, 0) -> + ?RAISE({input_required, Prompt}); + +do_get_string_input(Prompt, MaxRetries) -> + case rebar3_hex_io:ask(Prompt ++ ":", string, "") of + no_data -> + rebar_api:warn("A ~ts is required for this task, please try again.", [Prompt]), + do_get_string_input(Prompt, MaxRetries - 1); + Username -> + rebar_utils:to_binary(Username) + end. + +local_password_check(Pw) -> + byte_size(Pw) < 32 orelse "Local passwords can not be greater than 32 characters, please try again". + +get_password(account) -> + get_password(<<"Account">>, fun(_) -> true end); + +get_password(new_local) -> + get_password(<<"New local">>, fun(Pw) -> local_password_check(Pw) end); + +get_password(local) -> + get_password(<<"Local">>, fun(Pw) -> local_password_check(Pw) end). + +get_password(Type, Fun) when is_binary(Type) -> + MaxRetries = 3, + do_get_password(Type, Fun, MaxRetries). + +do_get_password(_, _, 0) -> + ?RAISE(passwords_do_not_match); + +do_get_password(Type, Fun, MaxRetries) -> + Rest = <<" Password: ">>, + Password = rebar3_hex_io:get_password(<>), + case Fun(Password) of + true -> + confirm_password(Type, Fun, Password, MaxRetries); + Err -> + rebar_api:warn(Err, []), + do_get_password(Type, Fun, MaxRetries - 1) + end. + +confirm_password(Type, Fun, ExpectedPw, MaxRetries) -> + Rest = <<" Password (confirm): ">>, + case rebar3_hex_io:get_password(<>) of + Pw when Pw =:= ExpectedPw -> + Pw; + _ -> + rebar_api:warn("Passwords do not match, please try again", []), + do_get_password(Type, Fun, MaxRetries - 1) + end. + +create_user(Username, Email, Password, Repo, State) -> + case rebar3_hex_client:create_user(Repo, Username, Password, Email) of + {ok, _} -> + rebar3_hex_io:say("You are required to confirm your email to access your account, " + "a confirmation email has been sent to ~s", [Email]), + rebar3_hex_io:say("Then run `rebar3 hex auth -r ~ts` to create and configure api tokens locally.", + [maps:get(repo_name, Repo)]), + {ok, State}; + {error, #{<<"errors">> := Errors}} -> + ?RAISE({registration_failure, Errors}); + Error -> + ?RAISE({registration_failure, Error}) + end. + +%% @private +encrypt_write_key(Username, LocalPassword, WriteKey) -> + rebar3_hex_config:encrypt_write_key(Username, LocalPassword, WriteKey). + +%% @private +%-spec decrypt_write_key(binary(), {binary(), {binary(), binary()}} | undefined) -> binary(). +decrypt_write_key(_Username, undefined) -> + {decrypt_write_key, no_write_key}; +decrypt_write_key(Username, Key) -> + MaxRetries = 2, + LocalPassword = rebar3_hex_io:get_password(<<"Local Password: ">>), + decrypt_write_key(Username, LocalPassword, Key, MaxRetries). + + +-ifdef(POST_OTP_22). +decrypt_write_key(_, _, _, 0) -> + ?RAISE(bad_local_password); + +decrypt_write_key(Username, LocalPassword, Key, MaxRetries) -> + case rebar3_hex_config:decrypt_write_key(Username, LocalPassword, Key) of + error -> + rebar_api:warn("Sorry, try again.", []), + LocalPassword1 = rebar3_hex_io:get_password(<<"Local Password: ">>), + decrypt_write_key(Username, LocalPassword1, Key, MaxRetries - 1); + Result -> + Result + end. +-else. +decrypt_write_key(_, _, _, 0) -> + ?RAISE(bad_local_password); + +decrypt_write_key(Username, LocalPassword, Key, MaxRetries) -> + case rebar3_hex_config:decrypt_write_key(Username, LocalPassword, Key) of + error -> + rebar_api:warn("Sorry, try again.", []), + LocalPassword1 = rebar3_hex_io:get_password(<<"Local Password: ">>), + decrypt_write_key(Username, LocalPassword1, Key, MaxRetries - 1); + Result -> + Result + end. +-endif. + +generate_key(HexConfig, KeyName, Perms) -> + case rebar3_hex_key:generate(HexConfig, KeyName, Perms) of + {ok, #{<<"secret">> := Secret}} -> + Secret; + {error, #{<<"message">> := Message}} -> + ?RAISE({generate_key, Message}); + Error -> + ?RAISE({generate_key, Error}) + end. + +hostname() -> + {ok, Name} = inet:gethostname(), + Name. + +api_key_name() -> + rebar_utils:to_binary(hostname()). + +api_key_name(Postfix) -> + rebar_utils:to_binary([hostname(), "-api-", Postfix]). + +repos_key_name() -> + rebar_utils:to_binary([hostname(), "-repositories"]). + + diff --git a/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_version.erl b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_version.erl new file mode 100644 index 0000000000000000000000000000000000000000..64c3cd758dba3ae0937126d4c609b482e97a51a7 --- /dev/null +++ b/deps/eini/_build/default/plugins/rebar3_hex/src/rebar3_hex_version.erl @@ -0,0 +1,31 @@ +%% @private +%%% =================================================================== +%%% Version utils +%%% =================================================================== +-module(rebar3_hex_version). + +-export([parse/1, increment/2, format/1]). + +-type increment_type() :: patch | minor | major. + +-spec parse(string() | binary()) -> {ok, verl:version_t()} | {error, term()}. +parse(Version) when is_list(Version) -> + parse(rebar_utils:to_binary(Version)); +parse(Version) when is_binary(Version) -> + verl:parse(Version). + +-spec increment(increment_type(), verl:version_t()) -> verl:version_t(). +increment(patch, #{major := Maj, minor := Min, patch := Patch} = Version) -> + Version#{major => Maj, minor => Min, patch => Patch + 1}; +increment(minor, #{major := Maj, minor := Min} = Version) -> + Version#{major => Maj, minor => Min + 1, patch => 0}; +increment(major, #{major := Maj} = Version) -> + Version#{major => Maj + 1, minor => 0, patch => 0}. + +-spec format(verl:version_t()) -> binary(). +format(#{major := Maj, minor := Min, patch := Patch}) -> + MajBin = integer_to_binary(Maj), + MinBin = integer_to_binary(Min), + PatchBin = integer_to_binary(Patch), + DotBin = <<".">>, + <>. diff --git a/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag new file mode 100644 index 0000000000000000000000000000000000000000..d15a66a13195ecb98b5b80bd9f6f86b177b27fa3 Binary files /dev/null and b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag differ diff --git a/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_xrl/source.dag b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_xrl/source.dag new file mode 100644 index 0000000000000000000000000000000000000000..e80fc8c6a312819b3a1d9c8ed1bca7c7625a2f62 Binary files /dev/null and b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_xrl/source.dag differ diff --git a/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_yrl/source.dag b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_yrl/source.dag new file mode 100644 index 0000000000000000000000000000000000000000..37b2f43ea6a3bfa35fd757734512803cdf77022e Binary files /dev/null and b/deps/eini/_build/prod/lib/.rebar3/rebar_compiler_yrl/source.dag differ diff --git a/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_erl/source_apps.dag b/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_erl/source_apps.dag new file mode 100644 index 0000000000000000000000000000000000000000..36817c1f5e36ce70be5e5671947838d65c0d6f00 Binary files /dev/null and b/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_erl/source_apps.dag differ diff --git a/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_xrl/source_apps.dag b/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_xrl/source_apps.dag new file mode 100644 index 0000000000000000000000000000000000000000..8afffb4e17de43417094ee38cd8529b924e5bdb7 Binary files /dev/null and b/deps/eini/_build/prod/plugins/.rebar3/rebar_compiler_xrl/source_apps.dag differ diff --git a/deps/phoenix_live_view/.formatter.exs b/deps/phoenix_live_view/.formatter.exs new file mode 100644 index 0000000000000000000000000000000000000000..0b6f5c2e737aa9c726d04d20036ecc5b87f9545e --- /dev/null +++ b/deps/phoenix_live_view/.formatter.exs @@ -0,0 +1,5 @@ +[ + import_deps: [:phoenix], + plugins: [Phoenix.LiveView.HTMLFormatter], + inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/deps/phoenix_live_view/.hex b/deps/phoenix_live_view/.hex new file mode 100644 index 0000000000000000000000000000000000000000..717f6f5c9d08fdc116dfae10148ac92e87b51014 Binary files /dev/null and b/deps/phoenix_live_view/.hex differ diff --git a/deps/phoenix_live_view/CHANGELOG.md b/deps/phoenix_live_view/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..3df6cf66b2d1d2240457a9c9b5a7484af8e987a7 --- /dev/null +++ b/deps/phoenix_live_view/CHANGELOG.md @@ -0,0 +1,595 @@ +# Changelog for v1.1 + +## Quick update guide + +When updating from LiveView 1.0, you can also use [igniter](https://hexdocs.pm/igniter) to perform the following changes for you: + +```bash +# Prior to / without running `mix deps.update` +mix igniter.upgrade phoenix_live_view + +# Or if you have previously run `mix deps.update phoenix_live_view` or are upgrading from a release candidate. +mix igniter.apply_upgrades phoenix_live_view:1.0.0:1.1.0 +``` + +Here is a quick summary of the changes necessary to upgrade to LiveView v1.1: + +1. In your `mix.exs`, update `phoenix_live_view` to latest and add `lazy_html` as a dependency: + + ```elixir + {:phoenix_live_view, "~> 1.1"}, + {:lazy_html, ">= 0.0.0", only: :test}, + ``` + + Note you may remove `floki` as a dependency if you don't use it anywhere. + +2. Still in your `mix.exs`, prepend `:phoenix_live_view` to your list of compilers inside `def project`, such as: + + ```elixir + compilers: [:phoenix_live_view] ++ Mix.compilers(), + ``` + +3. (optional) In your `config/dev.exs`, find `debug_heex_annotations`, and also add `debug_attributes` for improved annotations: + + ```elixir + config :phoenix_live_view, + debug_heex_annotations: true, + debug_attributes: true, + enable_expensive_runtime_checks: true + ``` + +4. (optional) To enable colocated hooks, you must update `esbuild` with `mix deps.update esbuild` and then update your `config/config.exs` accordingly. In particular, append `--alias:@=.` to the `args` list and pass a list of paths to the `"NODE_PATH"` env var, as shown below: + + ```elixir + your_app_name: [ + args: + ~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.), + env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}, + ``` + +## Colocated hooks + +LiveView v1.1 introduces colocated hooks to allow writing the hook's JavaScript code in the same file as your regular component code. + +A colocated hook is defined by placing the special `:type` attribute on a ` + """ +end +``` + +Important: LiveView now supports the `phx-hook` attribute to start with a dot (`.PhoneNumber` above) for namespacing. Any hook name starting with a dot is prefixed at compile time with the module name of the component. If you named your hooks with a leading dot in the past, you'll need to adjust this for your hooks to work properly on LiveView v1.1. + +Colocated hooks are extracted to a `phoenix-colocated` folder inside your `_build/$MIX_ENV` directory (`Mix.Project.build_path()`). See the quick update section at the top of the changelog on how to adjust your `esbuild` configuration to handle this. With everything configured, you can import your colocated hooks inside of your `app.js` like this: + +```diff +... + import {LiveSocket} from "phoenix_live_view" ++ import {hooks as colocatedHooks} from "phoenix-colocated/my_app" + import topbar from "../vendor/topbar" +... + const liveSocket = new LiveSocket("/live", Socket, { + longPollFallbackMs: 2500, + params: {_csrf_token: csrfToken}, ++ hooks: {...colocatedHooks} + }) +``` + +The `phoenix-colocated` folder has subfolders for each application that uses colocated hooks, therefore you'll need to adjust the `my_app` part of the import depending on the name of your project (defined in your `mix.exs`). You can read more about colocated hooks in the module documentation of `Phoenix.LiveView.ColocatedHook`. There's also a more generalized version for colocated JavaScript, see the documentation for `Phoenix.LiveView.ColocatedJS`. + +We're planning to make the private `Phoenix.Component.MacroComponent` API that we use for those features public in a future release. + +Note: Colocated hooks require Phoenix 1.8+. + +> #### Compilation order {: .info} +> +> Colocated hooks are only written when the corresponding component is compiled. +> Therefore, whenever you need to access a colocated hook, you need to ensure +> `mix compile` runs first. This automatically happens in development. +> +> If you have a custom mix alias, instead of +> +> ``` +> release: ["assets.deploy", "release"] +> ``` +> +> do +> +> ``` +> release: ["compile", "assets.deploy", "release"] +> ``` +> +> to ensure that all colocated hooks are extracted before esbuild or any other bundler runs. +> +> If you have a `Dockerfile` based on `mix phx.gen.release --docker`, ensure that `mix compile` runs before `mix assets.deploy`. + +## Change tracking in comprehensions + +One pitfall when rendering collections in LiveView was that they were not change tracked. If you had code like this: + +```heex +
    +
  • {item.name}
  • +
+``` + +When changing `@items`, all elements were re-sent over the wire. LiveView still optimized the static and dynamic parts of the template, but if you had 100 items in your list and only changed a single one (also applies to append, prepend, etc.), LiveView still sent the dynamic parts of all items. + +To improve this, LiveView prior to v1.1 had two solutions: + +1. Use streams. Streams are not kept in memory on the server and if you `stream_insert` a single item, only that item is sent over the wire. But because the server does not keep any state for streams, this also means that if you update an item in a stream, all the dynamic parts of the updated item are sent again. +2. Use a LiveComponent for each entry. LiveComponents perform change tracking on their own assigns. So when you update a single item, LiveView only sends a list of component IDs and the changed parts for that item. + +So LiveComponents allow for more granular diffs and also a more declarative approach than streams, but require more memory on the server. Thus, when memory usage is a concern, especially for very large collections, streams should be your first choice. Another downside of LiveComponents is that they require you to write a whole separate module just to get an optimized diff. + +LiveView v1.1 changes how comprehensions are handled to enable change tracking by default. If you only change a single item in a list, only its changes are sent. To do this, LiveView uses an element's index to track changes. This means that if you prepend an entry in a list, all items after the new one will be sent again. To improve this even further, LiveView v1.1 introduces a new `:key` attribute that can be used with `:for`: + +```heex +
    +
  • {item.name}
  • +
+``` + +LiveView uses the key to efficiently calculate a diff that only contains the new indexes of moved items. Change tracking in comprehensions comes with a slightly increased memory footprint. If memory is a concern, you should think about using streams. + +## Types for public interfaces + +LiveView v1.1 adds official types to the JavaScript client. This allows IntelliSense to work in editors that support it and is a massive improvement to the user experience when writing JavaScript hooks. If you're not using TypeScript, you can also add the necessary JSDoc hints to your hook definitions, assuming your editor supports them. + +Example when defining a hook object that is meant to be passed to the `LiveSocket` constructor: + +```javascript +/** + * @type {import("phoenix_live_view").HooksOptions} + */ +let Hooks = {} +Hooks.PhoneNumber = { + mounted() { + this.el.addEventListener("input", e => { + let match = this.el.value.replace(/\D/g, "").match(/^(\d{3})(\d{3})(\d{4})$/) + if(match) { + this.el.value = `${match[1]}-${match[2]}-${match[3]}` + } + }) + } +} + +let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, ...}) +... +``` + +Example when defining a hook on its own: + +```javascript +/** + * @type {import("phoenix_live_view").Hook} + */ +Hooks.InfiniteScroll = { + page() { return this.el.dataset.page }, + mounted(){ + this.pending = this.page() + window.addEventListener("scroll", e => { + if(this.pending == this.page() && scrollAt() > 90){ + this.pending = this.page() + 1 + this.pushEvent("load-more", {}) + } + }) + }, + updated(){ this.pending = this.page() } +} +``` + +Also, hooks can now be defined as a subclass of `ViewHook`, if you prefer [native classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class): + +```javascript +import { LiveSocket, ViewHook } from "phoenix_live_view" + +class MyHook extends ViewHook { + mounted() { + ... + } +} + +let liveSocket = new LiveSocket(..., { + hooks: { + MyHook + } +}) +``` + +Using [`@types/phoenix_live_view`](https://www.npmjs.com/package/@types/phoenix_live_view) (not maintained by the Phoenix team) is no longer necessary. + +## `<.portal>` component + +When designing reusable HTML components for UI elements like tooltips or dialogs, it is sometimes necessary to render a part of a component's template outside of the regular DOM hierarchy of that component, for example to prevent clipping due to CSS rules like `overflow: hidden` that are not controlled by the component itself. Modern browser APIs for rendering elements in [the top layer](https://developer.mozilla.org/en-US/docs/Glossary/Top_layer) can help in many cases, but if you cannot use those for whatever reasons, LiveView previously did not have a solution to solve that problem. In LiveView v1.1, we introduce a new `Phoenix.Component.portal/1` component: + +```heex +<%!-- in some nested LiveView or component --%> +<.portal id="my-element" target="body"> + <%!-- any content here will be teleported into the body tag --%> + +``` + +Any element can be teleported, even LiveComponents and nested LiveViews, and any `phx-*` events from inside a portal will still be handled by the correct LiveView. This is similar to [`` in Vue.js](https://vuejs.org/guide/built-ins/teleport) or [`createPortal` in React](https://react.dev/reference/react-dom/createPortal). + +As a demo, we created [an example for implementing tooltips using `Phoenix.Component.portal`](https://gist.github.com/SteffenDE/f599405c7c2eddbb14723ed4f3b7213f) as a single-file Elixir script. When saved as `portal.exs`, you can execute it as `elixir portal.exs` and visit `http://localhost:5001` in your browser. + +## `JS.ignore_attributes` + +Sometimes it is useful to prevent some attributes from being patched by LiveView. One example where this frequently came up is when using a native `` or `
` element that is controlled by the `open` attribute, which is special in that it is actually set (and removed) by the browser. Previously, LiveView would remove those attributes on update and required additional patching, now you can simply call `JS.ignore_attributes` in the `phx-mounted` attribute: + +```heex +
+ ... + ... +
+``` + +## Moving from Floki to LazyHTML + +LiveView v1.1 moves to [LazyHTML](https://hexdocs.pm/lazy_html/) as the HTML engine used by `LiveViewTest`. LazyHTML is based on [lexbor](https://github.com/lexbor/lexbor) and allows the use of modern CSS selector features, like `:is()`, `:has()`, etc. to target elements. Lexbor's stated goal is to create output that "should match that of modern browsers, meeting industry specifications". + +This is a mostly backwards compatible change. The only way in which this affects LiveView projects is when using Floki specific selectors (`fl-contains`, `fl-icontains`), which will not work any more in selectors passed to LiveViewTest's [`element/3`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html#element/3) function. In most cases, the `text_filter` option of [`element/3`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html#element/3) should be a sufficient replacement, which has been available since LiveView v0.12. + +Note that in Phoenix versions prior to v1.8, the `phx.gen.auth` generator used the Floki specific `fl-contains` selector in its generated tests in two instances, so if you used the `phx.gen.auth` generator to scaffold your authentication solution, those tests will need to be adjusted when updating to LiveView v1.1. In both cases, changing to use the `text_filter` option is enough to get you going again: + +```diff + {:ok, _login_live, login_html} = + lv +- |> element(~s|main a:fl-contains("Sign up")|) ++ |> element("main a", "Sign up") + |> render_click() + |> follow_redirect(conn, ~p"<%= schema.route_prefix %>/register") +``` + +If you're using Floki itself in your tests through its API (`Floki.parse_document`, `Floki.find`, etc.), you are not required to rewrite them when you update to LiveView v1.1. + +## Slot and line annotations + +When `:debug_heex_annotations` is enabled, LiveView will now annotate the beginning and end of each slot. A new `:debug_attributes` option has also been added, which adds the starting line of each tag as a `data-phx-loc` attribute. It also adds the LiveView PID to the root element of each LiveView. The goal is to provide more precise information to tools. + +To enable this, a new callback called `annotate_slot/4` was added. Custom implementations of `Phoenix.LiveView.TagEngine` must implement it accordingly. + +## v1.1.28 (2026-03-27) + +### Bug fixes + +* Fix race condition that could lead to a JS exception when nested LiveView is removed while it is joining ([#4177](https://github.com/phoenixframework/phoenix_live_view/issues/4177)) + +### Enhancements + +* A bunch of small performance and documentation improvements (thank you [@preciz](https://github.com/preciz)!) + +## v1.1.27 (2026-03-10) + +### Bug fixes + +* Workaround Chrome bug when patching `