Current section
Files
Jump to
Current section
Files
src/json@blueprint.erl
-module(json@blueprint).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([generate_json_schema/1, get_dynamic_decoder/1, decode/2, string/0, int/0, float/0, bool/0, list/1, optional/1, field/2, optional_field/2, union_type_encoder/2, union_type_decoder/1, tuple2/2, tuple3/3, tuple4/4, tuple5/5, tuple6/6, decode1/2, decode2/3, decode3/4]).
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 14).
-spec generate_json_schema(
{fun((gleam@dynamic:dynamic_()) -> {ok, any()} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> gleam@json:json().
generate_json_schema(Decoder) ->
{_, Schema} = Decoder,
json@blueprint@schema:to_json(json@blueprint@schema:new_schema(Schema)).
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 19).
-spec get_dynamic_decoder(
{fun((gleam@dynamic:dynamic_()) -> {ok, GGV} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> fun((gleam@dynamic:dynamic_()) -> {ok, GGV} |
{error, list(gleam@dynamic:decode_error())}).
get_dynamic_decoder(Decoder) ->
{Dyn_decoder, _} = Decoder,
Dyn_decoder.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 24).
-spec decode(
{fun((gleam@dynamic:dynamic_()) -> {ok, GGY} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
binary()
) -> {ok, GGY} | {error, gleam@json:decode_error()}.
decode(Decoder, Json_string) ->
{Dyn_decoder, _} = Decoder,
gleam@json:decode(Json_string, Dyn_decoder).
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 32).
-spec string() -> {fun((gleam@dynamic:dynamic_()) -> {ok, binary()} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
string() ->
{fun gleam@dynamic:string/1, {type, string_type}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 36).
-spec int() -> {fun((gleam@dynamic:dynamic_()) -> {ok, integer()} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
int() ->
{fun gleam@dynamic:int/1, {type, integer_type}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 40).
-spec float() -> {fun((gleam@dynamic:dynamic_()) -> {ok, float()} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
float() ->
{fun gleam@dynamic:float/1, {type, number_type}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 44).
-spec bool() -> {fun((gleam@dynamic:dynamic_()) -> {ok, boolean()} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
bool() ->
{fun gleam@dynamic:bool/1, {type, boolean_type}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 48).
-spec list(
{fun((gleam@dynamic:dynamic_()) -> {ok, GHG} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, list(GHG)} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
list(Decoder_type) ->
{Decoder, Schema} = Decoder_type,
{gleam@dynamic:list(Decoder), {array, {some, Schema}}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 53).
-spec optional(
{fun((gleam@dynamic:dynamic_()) -> {ok, GHK} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, gleam@option:option(GHK)} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
optional(Decode) ->
{Decoder, Schema} = Decode,
{gleam@dynamic:optional(Decoder), {nullable, Schema}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 58).
-spec field(
binary(),
{fun((gleam@dynamic:dynamic_()) -> {ok, GHO} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, GHO} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}}.
field(Name, Inner_type) ->
{Decoder, Schema} = Inner_type,
{gleam@dynamic:field(Name, Decoder), {Name, Schema}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 63).
-spec optional_field(
binary(),
{fun((gleam@dynamic:dynamic_()) -> {ok, GHR} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, gleam@option:option(GHR)} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}}.
optional_field(Name, Inner_type) ->
{Decoder, Schema} = Inner_type,
{gleam@dynamic:optional_field(Name, Decoder), {Name, {nullable, Schema}}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 99).
-spec union_type_encoder(GHV, fun((GHV) -> {binary(), gleam@json:json()})) -> gleam@json:json().
union_type_encoder(Of, Encoder_fn) ->
{Field_name, Json_value} = Encoder_fn(Of),
gleam@json:object(
[{<<"type"/utf8>>, gleam@json:string(Field_name)},
{<<"data"/utf8>>, Json_value}]
).
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 129).
-spec union_type_decoder(
list({binary(),
{fun((gleam@dynamic:dynamic_()) -> {ok, GHW} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}})
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, GHW} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
union_type_decoder(Decoders) ->
Constructor = fun(Type_str, Data) -> _pipe = Decoders,
_pipe@1 = gleam@list:find_map(_pipe, fun(Dec) -> case Dec of
{Name, D} when Type_str =:= Name ->
{Dyn_decoder, _} = D,
Dyn_decoder(Data);
_ ->
{error, []}
end end),
gleam@result:replace_error(
_pipe@1,
[{decode_error, <<"valid constructor type"/utf8>>, Type_str, []}]
) end,
Enum_decoder = fun(Data@1) ->
_pipe@2 = (gleam@dynamic:decode2(
Constructor,
gleam@dynamic:field(<<"type"/utf8>>, fun gleam@dynamic:string/1),
gleam@dynamic:field(<<"data"/utf8>>, fun gleam@dynamic:dynamic/1)
))(Data@1),
gleam@result:flatten(_pipe@2)
end,
{Enum_decoder,
begin
_pipe@3 = gleam@list:map(
Decoders,
fun(Field_dec) ->
{Name@1, Dec@1} = Field_dec,
{object,
[{<<"type"/utf8>>, {enum, [gleam@json:string(Name@1)]}},
{<<"data"/utf8>>, erlang:element(2, Dec@1)}],
{some, false},
{some, [<<"type"/utf8>>, <<"data"/utf8>>]}}
end
),
{one_of, _pipe@3}
end}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 178).
-spec tuple2(
{fun((gleam@dynamic:dynamic_()) -> {ok, GIA} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIC} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, {GIA, GIC}} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
tuple2(Decode1, Decode2) ->
{Decoder1, Schema1} = Decode1,
{Decoder2, Schema2} = Decode2,
{gleam@dynamic:tuple2(Decoder1, Decoder2),
{detailed_array,
none,
{some, [Schema1, Schema2]},
{some, 2},
{some, 2},
none,
none,
none,
none}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 199).
-spec tuple3(
{fun((gleam@dynamic:dynamic_()) -> {ok, GIF} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIH} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIJ} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, {GIF, GIH, GIJ}} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
tuple3(Decode1, Decode2, Decode3) ->
{Decoder1, Schema1} = Decode1,
{Decoder2, Schema2} = Decode2,
{Decoder3, Schema3} = Decode3,
{gleam@dynamic:tuple3(Decoder1, Decoder2, Decoder3),
{detailed_array,
none,
{some, [Schema1, Schema2, Schema3]},
{some, 3},
{some, 3},
none,
none,
none,
none}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 222).
-spec tuple4(
{fun((gleam@dynamic:dynamic_()) -> {ok, GIM} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIO} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIQ} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIS} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, {GIM, GIO, GIQ, GIS}} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
tuple4(Decode1, Decode2, Decode3, Decode4) ->
{Decoder1, Schema1} = Decode1,
{Decoder2, Schema2} = Decode2,
{Decoder3, Schema3} = Decode3,
{Decoder4, Schema4} = Decode4,
{gleam@dynamic:tuple4(Decoder1, Decoder2, Decoder3, Decoder4),
{detailed_array,
none,
{some, [Schema1, Schema2, Schema3, Schema4]},
{some, 4},
{some, 4},
none,
none,
none,
none}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 247).
-spec tuple5(
{fun((gleam@dynamic:dynamic_()) -> {ok, GIV} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIX} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GIZ} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJB} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJD} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, {GIV, GIX, GIZ, GJB, GJD}} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
tuple5(Decode1, Decode2, Decode3, Decode4, Decode5) ->
{Decoder1, Schema1} = Decode1,
{Decoder2, Schema2} = Decode2,
{Decoder3, Schema3} = Decode3,
{Decoder4, Schema4} = Decode4,
{Decoder5, Schema5} = Decode5,
{gleam@dynamic:tuple5(Decoder1, Decoder2, Decoder3, Decoder4, Decoder5),
{detailed_array,
none,
{some, [Schema1, Schema2, Schema3, Schema4, Schema5]},
{some, 5},
{some, 5},
none,
none,
none,
none}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 274).
-spec tuple6(
{fun((gleam@dynamic:dynamic_()) -> {ok, GJG} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJI} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJK} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJM} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJO} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJQ} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, {GJG, GJI, GJK, GJM, GJO, GJQ}} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
tuple6(Decode1, Decode2, Decode3, Decode4, Decode5, Decode6) ->
{Decoder1, Schema1} = Decode1,
{Decoder2, Schema2} = Decode2,
{Decoder3, Schema3} = Decode3,
{Decoder4, Schema4} = Decode4,
{Decoder5, Schema5} = Decode5,
{Decoder6, Schema6} = Decode6,
{gleam@dynamic:tuple6(
Decoder1,
Decoder2,
Decoder3,
Decoder4,
Decoder5,
Decoder6
),
{detailed_array,
none,
{some, [Schema1, Schema2, Schema3, Schema4, Schema5, Schema6]},
{some, 6},
{some, 6},
none,
none,
none,
none}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 303).
-spec create_object_schema(
list({binary(), json@blueprint@schema:schema_definition()})
) -> json@blueprint@schema:schema_definition().
create_object_schema(Fields) ->
{object,
Fields,
{some, false},
{some, gleam@list:filter_map(Fields, fun(Field_dec) -> case Field_dec of
{_, {nullable, _}} ->
{error, nil};
{Name, _} ->
{ok, Name}
end end)}}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 320).
-spec decode1(
fun((GJU) -> GJV),
{fun((gleam@dynamic:dynamic_()) -> {ok, GJU} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, GJV} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
decode1(Constructor, T1) ->
{Decoder, Schema} = T1,
{gleam@dynamic:decode1(Constructor, Decoder),
create_object_schema([Schema])}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 325).
-spec decode2(
fun((GJY, GJZ) -> GKA),
{fun((gleam@dynamic:dynamic_()) -> {ok, GJY} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}},
{fun((gleam@dynamic:dynamic_()) -> {ok, GJZ} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, GKA} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
decode2(Constructor, T1, T2) ->
{Decoder1, Schema1} = T1,
{Decoder2, Schema2} = T2,
{gleam@dynamic:decode2(Constructor, Decoder1, Decoder2),
create_object_schema([Schema1, Schema2])}.
-file("/code/edgar/gleamplay/src/json/blueprint.gleam", 338).
-spec decode3(
fun((GKE, GKF, GKG) -> GKH),
{fun((gleam@dynamic:dynamic_()) -> {ok, GKE} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}},
{fun((gleam@dynamic:dynamic_()) -> {ok, GKF} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}},
{fun((gleam@dynamic:dynamic_()) -> {ok, GKG} |
{error, list(gleam@dynamic:decode_error())}),
{binary(), json@blueprint@schema:schema_definition()}}
) -> {fun((gleam@dynamic:dynamic_()) -> {ok, GKH} |
{error, list(gleam@dynamic:decode_error())}),
json@blueprint@schema:schema_definition()}.
decode3(Constructor, T1, T2, T3) ->
{Decoder1, Schema1} = T1,
{Decoder2, Schema2} = T2,
{Decoder3, Schema3} = T3,
{gleam@dynamic:decode3(Constructor, Decoder1, Decoder2, Decoder3),
create_object_schema([Schema1, Schema2, Schema3])}.