Packages
caffeine_lang
2.0.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@parser@blueprints.erl
-module(caffeine_lang@parser@blueprints).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/parser/blueprints.gleam").
-export([validate_blueprints/2, blueprints_from_json/2, parse_from_json_string/2, parse_from_json_file/2]).
-export_type([blueprint/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 blueprint() :: {blueprint,
binary(),
binary(),
gleam@dict:dict(binary(), caffeine_lang@common@accepted_types:accepted_types()),
gleam@dict:dict(binary(), gleam@dynamic:dynamic_())}.
-file("src/caffeine_lang/parser/blueprints.gleam", 57).
?DOC(false).
-spec validate_blueprints(
list(blueprint()),
list(caffeine_lang@parser@artifacts:artifact())
) -> {ok, list(blueprint())} |
{error, caffeine_lang@common@errors:compilation_error()}.
validate_blueprints(Blueprints, Artifacts) ->
Blueprint_artifact_collection = caffeine_lang@common@helpers:map_reference_to_referrer_over_collection(
Artifacts,
Blueprints,
fun(A) -> erlang:element(2, A) end,
fun(B) -> erlang:element(3, B) end
),
gleam@result:'try'(
caffeine_lang@common@validations:validate_inputs_for_collection(
Blueprint_artifact_collection,
fun(Blueprint) -> erlang:element(5, Blueprint) end,
fun(Artifact) -> erlang:element(3, Artifact) end,
true
),
fun(_) ->
gleam@result:'try'(
caffeine_lang@common@validations:validate_relevant_uniqueness(
Blueprints,
fun(B@1) -> erlang:element(2, B@1) end,
<<"blueprint names"/utf8>>
),
fun(_) ->
Overshadow_params_error = begin
_pipe = Blueprint_artifact_collection,
_pipe@1 = gleam@list:filter_map(
_pipe,
fun(Blueprint_artifact_pair) ->
{Blueprint@1, Artifact@1} = Blueprint_artifact_pair,
case caffeine_lang@common@validations:check_collection_key_overshadowing(
erlang:element(4, Blueprint@1),
erlang:element(3, Artifact@1),
<<"Blueprint overshadowing inherited_params from artifact: "/utf8>>
) of
{ok, _} ->
{error, nil};
{error, Msg} ->
{ok, Msg}
end
end
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end,
gleam@result:'try'(case Overshadow_params_error of
<<""/utf8>> ->
{ok, true};
_ ->
{error,
{parser_duplicate_error,
<<"Overshadowed inherited_params in blueprint error: "/utf8,
Overshadow_params_error/binary>>}}
end, fun(_) ->
Merged_param_blueprints = begin
_pipe@2 = Blueprint_artifact_collection,
gleam@list:map(
_pipe@2,
fun(Blueprint_artifact_pair@1) ->
{Blueprint@2, Artifact@2} = Blueprint_artifact_pair@1,
All_params = begin
_pipe@3 = erlang:element(
3,
Artifact@2
),
maps:merge(
_pipe@3,
erlang:element(4, Blueprint@2)
)
end,
{blueprint,
erlang:element(2, Blueprint@2),
erlang:element(3, Blueprint@2),
All_params,
erlang:element(5, Blueprint@2)}
end
)
end,
{ok, Merged_param_blueprints}
end)
end
)
end
).
-file("src/caffeine_lang/parser/blueprints.gleam", 134).
?DOC(false).
-spec blueprints_from_json(
binary(),
list(caffeine_lang@parser@artifacts:artifact())
) -> {ok, list(blueprint())} | {error, gleam@json:decode_error()}.
blueprints_from_json(Json_string, Artifacts) ->
Blueprint_decoded = begin
gleam@dynamic@decode:field(
<<"name"/utf8>>,
caffeine_lang@common@decoders:non_empty_string_decoder(),
fun(Name) ->
gleam@dynamic@decode:field(
<<"artifact_ref"/utf8>>,
caffeine_lang@common@decoders:named_reference_decoder(
Artifacts,
fun(A) -> erlang:element(2, A) end
),
fun(Artifact_ref) ->
gleam@dynamic@decode:field(
<<"params"/utf8>>,
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
caffeine_lang@common@decoders:accepted_types_decoder(
)
),
fun(Params) ->
gleam@dynamic@decode:field(
<<"inputs"/utf8>>,
gleam@dynamic@decode:dict(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
),
fun(Inputs) ->
gleam@dynamic@decode:success(
{blueprint,
Name,
Artifact_ref,
Params,
Inputs}
)
end
)
end
)
end
)
end
)
end,
Blueprints_decoded = begin
gleam@dynamic@decode:field(
<<"blueprints"/utf8>>,
gleam@dynamic@decode:list(Blueprint_decoded),
fun(Blueprints) -> gleam@dynamic@decode:success(Blueprints) end
)
end,
gleam@json:parse(Json_string, Blueprints_decoded).
-file("src/caffeine_lang/parser/blueprints.gleam", 39).
?DOC(false).
-spec parse_from_json_string(
binary(),
list(caffeine_lang@parser@artifacts:artifact())
) -> {ok, list(blueprint())} |
{error, caffeine_lang@common@errors:compilation_error()}.
parse_from_json_string(Json_string, Artifacts) ->
gleam@result:'try'(case blueprints_from_json(Json_string, Artifacts) of
{ok, Blueprints} ->
{ok, Blueprints};
{error, Err} ->
{error,
caffeine_lang@common@errors:format_json_decode_error(Err)}
end, fun(Blueprints@1) ->
validate_blueprints(Blueprints@1, Artifacts)
end).
-file("src/caffeine_lang/parser/blueprints.gleam", 28).
?DOC(false).
-spec parse_from_json_file(
binary(),
list(caffeine_lang@parser@artifacts:artifact())
) -> {ok, list(blueprint())} |
{error, caffeine_lang@common@errors:compilation_error()}.
parse_from_json_file(File_path, Artifacts) ->
gleam@result:'try'(
caffeine_lang@common@helpers:json_from_file(File_path),
fun(Json_string) -> parse_from_json_string(Json_string, Artifacts) end
).