Current section
Files
Jump to
Current section
Files
src/jsonlogic@internal@decoding.erl
-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", 20).
?DOC(false).
-spec to_nullable(gleam@option:option(GIY)) -> {ok, GIY} | {error, nil}.
to_nullable(Value) ->
gleam@option:to_result(Value, nil).
-file("src/jsonlogic/internal/decoding.gleam", 102).
?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", 209).
?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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 214,
value => _assert_fail,
start => 6068,
'end' => 6123,
pattern_start => 6079,
pattern_end => 6090})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 218,
value => _assert_fail@1,
start => 6179,
'end' => 6233,
pattern_start => 6190,
pattern_end => 6201})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 222,
value => _assert_fail@2,
start => 6296,
'end' => 6352,
pattern_start => 6307,
pattern_end => 6318})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 226,
value => _assert_fail@3,
start => 6418,
'end' => 6475,
pattern_start => 6429,
pattern_end => 6440})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 230,
value => _assert_fail@4,
start => 6538,
'end' => 6609,
pattern_start => 6549,
pattern_end => 6560})
end,
{ok, {Decoded@9 /= [], Input}};
<<"Nil"/utf8>> ->
{ok, {false, Input}};
<<"Dict"/utf8>> ->
{ok, {true, Input}};
T ->
erlang:error(#{gleam_error => panic,
message => (<<"Cannot convert type: "/utf8, T/binary>>),
file => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_bool"/utf8>>,
line => 236})
end.
-file("src/jsonlogic/internal/decoding.gleam", 240).
?DOC(false).
-spec dynamic_to_string(gleam@dynamic:dynamic_()) -> {ok, binary()} |
{error, jsonlogic@error:evaluation_error()}.
dynamic_to_string(Input) ->
_pipe@5 = gleam@dynamic@decode:run(
Input,
gleam@dynamic@decode:one_of(
begin
_pipe = gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
gleam@dynamic@decode:map(
_pipe,
fun(_capture) ->
gleam@option:unwrap(_capture, <<""/utf8>>)
end
)
end,
[begin
_pipe@1 = {decoder, fun gleam@dynamic@decode:decode_float/1},
gleam@dynamic@decode:map(
_pipe@1,
fun gleam_stdlib:float_to_string/1
)
end,
begin
_pipe@2 = {decoder, fun gleam@dynamic@decode:decode_int/1},
gleam@dynamic@decode:map(
_pipe@2,
fun erlang:integer_to_binary/1
)
end,
begin
_pipe@3 = {decoder, fun gleam@dynamic@decode:decode_bool/1},
_pipe@4 = gleam@dynamic@decode:map(
_pipe@3,
fun gleam@bool:to_string/1
),
gleam@dynamic@decode:map(_pipe@4, fun string:lowercase/1)
end]
)
),
gleam@result:map_error(_pipe@5, fun(Field@0) -> {decode_error, Field@0} end).
-file("src/jsonlogic/internal/decoding.gleam", 260).
?DOC(false).
-spec dynamic_to_array(gleam@dynamic:dynamic_()) -> {ok,
{ok, list(gleam@dynamic:dynamic_())} | {error, nil}} |
{error, jsonlogic@error:evaluation_error()}.
dynamic_to_array(Input) ->
_pipe@3 = 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 to_nullable/1)
end,
[begin
_pipe@1 = {decoder,
fun gleam@dynamic@decode:decode_dynamic/1},
_pipe@2 = gleam@dynamic@decode:map(
_pipe@1,
fun gleam@list:wrap/1
),
gleam@dynamic@decode:map(
_pipe@2,
fun(Field@0) -> {ok, Field@0} end
)
end]
)
),
gleam@result:map_error(_pipe@3, fun(Field@0) -> {decode_error, Field@0} end).
-file("src/jsonlogic/internal/decoding.gleam", 276).
?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", 145).
?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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_int"/utf8>>,
line => 150,
value => _assert_fail,
start => 4378,
'end' => 4435,
pattern_start => 4389,
pattern_end => 4400})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_int"/utf8>>,
line => 161,
value => _assert_fail@1,
start => 4714,
'end' => 4768,
pattern_start => 4725,
pattern_end => 4736})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_int"/utf8>>,
line => 165,
value => _assert_fail@2,
start => 4816,
'end' => 4872,
pattern_start => 4827,
pattern_end => 4838})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_int"/utf8>>,
line => 169,
value => _assert_fail@3,
start => 4935,
'end' => 4990,
pattern_start => 4946,
pattern_end => 4957})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_int"/utf8>>,
line => 174})
end.
-file("src/jsonlogic/internal/decoding.gleam", 178).
?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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_float"/utf8>>,
line => 183,
value => _assert_fail,
start => 5272,
'end' => 5329,
pattern_start => 5283,
pattern_end => 5294})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_float"/utf8>>,
line => 192,
value => _assert_fail@1,
start => 5521,
'end' => 5577,
pattern_start => 5532,
pattern_end => 5543})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_float"/utf8>>,
line => 196,
value => _assert_fail@2,
start => 5623,
'end' => 5677,
pattern_start => 5634,
pattern_end => 5645})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"dynamic_to_float"/utf8>>,
line => 200,
value => _assert_fail@3,
start => 5738,
'end' => 5793,
pattern_start => 5749,
pattern_end => 5760})
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", 314).
?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", 283).
?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", 307).
?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", 72).
?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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 77,
value => _assert_fail,
start => 2091,
'end' => 2148,
pattern_start => 2102,
pattern_end => 2113})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 81,
value => _assert_fail@1,
start => 2215,
'end' => 2274,
pattern_start => 2226,
pattern_end => 2237})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 85,
value => _assert_fail@2,
start => 2340,
'end' => 2396,
pattern_start => 2351,
pattern_end => 2362})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 89,
value => _assert_fail@3,
start => 2461,
'end' => 2519,
pattern_start => 2472,
pattern_end => 2483})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 94,
value => _assert_fail@4,
start => 2618,
'end' => 2691,
pattern_start => 2629,
pattern_end => 2640})
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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_literal"/utf8>>,
line => 98})
end.
-file("src/jsonlogic/internal/decoding.gleam", 32).
?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 => <<?FILEPATH/utf8>>,
module => <<"jsonlogic/internal/decoding"/utf8>>,
function => <<"decode_rule"/utf8>>,
line => 68})
end.
-file("src/jsonlogic/internal/decoding.gleam", 24).
?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).