-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 ).