Current section
Files
Jump to
Current section
Files
src/aion@awl@codec.erl
-module(aion@awl@codec).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/aion/awl/codec.gleam").
-export([string_codec/0, int_codec/0, float_codec/0, bool_codec/0, nil_codec/0, string_to_json/1, int_to_json/1, float_to_json/1, bool_to_json/1, nil_to_json/1, string_decoder/0, int_decoder/0, float_decoder/0, bool_decoder/0, nil_decoder/0, raw/0, decoded/3, json_value/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(
" Fixed codec glue hoisted out of every generated AWL module (AWL-BC-0,\n"
" hoist-only): the builtin leaf codecs (`String`/`Int`/`Float`/`Bool`/`Nil`),\n"
" the raw wire-passthrough codec heterogeneous parallel branches ride, the\n"
" per-branch decode helper, and the encode-only child-input codec.\n"
"\n"
" Generated per-type record/enum/union codecs stay in the emitted module and\n"
" reference these leaves qualified (`awlc.string_to_json`, …); the behavior is\n"
" byte-identical to the code the emitter used to inline.\n"
).
-file("src/aion/awl/codec.gleam", 18).
?DOC(" `String` codec.\n").
-spec string_codec() -> aion@codec:codec(binary()).
string_codec() ->
aion@codec:json_codec(
fun gleam@json:string/1,
{decoder, fun gleam@dynamic@decode:decode_string/1}
).
-file("src/aion/awl/codec.gleam", 23).
?DOC(" `Int` codec.\n").
-spec int_codec() -> aion@codec:codec(integer()).
int_codec() ->
aion@codec:json_codec(
fun gleam@json:int/1,
{decoder, fun gleam@dynamic@decode:decode_int/1}
).
-file("src/aion/awl/codec.gleam", 28).
?DOC(" `Float` codec.\n").
-spec float_codec() -> aion@codec:codec(float()).
float_codec() ->
aion@codec:json_codec(
fun gleam@json:float/1,
{decoder, fun gleam@dynamic@decode:decode_float/1}
).
-file("src/aion/awl/codec.gleam", 33).
?DOC(" `Bool` codec.\n").
-spec bool_codec() -> aion@codec:codec(boolean()).
bool_codec() ->
aion@codec:json_codec(
fun gleam@json:bool/1,
{decoder, fun gleam@dynamic@decode:decode_bool/1}
).
-file("src/aion/awl/codec.gleam", 38).
?DOC(" `Nil` codec: encodes `{}` and decodes accepting any value.\n").
-spec nil_codec() -> aion@codec:codec(nil).
nil_codec() ->
aion@codec:json_codec(
fun(_) -> gleam@json:object([]) end,
gleam@dynamic@decode:success(nil)
).
-file("src/aion/awl/codec.gleam", 43).
?DOC(" `String` JSON encoder.\n").
-spec string_to_json(binary()) -> gleam@json:json().
string_to_json(Value) ->
gleam@json:string(Value).
-file("src/aion/awl/codec.gleam", 48).
?DOC(" `Int` JSON encoder.\n").
-spec int_to_json(integer()) -> gleam@json:json().
int_to_json(Value) ->
gleam@json:int(Value).
-file("src/aion/awl/codec.gleam", 53).
?DOC(" `Float` JSON encoder.\n").
-spec float_to_json(float()) -> gleam@json:json().
float_to_json(Value) ->
gleam@json:float(Value).
-file("src/aion/awl/codec.gleam", 58).
?DOC(" `Bool` JSON encoder.\n").
-spec bool_to_json(boolean()) -> gleam@json:json().
bool_to_json(Value) ->
gleam@json:bool(Value).
-file("src/aion/awl/codec.gleam", 63).
?DOC(" `Nil` JSON encoder: the empty object.\n").
-spec nil_to_json(nil) -> gleam@json:json().
nil_to_json(_) ->
gleam@json:object([]).
-file("src/aion/awl/codec.gleam", 68).
?DOC(" `String` decoder.\n").
-spec string_decoder() -> gleam@dynamic@decode:decoder(binary()).
string_decoder() ->
{decoder, fun gleam@dynamic@decode:decode_string/1}.
-file("src/aion/awl/codec.gleam", 73).
?DOC(" `Int` decoder.\n").
-spec int_decoder() -> gleam@dynamic@decode:decoder(integer()).
int_decoder() ->
{decoder, fun gleam@dynamic@decode:decode_int/1}.
-file("src/aion/awl/codec.gleam", 78).
?DOC(" `Float` decoder.\n").
-spec float_decoder() -> gleam@dynamic@decode:decoder(float()).
float_decoder() ->
{decoder, fun gleam@dynamic@decode:decode_float/1}.
-file("src/aion/awl/codec.gleam", 83).
?DOC(" `Bool` decoder.\n").
-spec bool_decoder() -> gleam@dynamic@decode:decoder(boolean()).
bool_decoder() ->
{decoder, fun gleam@dynamic@decode:decode_bool/1}.
-file("src/aion/awl/codec.gleam", 88).
?DOC(" `Nil` decoder: succeeds on any value.\n").
-spec nil_decoder() -> gleam@dynamic@decode:decoder(nil).
nil_decoder() ->
gleam@dynamic@decode:success(nil).
-file("src/aion/awl/codec.gleam", 96).
?DOC(
" Identity codec: heterogeneous parallel branches ride `workflow.all` as raw\n"
" JSON payload strings, decoded per branch at the join with [`decoded`].\n"
).
-spec raw() -> aion@codec:codec(binary()).
raw() ->
{codec, fun(Payload) -> Payload end, fun(Payload@1) -> {ok, Payload@1} end}.
-file("src/aion/awl/codec.gleam", 104).
?DOC(
" Decode one parallel branch's payload with its action's return codec; a\n"
" decode failure becomes a step failure naming the action.\n"
).
-spec decoded(aion@codec:codec(EJP), binary(), binary()) -> {ok, EJP} |
{error, aion@awl@error:awl_error()}.
decoded(Item_codec, Payload, Action) ->
case (erlang:element(3, Item_codec))(Payload) of
{ok, Value} ->
{ok, Value};
{error, _} ->
{error, {awl_activity_failed, Action}}
end.
-file("src/aion/awl/codec.gleam", 117).
?DOC(
" Encode-only codec for child workflow inputs: the parent assembles the\n"
" child's input record as JSON and never decodes it back.\n"
).
-spec json_value() -> aion@codec:codec(gleam@json:json()).
json_value() ->
{codec,
fun gleam@json:to_string/1,
fun(_) ->
{error,
{decode_error, <<"child call input is encode-only"/utf8>>, []}}
end}.