-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( " The `types` plugin: for each codec unit (a def or a synthesized union\n" " field type), emits the Gleam type, the JSON-fields helper, and the\n" " `$type`-tagging encoder. Decoding is the `decode-json` plugin's job; the\n" " host interleaves the two so the assembled file matches the original\n" " monolithic emitter's ordering.\n" ). -file("src/atproto_codegen/plugins/types.gleam", 46). -spec render_unit( atproto_codegen@emit@zero:zero_plan(), atproto_codegen@config:config(), binary(), atproto_codegen@lower:codec_unit() ) -> binary(). render_unit(Plan, Cfg, Nsid, Unit) -> case Unit of {def_unit, Def} -> Name = atproto_codegen@naming:def_type_name( erlang:element(5, Cfg), Def ), Props = atproto_codegen@lower:properties_of(Def), Is_record = atproto_codegen@lower:is_record(Def), _pipe = [case Is_record of true -> [<<<<"pub const collection = \""/utf8, (atproto_codegen@emit@exprs:escape(Nsid))/binary>>/binary, "\""/utf8>>]; false -> [] end, [atproto_codegen@emit@def:emit_type( Cfg, Nsid, Def, Name, Props )], [atproto_codegen@emit@def:emit_fields( Cfg, Nsid, Def, Name, Props )], [atproto_codegen@emit@def:emit_encoder( Nsid, Name, Is_record )], case atproto_codegen@emit@zero:needs_zero(Plan, Def) of true -> [atproto_codegen@emit@def:emit_zero( Plan, Cfg, 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, Closed} -> Name@1 = atproto_codegen@emit@exprs:union_type_name( Cfg, Def@1, Field ), Parts = atproto_codegen@emit@union:emit_union( Plan, Cfg, Nsid, Name@1, Refs, Closed ), <<<<(erlang:element(2, Parts))/binary, "\n\n"/utf8>>/binary, (erlang:element(3, Parts))/binary>> end. -file("src/atproto_codegen/plugins/types.gleam", 27). -spec emit(atproto_codegen@plugin:plugin_context()) -> {ok, list(atproto_codegen@plugin:output_file())} | {error, atproto_codegen@plugin:codegen_error()}. emit(Ctx) -> case atproto_codegen@emit@zero:compute(erlang:element(4, Ctx)) of {error, Reason} -> {error, {plugin_failure, <<"types"/utf8>>, Reason}}; {ok, Plan} -> _pipe = erlang:element(4, Ctx), _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, Ctx) ), erlang:element(2, Lex) ))/binary, ".gleam"/utf8>>, gleam@list:map( Units, fun(_capture) -> render_unit( Plan, erlang:element(2, Ctx), erlang:element(2, Lex), _capture ) end )}} end end ), {ok, _pipe@1} end. -file("src/atproto_codegen/plugins/types.gleam", 23). -spec plugin() -> atproto_codegen@plugin:plugin(). plugin() -> {plugin, <<"types"/utf8>>, [], fun emit/1}.