-module(ids@typeid). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([from_uuid/2, generate/1, decode/1]). -spec from_uuid(binary(), binary()) -> {ok, binary()} | {error, binary()}. from_uuid(Prefix, Uuid) -> _assert_subject = gleam@regex:from_string( <<"^([a-z]([a-z_]{0,61}[a-z])?)?$"/utf8>> ), {ok, Re} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"ids/typeid"/utf8>>, function => <<"from_uuid"/utf8>>, line => 35}) end, case gleam@regex:check(Re, Prefix) of true -> P = case Prefix of <<""/utf8>> -> <<""/utf8>>; _ -> <> end, gleam@result:'try'( begin _pipe = Uuid, _pipe@1 = gleam_stdlib:identity(_pipe), ids@uuid:dump(_pipe@1) end, fun(Raw_uuid) -> Id = ids@base32:encode( Raw_uuid, <<"0123456789abcdefghjkmnpqrstvwxyz"/utf8>> ), {ok, <

>} end ); false -> {error, <<"Error: Prefix must contain at most 63 characters and only lowercase alphabetic ASCII characters [a-z], or an underscore."/utf8>>} end. -spec generate(binary()) -> {ok, binary()} | {error, binary()}. generate(Prefix) -> gleam@result:'try'( ids@uuid:generate_v7(), fun(Uuid) -> from_uuid(Prefix, Uuid) end ). -spec decode_suffix(binary()) -> {ok, binary()} | {error, binary()}. decode_suffix(Suffix) -> gleam@result:'try'( begin _pipe = Suffix, _pipe@1 = ids@base32:decode( _pipe, <<"0123456789abcdefghjkmnpqrstvwxyz"/utf8>> ), gleam@result:replace_error( _pipe@1, <<"Error: Couldn't decode suffix."/utf8>> ) end, fun(Raw_uuid) -> gleam@result:'try'( begin _pipe@2 = Raw_uuid, _pipe@3 = ids@uuid:cast(_pipe@2), gleam@result:replace_error( _pipe@3, <<"Error: Couldn't decode UUID."/utf8>> ) end, fun(Uuid) -> {ok, Uuid} end ) end ). -spec decode(binary()) -> {ok, {binary(), binary()}} | {error, binary()}. decode(Tid) -> case begin _pipe = Tid, _pipe@1 = gleam@string:reverse(_pipe), gleam@string:split_once(_pipe@1, <<"_"/utf8>>) end of {ok, {Xiffus, Xiferp}} -> gleam@result:'try'( begin _pipe@2 = Xiffus, _pipe@3 = gleam@string:reverse(_pipe@2), decode_suffix(_pipe@3) end, fun(Uuid) -> {ok, {gleam@string:reverse(Xiferp), Uuid}} end ); {error, nil} -> gleam@result:'try'( decode_suffix(Tid), fun(Uuid@1) -> {ok, {<<""/utf8>>, Uuid@1}} end ) end.