Packages
caffeine_lang
4.7.5
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_value_indexed/3, extract_threshold/1, extract_threshold_indexed/1, extract_relations/1, extract_relations_indexed/1, extract_indicators/1, extract_indicators_indexed/1, extract_tags/1, extract_tags_indexed/1, build_system_tag_pairs/7, extract_window_in_days/1, extract_window_in_days_indexed/1]).
-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", 24).
?DOC(false).
-spec map_reference_to_referrer_over_collection(
list(GVZ),
list(GWB),
fun((GVZ) -> binary()),
fun((GWB) -> binary())
) -> list({GWB, GVZ}).
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", 45).
?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", 76).
?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", 86).
?DOC(false).
-spec extract_value(
list(value_tuple()),
binary(),
fun((caffeine_lang@value:value()) -> {ok, GWI} | {error, nil})
) -> {ok, GWI} | {error, nil}.
extract_value(Values, Label, Extractor) ->
_pipe = Values,
_pipe@1 = gleam@list:find(
_pipe,
fun(Vt) -> erlang:element(2, Vt) =:= Label end
),
gleam@result:'try'(
_pipe@1,
fun(Vt@1) -> Extractor(erlang:element(4, Vt@1)) end
).
-file("src/caffeine_lang/helpers.gleam", 98).
?DOC(false).
-spec extract_value_indexed(
gleam@dict:dict(binary(), value_tuple()),
binary(),
fun((caffeine_lang@value:value()) -> {ok, GWP} | {error, nil})
) -> {ok, GWP} | {error, nil}.
extract_value_indexed(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", 111).
?DOC(false).
-spec extract_threshold(list(value_tuple())) -> float().
extract_threshold(Values) ->
Threshold@1 = case extract_value(
Values,
<<"threshold"/utf8>>,
fun caffeine_lang@value:extract_percentage/1
) of
{ok, Threshold} -> Threshold;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"caffeine_lang/helpers"/utf8>>,
function => <<"extract_threshold"/utf8>>,
line => 112,
value => _assert_fail,
start => 3369,
'end' => 3460,
pattern_start => 3380,
pattern_end => 3393})
end,
Threshold@1.
-file("src/caffeine_lang/helpers.gleam", 119).
?DOC(false).
-spec extract_threshold_indexed(gleam@dict:dict(binary(), value_tuple())) -> float().
extract_threshold_indexed(Index) ->
Threshold@1 = case extract_value_indexed(
Index,
<<"threshold"/utf8>>,
fun caffeine_lang@value:extract_percentage/1
) of
{ok, Threshold} -> Threshold;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"caffeine_lang/helpers"/utf8>>,
function => <<"extract_threshold_indexed"/utf8>>,
line => 122,
value => _assert_fail,
start => 3638,
'end' => 3736,
pattern_start => 3649,
pattern_end => 3662})
end,
Threshold@1.
-file("src/caffeine_lang/helpers.gleam", 149).
?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", 130).
?DOC(false).
-spec extract_relations(list(value_tuple())) -> gleam@dict:dict(caffeine_lang@linker@artifacts:dependency_relation_type(), list(binary())).
extract_relations(Values) ->
_pipe = Values,
_pipe@1 = gleam@list:find(
_pipe,
fun(Vt) -> erlang:element(2, Vt) =:= <<"relations"/utf8>> end
),
extract_relations_from_value_tuple(_pipe@1).
-file("src/caffeine_lang/helpers.gleam", 140).
?DOC(false).
-spec extract_relations_indexed(gleam@dict:dict(binary(), value_tuple())) -> gleam@dict:dict(caffeine_lang@linker@artifacts:dependency_relation_type(), list(binary())).
extract_relations_indexed(Index) ->
_pipe = Index,
_pipe@1 = gleam_stdlib:map_get(_pipe, <<"relations"/utf8>>),
extract_relations_from_value_tuple(_pipe@1).
-file("src/caffeine_lang/helpers.gleam", 205).
?DOC(false).
-spec extract_indicators(list(value_tuple())) -> gleam@dict:dict(binary(), binary()).
extract_indicators(Values) ->
_pipe = Values,
_pipe@1 = gleam@list:find(
_pipe,
fun(Vt) -> erlang:element(2, Vt) =:= <<"indicators"/utf8>> end
),
_pipe@2 = gleam@result:'try'(
_pipe@1,
fun(Vt@1) ->
caffeine_lang@value:extract_string_dict(erlang:element(4, Vt@1))
end
),
gleam@result:unwrap(_pipe@2, maps:new()).
-file("src/caffeine_lang/helpers.gleam", 214).
?DOC(false).
-spec extract_indicators_indexed(gleam@dict:dict(binary(), value_tuple())) -> gleam@dict:dict(binary(), binary()).
extract_indicators_indexed(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", 225).
?DOC(false).
-spec extract_tags(list(value_tuple())) -> list({binary(), binary()}).
extract_tags(Values) ->
_pipe = Values,
_pipe@1 = gleam@list:find(
_pipe,
fun(Vt) -> erlang:element(2, Vt) =:= <<"tags"/utf8>> end
),
_pipe@2 = gleam@result:'try'(
_pipe@1,
fun(Vt@1) -> case erlang:element(4, Vt@1) of
nil_value ->
{ok, maps:new()};
{dict_value, _} ->
caffeine_lang@value:extract_string_dict(
erlang:element(4, Vt@1)
);
_ ->
{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", 242).
?DOC(false).
-spec extract_tags_indexed(gleam@dict:dict(binary(), value_tuple())) -> list({binary(),
binary()}).
extract_tags_indexed(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", 261).
?DOC(
" Build system tag key-value pairs from IR metadata fields and artifact refs.\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:blueprint_name(),
caffeine_lang@identifiers:expectation_label(),
list(caffeine_lang@linker@artifacts:artifact_type()),
gleam@dict:dict(binary(), list(binary()))
) -> list({binary(), binary()}).
build_system_tag_pairs(
Org_name,
Team_name,
Service_name,
Blueprint_name,
Friendly_label,
Artifact_refs,
Misc
) ->
_pipe = [{<<"managed_by"/utf8>>, <<"caffeine"/utf8>>},
{<<"caffeine_version"/utf8>>, <<"4.7.5"/utf8>>},
{<<"org"/utf8>>, erlang:element(2, Org_name)},
{<<"team"/utf8>>, erlang:element(2, Team_name)},
{<<"service"/utf8>>, erlang:element(2, Service_name)},
{<<"blueprint"/utf8>>, erlang:element(2, Blueprint_name)},
{<<"expectation"/utf8>>, erlang:element(2, Friendly_label)}],
_pipe@2 = lists:append(
_pipe,
begin
_pipe@1 = Artifact_refs,
gleam@list:map(
_pipe@1,
fun(Ref) ->
{<<"artifact"/utf8>>,
caffeine_lang@linker@artifacts:artifact_type_to_string(
Ref
)}
end
)
end
),
lists:append(
_pipe@2,
begin
_pipe@3 = Misc,
_pipe@4 = maps:to_list(_pipe@3),
_pipe@5 = gleam@list:sort(
_pipe@4,
fun(A, B) ->
gleam@string:compare(
erlang:element(1, A),
erlang:element(1, B)
)
end
),
gleam@list:flat_map(
_pipe@5,
fun(Pair) ->
{Key, Values} = Pair,
_pipe@6 = Values,
_pipe@7 = gleam@list:sort(
_pipe@6,
fun gleam@string:compare/2
),
gleam@list:map(_pipe@7, fun(Value) -> {Key, Value} end)
end
)
end
).
-file("src/caffeine_lang/helpers.gleam", 189).
?DOC(false).
-spec extract_window_in_days(list(value_tuple())) -> integer().
extract_window_in_days(Values) ->
_pipe = extract_value(
Values,
<<"window_in_days"/utf8>>,
fun caffeine_lang@value:extract_int/1
),
gleam@result:unwrap(_pipe, 30).
-file("src/caffeine_lang/helpers.gleam", 196).
?DOC(false).
-spec extract_window_in_days_indexed(gleam@dict:dict(binary(), value_tuple())) -> integer().
extract_window_in_days_indexed(Index) ->
_pipe = extract_value_indexed(
Index,
<<"window_in_days"/utf8>>,
fun caffeine_lang@value:extract_int/1
),
gleam@result:unwrap(_pipe, 30).