-module(atproto_codegen@emit@exprs). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/atproto_codegen/emit/exprs.gleam"). -export([escape/1, type_uses_helper/1, type_uses_blob/1, type_uses_unknown/1, union_type_name/3, gleam_type/4, encoder_expr/4, decoder_expr/4, zero_expr/5]). -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( " Per-field expressions: the Gleam type, encoder, and decoder for one\n" " lexicon field type, plus the predicates the header/emission logic keys on.\n" ). -file("src/atproto_codegen/emit/exprs.gleam", 16). -spec escape(binary()) -> binary(). escape(Value) -> _pipe = Value, _pipe@1 = gleam@string:replace(_pipe, <<"\\"/utf8>>, <<"\\\\"/utf8>>), gleam@string:replace(_pipe@1, <<"\""/utf8>>, <<"\\\""/utf8>>). -file("src/atproto_codegen/emit/exprs.gleam", 23). ?DOC(" Only an open union pulls in the `internal` import.\n"). -spec type_uses_helper(atproto_codegen@lower:flat_type()) -> boolean(). type_uses_helper(Ft) -> case Ft of t_cid_link -> true; t_bytes -> true; t_unknown -> true; {t_union, _, Closed} -> not Closed; {t_array, Inner} -> type_uses_helper(Inner); _ -> false end. -file("src/atproto_codegen/emit/exprs.gleam", 32). -spec type_uses_blob(atproto_codegen@lower:flat_type()) -> boolean(). type_uses_blob(Ft) -> case Ft of t_blob -> true; {t_array, Inner} -> type_uses_blob(Inner); _ -> false end. -file("src/atproto_codegen/emit/exprs.gleam", 41). ?DOC(" Only an open union needs `dynamic` (Other variant, nil zero).\n"). -spec type_uses_unknown(atproto_codegen@lower:flat_type()) -> boolean(). type_uses_unknown(Ft) -> case Ft of t_unknown -> true; {t_union, _, Closed} -> not Closed; {t_array, Inner} -> type_uses_unknown(Inner); _ -> false end. -file("src/atproto_codegen/emit/exprs.gleam", 51). ?DOC(" The synthesized name for a property's inline union type.\n"). -spec union_type_name( atproto_codegen@config:config(), atproto_codegen@lower:flat_def(), atproto_codegen@lower:flat_field() ) -> binary(). union_type_name(Cfg, Def, Prop) -> <<(atproto_codegen@naming:def_type_name(erlang:element(5, Cfg), Def))/binary, (justin:pascal_case(erlang:element(2, Prop)))/binary>>. -file("src/atproto_codegen/emit/exprs.gleam", 55). -spec gleam_type( atproto_codegen@config:config(), binary(), binary(), atproto_codegen@lower:flat_type() ) -> binary(). gleam_type(Cfg, Current, Union_name, Ft) -> case Ft of t_string -> <<"String"/utf8>>; t_int -> <<"Int"/utf8>>; t_bool -> <<"Bool"/utf8>>; {t_ref, Ref} -> R = atproto_codegen@naming:parse_ref(Current, Ref), <<(atproto_codegen@naming:qualifier( erlang:element(5, Cfg), Current, erlang:element(2, R) ))/binary, (atproto_codegen@naming:ref_type_name(erlang:element(5, Cfg), R))/binary>>; {t_array, Inner} -> <<<<"List("/utf8, (gleam_type(Cfg, Current, Union_name, Inner))/binary>>/binary, ")"/utf8>>; t_cid_link -> <<"String"/utf8>>; t_bytes -> <<"BitArray"/utf8>>; t_blob -> <<"blob.Blob"/utf8>>; t_unknown -> <<"dynamic.Dynamic"/utf8>>; {t_union, _, _} -> Union_name; {t_unsupported, Kind} -> <<"Dynamic_"/utf8, Kind/binary>> end. -file("src/atproto_codegen/emit/exprs.gleam", 81). -spec encoder_expr( atproto_codegen@config:config(), binary(), binary(), atproto_codegen@lower:flat_type() ) -> binary(). encoder_expr(Cfg, Current, Union_name, Ft) -> case Ft of t_string -> <<"json.string"/utf8>>; t_int -> <<"json.int"/utf8>>; t_bool -> <<"json.bool"/utf8>>; {t_ref, Ref} -> R = atproto_codegen@naming:parse_ref(Current, Ref), <<<<(atproto_codegen@naming:qualifier( erlang:element(5, Cfg), Current, erlang:element(2, R) ))/binary, "encode_"/utf8>>/binary, (justin:snake_case( atproto_codegen@naming:ref_type_name( erlang:element(5, Cfg), R ) ))/binary>>; {t_array, Inner} -> <<<<"fn(items) { json.array(items, "/utf8, (encoder_expr(Cfg, Current, Union_name, Inner))/binary>>/binary, ") }"/utf8>>; t_cid_link -> <<"internal.encode_cid_link"/utf8>>; t_bytes -> <<"internal.encode_bytes"/utf8>>; t_blob -> <<"blob.encode_blob"/utf8>>; t_unknown -> <<"internal.dynamic_to_json"/utf8>>; {t_union, _, _} -> <<"encode_"/utf8, (justin:snake_case(Union_name))/binary>>; {t_unsupported, _} -> <<"json.string"/utf8>> end. -file("src/atproto_codegen/emit/exprs.gleam", 110). -spec decoder_expr( atproto_codegen@config:config(), binary(), binary(), atproto_codegen@lower:flat_type() ) -> binary(). decoder_expr(Cfg, Current, Union_name, Ft) -> case Ft of t_string -> <<"decode.string"/utf8>>; t_int -> <<"decode.int"/utf8>>; t_bool -> <<"decode.bool"/utf8>>; {t_ref, Ref} -> R = atproto_codegen@naming:parse_ref(Current, Ref), <<<<(atproto_codegen@naming:qualifier( erlang:element(5, Cfg), Current, erlang:element(2, R) ))/binary, (justin:snake_case( atproto_codegen@naming:ref_type_name( erlang:element(5, Cfg), R ) ))/binary>>/binary, "_decoder()"/utf8>>; {t_array, Inner} -> <<<<"decode.list("/utf8, (decoder_expr(Cfg, Current, Union_name, Inner))/binary>>/binary, ")"/utf8>>; t_cid_link -> <<"internal.cid_link_decoder()"/utf8>>; t_bytes -> <<"internal.bytes_decoder()"/utf8>>; t_blob -> <<"blob.blob_decoder()"/utf8>>; t_unknown -> <<"decode.dynamic"/utf8>>; {t_union, _, _} -> <<(justin:snake_case(Union_name))/binary, "_decoder()"/utf8>>; {t_unsupported, _} -> <<"decode.string"/utf8>> end. -file("src/atproto_codegen/emit/exprs.gleam", 138). ?DOC(" Zero for one field type; arrays/optionals never recurse.\n"). -spec zero_expr( atproto_codegen@emit@zero:zero_plan(), atproto_codegen@config:config(), binary(), binary(), atproto_codegen@lower:flat_type() ) -> binary(). zero_expr(Plan, Cfg, Current, Union_name, Ft) -> case Ft of t_string -> <<"\"\""/utf8>>; t_int -> <<"0"/utf8>>; t_bool -> <<"False"/utf8>>; {t_ref, Ref} -> R = atproto_codegen@naming:parse_ref(Current, Ref), <<<<(atproto_codegen@naming:qualifier( erlang:element(5, Cfg), Current, erlang:element(2, R) ))/binary, (justin:snake_case( atproto_codegen@naming:ref_type_name( erlang:element(5, Cfg), R ) ))/binary>>/binary, "_zero()"/utf8>>; {t_array, _} -> <<"[]"/utf8>>; t_cid_link -> <<"\"\""/utf8>>; t_bytes -> <<"<<>>"/utf8>>; t_blob -> <<"blob.Blob(\"\", \"\", 0)"/utf8>>; t_unknown -> <<"dynamic.nil()"/utf8>>; {t_union, _, false} -> <>; {t_union, Refs, true} -> Ref@2 = case atproto_codegen@emit@zero:choose_fallback( Plan, Current, Refs ) of {ok, Ref@1} -> Ref@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"atproto_codegen/emit/exprs"/utf8>>, function => <<"zero_expr"/utf8>>, line => 162, value => _assert_fail, start => 4392, 'end' => 4454, pattern_start => 4403, pattern_end => 4410}) end, R@1 = atproto_codegen@naming:parse_ref(Current, Ref@2), <<<<<<<>/binary, "("/utf8>>/binary, (zero_expr(Plan, Cfg, Current, Union_name, {t_ref, Ref@2}))/binary>>/binary, ")"/utf8>>; {t_unsupported, _} -> <<"dynamic.nil()"/utf8>> end.