-module(jsonlogic@internal@decoding). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/jsonlogic/internal/decoding.gleam"). -export([decode_operator/1, dynamic_to_bool/1, dynamic_to_string/1, dynamic_to_array/1, bool_to_float/1, dynamic_to_int/1, dynamic_to_float/1, decode_data/3, decode_data_val/2, decode_rule/1, decode_rule_string/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -file("src/jsonlogic/internal/decoding.gleam", 95). ?DOC(false). -spec decode_operator(binary()) -> {ok, jsonlogic@internal@operator:operator()} | {error, jsonlogic@error:evaluation_error()}. decode_operator(Operator) -> case Operator of <<"val"/utf8>> -> {ok, value}; <<"var"/utf8>> -> {ok, variable}; <<"missing"/utf8>> -> {ok, missing}; <<"missing_some"/utf8>> -> {ok, missing_some}; <<"=="/utf8>> -> {ok, abstract_equals}; <<"!="/utf8>> -> {ok, abstract_not_equals}; <<"==="/utf8>> -> {ok, strict_equals}; <<"!=="/utf8>> -> {ok, strict_not_equals}; <<">"/utf8>> -> {ok, greater_than}; <<"<"/utf8>> -> {ok, less_than}; <<">="/utf8>> -> {ok, greater_than_or_equal}; <<"<="/utf8>> -> {ok, less_than_or_equal}; <<"!"/utf8>> -> {ok, negate}; <<"!!"/utf8>> -> {ok, double_negate}; <<"or"/utf8>> -> {ok, 'or'}; <<"and"/utf8>> -> {ok, 'and'}; <<"?:"/utf8>> -> {ok, conditional}; <<"in"/utf8>> -> {ok, in}; <<"cat"/utf8>> -> {ok, concatenate}; <<"%"/utf8>> -> {ok, modulo}; <<"max"/utf8>> -> {ok, max}; <<"min"/utf8>> -> {ok, min}; <<"+"/utf8>> -> {ok, plus}; <<"*"/utf8>> -> {ok, multiply}; <<"-"/utf8>> -> {ok, minus}; <<"/"/utf8>> -> {ok, divide}; <<"substr"/utf8>> -> {ok, substring}; <<"merge"/utf8>> -> {ok, merge}; <<"if"/utf8>> -> {ok, 'if'}; <<"filter"/utf8>> -> {ok, filter}; <<"map"/utf8>> -> {ok, map}; <<"reduce"/utf8>> -> {ok, reduce}; <<"all"/utf8>> -> {ok, all}; <<"none"/utf8>> -> {ok, none}; <<"some"/utf8>> -> {ok, some}; _ -> {error, {unknown_operator_error, Operator}} end. -file("src/jsonlogic/internal/decoding.gleam", 202). ?DOC(false). -spec dynamic_to_bool(gleam@dynamic:dynamic_()) -> {ok, {boolean(), gleam@dynamic:dynamic_()}} | {error, jsonlogic@error:evaluation_error()}. dynamic_to_bool(Input) -> case gleam_stdlib:classify_dynamic(Input) of <<"Bool"/utf8>> -> Decoded@1 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_bool/1} ) of {ok, Decoded} -> Decoded; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 207, value => _assert_fail, start => 5936, 'end' => 5991, pattern_start => 5947, pattern_end => 5958}) end, {ok, {Decoded@1, Input}}; <<"Int"/utf8>> -> Decoded@3 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_int/1} ) of {ok, Decoded@2} -> Decoded@2; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 211, value => _assert_fail@1, start => 6047, 'end' => 6101, pattern_start => 6058, pattern_end => 6069}) end, {ok, {Decoded@3 /= 0, Input}}; <<"Float"/utf8>> -> Decoded@5 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_float/1} ) of {ok, Decoded@4} -> Decoded@4; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 215, value => _assert_fail@2, start => 6164, 'end' => 6220, pattern_start => 6175, pattern_end => 6186}) end, {ok, {Decoded@5 /= +0.0, Input}}; <<"String"/utf8>> -> Decoded@7 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_string/1} ) of {ok, Decoded@6} -> Decoded@6; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 219, value => _assert_fail@3, start => 6286, 'end' => 6343, pattern_start => 6297, pattern_end => 6308}) end, {ok, {Decoded@7 /= <<""/utf8>>, Input}}; <<"List"/utf8>> -> Decoded@9 = case gleam@dynamic@decode:run( Input, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ) of {ok, Decoded@8} -> Decoded@8; _assert_fail@4 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 223, value => _assert_fail@4, start => 6406, 'end' => 6477, pattern_start => 6417, pattern_end => 6428}) end, {ok, {Decoded@9 /= [], Input}}; <<"Nil"/utf8>> -> {ok, {false, Input}}; <<"Dict"/utf8>> -> Decoded@11 = case gleam@dynamic@decode:run( Input, gleam@dynamic@decode:dict( {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ) of {ok, Decoded@10} -> Decoded@10; _assert_fail@5 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 228, value => _assert_fail@5, start => 6573, 'end' => 6668, pattern_start => 6584, pattern_end => 6595}) end, {ok, {maps:size(Decoded@11) /= 0, Input}}; T -> erlang:error(#{gleam_error => panic, message => (<<"Cannot convert type: "/utf8, T/binary>>), file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_bool"/utf8>>, line => 233}) end. -file("src/jsonlogic/internal/decoding.gleam", 237). ?DOC(false). -spec dynamic_to_string(gleam@dynamic:dynamic_()) -> {ok, binary()} | {error, jsonlogic@error:evaluation_error()}. dynamic_to_string(Input) -> _pipe@4 = gleam@dynamic@decode:run( Input, gleam@dynamic@decode:one_of( {decoder, fun gleam@dynamic@decode:decode_string/1}, [begin _pipe = {decoder, fun gleam@dynamic@decode:decode_float/1}, gleam@dynamic@decode:map( _pipe, fun gleam_stdlib:float_to_string/1 ) end, begin _pipe@1 = {decoder, fun gleam@dynamic@decode:decode_int/1}, gleam@dynamic@decode:map( _pipe@1, fun erlang:integer_to_binary/1 ) end, begin _pipe@2 = {decoder, fun gleam@dynamic@decode:decode_bool/1}, _pipe@3 = gleam@dynamic@decode:map( _pipe@2, fun gleam@bool:to_string/1 ), gleam@dynamic@decode:map(_pipe@3, fun string:lowercase/1) end] ) ), gleam@result:map_error(_pipe@4, fun(Field@0) -> {decode_error, Field@0} end). -file("src/jsonlogic/internal/decoding.gleam", 251). ?DOC(false). -spec dynamic_to_array(gleam@dynamic:dynamic_()) -> {ok, list(gleam@dynamic:dynamic_())} | {error, jsonlogic@error:evaluation_error()}. dynamic_to_array(Input) -> _pipe@2 = gleam@dynamic@decode:run( Input, gleam@dynamic@decode:one_of( begin _pipe = gleam@dynamic@decode:optional( gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ), gleam@dynamic@decode:map(_pipe, fun(Value) -> case Value of none -> []; {some, Value@1} -> Value@1 end end) end, [begin _pipe@1 = {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, gleam@dynamic@decode:map(_pipe@1, fun gleam@list:wrap/1) end] ) ), gleam@result:map_error(_pipe@2, fun(Field@0) -> {decode_error, Field@0} end). -file("src/jsonlogic/internal/decoding.gleam", 272). ?DOC(false). -spec bool_to_float(boolean()) -> float(). bool_to_float(Value) -> case Value of true -> 1.0; false -> +0.0 end. -file("src/jsonlogic/internal/decoding.gleam", 138). ?DOC(false). -spec dynamic_to_int(gleam@dynamic:dynamic_()) -> {ok, integer()} | {error, jsonlogic@error:evaluation_error()}. dynamic_to_int(Input) -> case gleam_stdlib:classify_dynamic(Input) of <<"String"/utf8>> -> Decoded@1 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_string/1} ) of {ok, Decoded} -> Decoded; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_int"/utf8>>, line => 143, value => _assert_fail, start => 4246, 'end' => 4303, pattern_start => 4257, pattern_end => 4268}) end, case Decoded@1 of <<""/utf8>> -> {ok, 0}; _ -> _pipe = gleam_stdlib:parse_float(Decoded@1), _pipe@1 = gleam@result:map(_pipe, fun erlang:trunc/1), _pipe@2 = gleam@result:try_recover( _pipe@1, fun(_) -> gleam_stdlib:parse_int(Decoded@1) end ), gleam@result:map_error(_pipe@2, fun(_) -> na_n_error end) end; <<"Int"/utf8>> -> Decoded@3 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_int/1} ) of {ok, Decoded@2} -> Decoded@2; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_int"/utf8>>, line => 154, value => _assert_fail@1, start => 4582, 'end' => 4636, pattern_start => 4593, pattern_end => 4604}) end, {ok, Decoded@3}; <<"Float"/utf8>> -> Decoded@5 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_float/1} ) of {ok, Decoded@4} -> Decoded@4; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_int"/utf8>>, line => 158, value => _assert_fail@2, start => 4684, 'end' => 4740, pattern_start => 4695, pattern_end => 4706}) end, {ok, erlang:trunc(Decoded@5)}; <<"Bool"/utf8>> -> Decoded@7 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_bool/1} ) of {ok, Decoded@6} -> Decoded@6; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_int"/utf8>>, line => 162, value => _assert_fail@3, start => 4803, 'end' => 4858, pattern_start => 4814, pattern_end => 4825}) end, _pipe@3 = bool_to_float(Decoded@7), _pipe@4 = erlang:trunc(_pipe@3), {ok, _pipe@4}; T -> erlang:error(#{gleam_error => panic, message => (<<"Cannot convert type: "/utf8, T/binary>>), file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_int"/utf8>>, line => 167}) end. -file("src/jsonlogic/internal/decoding.gleam", 171). ?DOC(false). -spec dynamic_to_float(gleam@dynamic:dynamic_()) -> {ok, float()} | {error, jsonlogic@error:evaluation_error()}. dynamic_to_float(Input) -> case gleam_stdlib:classify_dynamic(Input) of <<"String"/utf8>> -> Decoded@1 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_string/1} ) of {ok, Decoded} -> Decoded; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_float"/utf8>>, line => 176, value => _assert_fail, start => 5140, 'end' => 5197, pattern_start => 5151, pattern_end => 5162}) end, case Decoded@1 of <<""/utf8>> -> {ok, +0.0}; _ -> _pipe = lenient_parse:to_float(Decoded@1), gleam@result:map_error(_pipe, fun(_) -> na_n_error end) end; <<"Float"/utf8>> -> Decoded@3 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_float/1} ) of {ok, Decoded@2} -> Decoded@2; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_float"/utf8>>, line => 185, value => _assert_fail@1, start => 5389, 'end' => 5445, pattern_start => 5400, pattern_end => 5411}) end, {ok, Decoded@3}; <<"Int"/utf8>> -> Decoded@5 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_int/1} ) of {ok, Decoded@4} -> Decoded@4; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_float"/utf8>>, line => 189, value => _assert_fail@2, start => 5491, 'end' => 5545, pattern_start => 5502, pattern_end => 5513}) end, {ok, erlang:float(Decoded@5)}; <<"Bool"/utf8>> -> Decoded@7 = case gleam@dynamic@decode:run( Input, {decoder, fun gleam@dynamic@decode:decode_bool/1} ) of {ok, Decoded@6} -> Decoded@6; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"dynamic_to_float"/utf8>>, line => 193, value => _assert_fail@3, start => 5606, 'end' => 5661, pattern_start => 5617, pattern_end => 5628}) end, _pipe@1 = bool_to_float(Decoded@7), {ok, _pipe@1}; <<"Nil"/utf8>> -> {ok, +0.0}; _ -> {error, na_n_error} end. -file("src/jsonlogic/internal/decoding.gleam", 310). ?DOC(false). -spec do_decode_data( list(gleam@dynamic:dynamic_()), gleam@dynamic:dynamic_(), gleam@option:option(gleam@dynamic:dynamic_()) ) -> gleam@dynamic:dynamic_(). do_decode_data(Key, Data, Default) -> _pipe = gleam@dynamic@decode:run( Data, gleam@dynamic@decode:at( Key, {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ), gleam@result:lazy_unwrap(_pipe, fun() -> case Default of {some, Default@1} -> Default@1; none -> gleam@dynamic:nil() end end). -file("src/jsonlogic/internal/decoding.gleam", 279). ?DOC(false). -spec decode_data( gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@option:option(gleam@dynamic:dynamic_()) ) -> {ok, gleam@dynamic:dynamic_()} | {error, jsonlogic@error:evaluation_error()}. decode_data(Key, Data, Default) -> case {Key =:= gleam@dynamic:nil(), Key =:= gleam_stdlib:identity(<<""/utf8>>), Key =:= gleam_stdlib:identity([])} of {true, _, _} -> {ok, Data}; {_, true, _} -> {ok, Data}; {_, _, true} -> {ok, Data}; {_, _, _} -> gleam@result:map( dynamic_to_string(Key), fun(Key@1) -> Keys = gleam@string:split(Key@1, <<"."/utf8>>), _pipe@2 = gleam@list:map( Keys, fun(K) -> _pipe = gleam_stdlib:parse_int(K), _pipe@1 = gleam@result:map( _pipe, fun gleam_stdlib:identity/1 ), gleam@result:unwrap( _pipe@1, gleam_stdlib:identity(K) ) end ), do_decode_data(_pipe@2, Data, Default) end ) end. -file("src/jsonlogic/internal/decoding.gleam", 303). ?DOC(false). -spec decode_data_val(list(gleam@dynamic:dynamic_()), gleam@dynamic:dynamic_()) -> {ok, gleam@dynamic:dynamic_()} | {error, jsonlogic@error:evaluation_error()}. decode_data_val(Key, Data) -> {ok, do_decode_data(Key, Data, none)}. -file("src/jsonlogic/internal/decoding.gleam", 65). ?DOC(false). -spec decode_literal(gleam@dynamic:dynamic_()) -> {ok, jsonlogic@internal@rule:json_literal()} | {error, jsonlogic@error:evaluation_error()}. decode_literal(Literal) -> case gleam_stdlib:classify_dynamic(Literal) of <<"Bool"/utf8>> -> Decoded@1 = case gleam@dynamic@decode:run( Literal, {decoder, fun gleam@dynamic@decode:decode_bool/1} ) of {ok, Decoded} -> Decoded; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 70, value => _assert_fail, start => 1959, 'end' => 2016, pattern_start => 1970, pattern_end => 1981}) end, {ok, {bool_literal, Decoded@1}}; <<"String"/utf8>> -> Decoded@3 = case gleam@dynamic@decode:run( Literal, {decoder, fun gleam@dynamic@decode:decode_string/1} ) of {ok, Decoded@2} -> Decoded@2; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 74, value => _assert_fail@1, start => 2083, 'end' => 2142, pattern_start => 2094, pattern_end => 2105}) end, {ok, {string_literal, Decoded@3}}; <<"Int"/utf8>> -> Decoded@5 = case gleam@dynamic@decode:run( Literal, {decoder, fun gleam@dynamic@decode:decode_int/1} ) of {ok, Decoded@4} -> Decoded@4; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 78, value => _assert_fail@2, start => 2208, 'end' => 2264, pattern_start => 2219, pattern_end => 2230}) end, {ok, {int_literal, Decoded@5}}; <<"Float"/utf8>> -> Decoded@7 = case gleam@dynamic@decode:run( Literal, {decoder, fun gleam@dynamic@decode:decode_float/1} ) of {ok, Decoded@6} -> Decoded@6; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 82, value => _assert_fail@3, start => 2329, 'end' => 2387, pattern_start => 2340, pattern_end => 2351}) end, {ok, {float_literal, Decoded@7}}; <<"Nil"/utf8>> -> {ok, nil_literal}; <<"List"/utf8>> -> Decoded@9 = case gleam@dynamic@decode:run( Literal, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ) of {ok, Decoded@8} -> Decoded@8; _assert_fail@4 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 87, value => _assert_fail@4, start => 2486, 'end' => 2559, pattern_start => 2497, pattern_end => 2508}) end, _pipe = gleam@list:try_map(Decoded@9, fun decode_rule/1), gleam@result:map( _pipe, fun(Field@0) -> {array_literal, Field@0} end ); T -> erlang:error(#{gleam_error => panic, message => (<<"Unsupported literal type: "/utf8, T/binary>>), file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_literal"/utf8>>, line => 91}) end. -file("src/jsonlogic/internal/decoding.gleam", 25). ?DOC(false). -spec decode_rule(gleam@dynamic:dynamic_()) -> {ok, jsonlogic@internal@rule:rule()} | {error, jsonlogic@error:evaluation_error()}. decode_rule(Rule) -> case gleam_stdlib:classify_dynamic(Rule) of <<"Bool"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"String"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"Int"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"Float"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"Nil"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"List"/utf8>> -> _pipe = decode_literal(Rule), gleam@result:map(_pipe, fun(Field@0) -> {literal, Field@0} end); <<"Dict"/utf8>> -> Decoding_result = begin _pipe@1 = gleam@dynamic@decode:run( Rule, gleam@dynamic@decode:dict( {decoder, fun gleam@dynamic@decode:decode_string/1}, {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ), _pipe@2 = gleam@result:map(_pipe@1, fun maps:to_list/1), gleam@result:map_error( _pipe@2, fun(Field@0) -> {decode_error, Field@0} end ) end, gleam@result:'try'( Decoding_result, fun(Decoded_entries) -> Raw_rule = begin _pipe@3 = gleam@list:first(Decoded_entries), _pipe@4 = gleam@result:map_error( _pipe@3, fun(_) -> {invalid_rule_error, <<"no operator in rule"/utf8>>} end ), gleam@result:'try'( _pipe@4, fun(Rule@1) -> _pipe@5 = decode_rule(erlang:element(2, Rule@1)), gleam@result:map( _pipe@5, fun(Values) -> case Values of {literal, {array_literal, Inner_values}} -> {erlang:element(1, Rule@1), Inner_values}; Other_rule -> {erlang:element(1, Rule@1), [Other_rule]} end end ) end ) end, gleam@result:'try'( Raw_rule, fun(_use0) -> {Operator, Values@1} = _use0, gleam@result:map( decode_operator(Operator), fun(Typed_operator) -> {operation, Typed_operator, Values@1} end ) end ) end ); Unrecognized -> erlang:error(#{gleam_error => panic, message => (<<"Unrecognized rule: "/utf8, Unrecognized/binary>>), file => <>, module => <<"jsonlogic/internal/decoding"/utf8>>, function => <<"decode_rule"/utf8>>, line => 61}) end. -file("src/jsonlogic/internal/decoding.gleam", 17). ?DOC(false). -spec decode_rule_string(binary()) -> {ok, jsonlogic@internal@rule:rule()} | {error, jsonlogic@error:evaluation_error()}. decode_rule_string(Rule) -> _pipe = gleam@json:parse( Rule, {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ), _pipe@1 = gleam@result:map_error( _pipe, fun(Field@0) -> {json_decode_error, Field@0} end ), gleam@result:'try'(_pipe@1, fun decode_rule/1).