Current section
Files
Jump to
Current section
Files
src/sprocket@internal@utils@unique.erl
-module(sprocket@internal@utils@unique).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([uuid/0, cuid/1, slug/2, from_string/1, to_string/1, equals/2]).
-export_type([unique/1]).
-opaque unique(JHX) :: {unique, binary()} | {gleam_phantom, JHX}.
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 9).
-spec uuid() -> unique(any()).
uuid() ->
_assert_subject = ids@uuid:generate_v4(),
{ok, Id} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"sprocket/internal/utils/unique"/utf8>>,
function => <<"uuid"/utf8>>,
line => 10})
end,
{unique, Id}.
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 15).
-spec cuid(gleam@erlang@process:subject(ids@cuid:message())) -> unique(any()).
cuid(Channel) ->
Id = ids@cuid:generate(Channel),
{unique, Id}.
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 21).
-spec slug(gleam@erlang@process:subject(ids@cuid:message()), binary()) -> unique(any()).
slug(Channel, Label) ->
Id = <<<<Label/binary, "-"/utf8>>/binary, (ids@cuid:slug(Channel))/binary>>,
{unique, Id}.
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 27).
-spec from_string(binary()) -> unique(any()).
from_string(Str) ->
{unique, Str}.
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 31).
-spec to_string(unique(any())) -> binary().
to_string(Unique) ->
erlang:element(2, Unique).
-file("/home/runner/work/sprocket/sprocket/src/sprocket/internal/utils/unique.gleam", 35).
-spec equals(unique(JIK), unique(JIK)) -> boolean().
equals(A, B) ->
erlang:element(2, A) =:= erlang:element(2, B).