-module(atproto_codegen@plugins@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/atproto_codegen/plugins/types.gleam"). -export([plugin/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. ?MODULEDOC(false). -file("src/atproto_codegen/plugins/types.gleam", 55). ?DOC(false). -spec render_unit( atproto_codegen@emit@zero:zero_plan(), atproto_codegen@config:config(), binary(), atproto_codegen@lower:codec_unit() ) -> binary(). render_unit(Plan, Config, Nsid, Unit) -> case Unit of {def_unit, Def} -> Name = atproto_codegen@naming:def_type_name( erlang:element(5, Config), Def ), Props = atproto_codegen@lower:emittable_properties(Def), _pipe = [case Def of {emittable_record, _, _} -> [<<<<"pub const collection = \""/utf8, (atproto_codegen@emit@exprs:escape(Nsid))/binary>>/binary, "\""/utf8>>]; {emittable_object, _, _, _} -> [] end, [atproto_codegen@emit@def:emit_type( Config, Nsid, Def, Name, Props )], [atproto_codegen@emit@def:emit_fields( Config, Nsid, Def, Name, Props )], [atproto_codegen@emit@def:emit_encoder(Nsid, Name, Def)], case atproto_codegen@emit@zero:needs_zero( Plan, Def ) of true -> [atproto_codegen@emit@def:emit_zero( Plan, Config, Nsid, Def, Name, Props )]; false -> [] end], _pipe@1 = lists:append(_pipe), gleam@string:join(_pipe@1, <<"\n\n"/utf8>>); {union_unit, Def@1, Field, Refs, Openness} -> Name@1 = atproto_codegen@emit@exprs:union_type_name( Config, Def@1, Field ), Parts = atproto_codegen@emit@union:emit_union( Plan, Config, Nsid, Name@1, Refs, Openness ), <<<<(erlang:element(2, Parts))/binary, "\n\n"/utf8>>/binary, (erlang:element(3, Parts))/binary>> end. -file("src/atproto_codegen/plugins/types.gleam", 27). ?DOC(false). -spec emit(atproto_codegen@plugin:plugin_context()) -> {ok, list(atproto_codegen@plugin:output_file())} | {error, atproto_codegen@plugin:codegen_error()}. emit(Context) -> case atproto_codegen@emit@zero:compute(erlang:element(4, Context)) of {error, Err} -> {error, {plugin_failure, <<"types"/utf8>>, atproto_codegen@emit@zero:error_to_string(Err)}}; {ok, Plan} -> _pipe = erlang:element(4, Context), _pipe@1 = gleam@list:filter_map( _pipe, fun(Lex) -> case atproto_codegen@lower:codec_units( erlang:element(4, Lex) ) of [] -> {error, nil}; Units -> {ok, {output_file, <<(atproto_codegen@naming:module_subpath( erlang:element( 5, erlang:element(2, Context) ), erlang:element(2, Lex) ))/binary, ".gleam"/utf8>>, gleam@list:map( Units, fun(_capture) -> render_unit( Plan, erlang:element(2, Context), erlang:element(2, Lex), _capture ) end )}} end end ), {ok, _pipe@1} end. -file("src/atproto_codegen/plugins/types.gleam", 23). ?DOC(false). -spec plugin() -> atproto_codegen@plugin:plugin(). plugin() -> {plugin, <<"types"/utf8>>, [], fun emit/1}.