Packages
caffeine_lang
5.4.2
6.3.1
6.3.0
6.2.2
6.2.1
6.2.0
6.1.2
6.1.1
6.1.0
6.0.0
5.6.0
5.5.0
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.0
5.1.1
5.1.0
5.0.12
5.0.11
5.0.10
5.0.8
5.0.7
5.0.6
5.0.5
5.0.4
5.0.1
5.0.0
4.10.0
4.9.0
4.8.3
4.8.2
4.8.1
4.8.0
4.7.9
4.7.8
4.7.7
4.7.6
4.7.5
4.6.7
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.7
4.3.6
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
0.1.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.2
0.0.1
A compiler for generating reliability artifacts from service expectation definitions.
Current section
Files
Jump to
Current section
Files
src/caffeine_lang@helpers.erl
-module(caffeine_lang@helpers).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/helpers.gleam").
-export([map_reference_to_referrer_over_collection/4, extract_path_prefix/1, index_value_tuples/1, extract_value/3, extract_depends_on/1, extract_window_in_days/1, extract_indicators/1, extract_tags/1, build_system_tag_pairs/6]).
-export_type([value_tuple/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type value_tuple() :: {value_tuple,
binary(),
caffeine_lang@types:accepted_types(),
caffeine_lang@value:value()}.
-file("src/caffeine_lang/helpers.gleam", 22).
?DOC(false).
-spec map_reference_to_referrer_over_collection(
list(GFS),
list(GFU),
fun((GFS) -> binary()),
fun((GFU) -> binary())
) -> list({GFU, GFS}).
map_reference_to_referrer_over_collection(
References,
Referrers,
Reference_name,
Referrer_reference
) ->
Reference_map = begin
_pipe = References,
_pipe@1 = gleam@list:map(
_pipe,
fun(Ref) -> {Reference_name(Ref), Ref} end
),
maps:from_list(_pipe@1)
end,
_pipe@2 = Referrers,
gleam@list:filter_map(
_pipe@2,
fun(Referrer) ->
_pipe@3 = gleam_stdlib:map_get(
Reference_map,
Referrer_reference(Referrer)
),
gleam@result:map(
_pipe@3,
fun(Reference) -> {Referrer, Reference} end
)
end
).
-file("src/caffeine_lang/helpers.gleam", 43).
?DOC(false).
-spec extract_path_prefix(binary()) -> {binary(), binary(), binary()}.
extract_path_prefix(Path) ->
case begin
_pipe = Path,
_pipe@1 = gleam@string:split(_pipe, <<"/"/utf8>>),
_pipe@2 = lists:reverse(_pipe@1),
_pipe@3 = gleam@list:take(_pipe@2, 3),
_pipe@4 = lists:reverse(_pipe@3),
gleam@list:map(
_pipe@4,
fun(Segment) ->
case gleam_stdlib:string_ends_with(
Segment,
<<".caffeine"/utf8>>
) of
true ->
gleam@string:drop_end(Segment, 9);
false ->
case gleam_stdlib:string_ends_with(
Segment,
<<".json"/utf8>>
) of
true ->
gleam@string:drop_end(Segment, 5);
false ->
Segment
end
end
end
)
end of
[Org, Team, Service] ->
{Org, Team, Service};
_ ->
{<<"unknown"/utf8>>, <<"unknown"/utf8>>, <<"unknown"/utf8>>}
end.
-file("src/caffeine_lang/helpers.gleam", 77).
?DOC(false).
-spec index_value_tuples(list(value_tuple())) -> gleam@dict:dict(binary(), value_tuple()).
index_value_tuples(Values) ->
_pipe = Values,
_pipe@1 = gleam@list:map(_pipe, fun(Vt) -> {erlang:element(2, Vt), Vt} end),
maps:from_list(_pipe@1).
-file("src/caffeine_lang/helpers.gleam", 87).
?DOC(false).
-spec extract_value(
gleam@dict:dict(binary(), value_tuple()),
binary(),
fun((caffeine_lang@value:value()) -> {ok, GGC} | {error, nil})
) -> {ok, GGC} | {error, nil}.
extract_value(Index, Label, Extractor) ->
_pipe = Index,
_pipe@1 = gleam_stdlib:map_get(_pipe, Label),
gleam@result:'try'(_pipe@1, fun(Vt) -> Extractor(erlang:element(4, Vt)) end).
-file("src/caffeine_lang/helpers.gleam", 108).
?DOC(" Shared implementation for extracting relations from a Result(ValueTuple, Nil).\n").
-spec extract_relations_from_value_tuple({ok, value_tuple()} | {error, nil}) -> gleam@dict:dict(caffeine_lang@linker@artifacts:dependency_relation_type(), list(binary())).
extract_relations_from_value_tuple(Vt_result) ->
_pipe = Vt_result,
_pipe@8 = gleam@result:'try'(_pipe, fun(Vt) -> case erlang:element(4, Vt) of
{dict_value, D} ->
_pipe@1 = D,
_pipe@2 = maps:to_list(_pipe@1),
_pipe@5 = gleam@list:try_map(
_pipe@2,
fun(Pair) -> case erlang:element(2, Pair) of
{list_value, Items} ->
_pipe@3 = Items,
_pipe@4 = gleam@list:try_map(
_pipe@3,
fun caffeine_lang@value:extract_string/1
),
gleam@result:map(
_pipe@4,
fun(Strings) ->
{erlang:element(1, Pair), Strings}
end
);
_ ->
{error, nil}
end end
),
gleam@result:map(_pipe@5, fun(Pairs) -> _pipe@6 = Pairs,
_pipe@7 = gleam@list:filter_map(
_pipe@6,
fun(Pair@1) ->
case caffeine_lang@linker@artifacts:parse_relation_type(
erlang:element(1, Pair@1)
) of
{ok, Rt} ->
{ok,
{Rt, erlang:element(2, Pair@1)}};
{error, nil} ->
{error, nil}
end
end
),
maps:from_list(_pipe@7) end);
_ ->
{error, nil}
end end),
gleam@result:unwrap(_pipe@8, maps:new()).
-file("src/caffeine_lang/helpers.gleam", 99).
?DOC(false).
-spec extract_depends_on(gleam@dict:dict(binary(), value_tuple())) -> gleam@dict:dict(caffeine_lang@linker@artifacts:dependency_relation_type(), list(binary())).
extract_depends_on(Index) ->
_pipe = Index,
_pipe@1 = gleam_stdlib:map_get(_pipe, <<"depends_on"/utf8>>),
extract_relations_from_value_tuple(_pipe@1).
-file("src/caffeine_lang/helpers.gleam", 145).
?DOC(false).
-spec extract_window_in_days(gleam@dict:dict(binary(), value_tuple())) -> integer().
extract_window_in_days(Index) ->
_pipe = extract_value(
Index,
<<"window_in_days"/utf8>>,
fun caffeine_lang@value:extract_int/1
),
gleam@result:unwrap(_pipe, 30).
-file("src/caffeine_lang/helpers.gleam", 152).
?DOC(false).
-spec extract_indicators(gleam@dict:dict(binary(), value_tuple())) -> gleam@dict:dict(binary(), binary()).
extract_indicators(Index) ->
_pipe = Index,
_pipe@1 = gleam_stdlib:map_get(_pipe, <<"indicators"/utf8>>),
_pipe@2 = gleam@result:'try'(
_pipe@1,
fun(Vt) ->
caffeine_lang@value:extract_string_dict(erlang:element(4, Vt))
end
),
gleam@result:unwrap(_pipe@2, maps:new()).
-file("src/caffeine_lang/helpers.gleam", 163).
?DOC(false).
-spec extract_tags(gleam@dict:dict(binary(), value_tuple())) -> list({binary(),
binary()}).
extract_tags(Index) ->
_pipe = Index,
_pipe@1 = gleam_stdlib:map_get(_pipe, <<"tags"/utf8>>),
_pipe@2 = gleam@result:'try'(
_pipe@1,
fun(Vt) -> case erlang:element(4, Vt) of
nil_value ->
{ok, maps:new()};
{dict_value, _} ->
caffeine_lang@value:extract_string_dict(
erlang:element(4, Vt)
);
_ ->
{error, nil}
end end
),
_pipe@3 = gleam@result:unwrap(_pipe@2, maps:new()),
_pipe@4 = maps:to_list(_pipe@3),
gleam@list:sort(
_pipe@4,
fun(A, B) ->
gleam@string:compare(erlang:element(1, A), erlang:element(1, B))
end
).
-file("src/caffeine_lang/helpers.gleam", 182).
?DOC(
" Build system tag key-value pairs from IR metadata fields.\n"
" Returns a sorted, deterministic list of tag pairs shared across all generators.\n"
).
-spec build_system_tag_pairs(
caffeine_lang@identifiers:org_name(),
caffeine_lang@identifiers:team_name(),
caffeine_lang@identifiers:service_name(),
caffeine_lang@identifiers:measurement_name(),
caffeine_lang@identifiers:expectation_label(),
gleam@dict:dict(binary(), list(binary()))
) -> list({binary(), binary()}).
build_system_tag_pairs(
Org_name,
Team_name,
Service_name,
Measurement_name,
Friendly_label,
Misc
) ->
_pipe = [{<<"managed_by"/utf8>>, <<"caffeine"/utf8>>},
{<<"caffeine_version"/utf8>>, <<"5.4.2"/utf8>>},
{<<"org"/utf8>>, erlang:element(2, Org_name)},
{<<"team"/utf8>>, erlang:element(2, Team_name)},
{<<"service"/utf8>>, erlang:element(2, Service_name)},
{<<"measurement"/utf8>>, erlang:element(2, Measurement_name)},
{<<"expectation"/utf8>>, erlang:element(2, Friendly_label)}],
lists:append(
_pipe,
begin
_pipe@1 = Misc,
_pipe@2 = maps:to_list(_pipe@1),
_pipe@3 = gleam@list:sort(
_pipe@2,
fun(A, B) ->
gleam@string:compare(
erlang:element(1, A),
erlang:element(1, B)
)
end
),
gleam@list:flat_map(
_pipe@3,
fun(Pair) ->
{Key, Values} = Pair,
_pipe@4 = Values,
_pipe@5 = gleam@list:sort(
_pipe@4,
fun gleam@string:compare/2
),
gleam@list:map(_pipe@5, fun(Value) -> {Key, Value} end)
end
)
end
).