-module(agnostic@internals@json_object_builder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/agnostic/internals/json_object_builder.gleam"). -export([new/0, json/3, tagged/1, build/1, string/3, int/3, bool/3, list/4, object/3]). -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( " This module contains helper functions for building up json objects using\n" " pipelines. This allows us to skip \"empty\" values, reducing payload size.\n" "\n" " It builds up a list of entries in reverse; but since we do not care about\n" " the order of our keys, we can just leave the list like it is.\n" ). -file("src/agnostic/internals/json_object_builder.gleam", 13). -spec new() -> list({binary(), gleam@json:json()}). new() -> []. -file("src/agnostic/internals/json_object_builder.gleam", 25). -spec json(list({binary(), gleam@json:json()}), binary(), gleam@json:json()) -> list({binary(), gleam@json:json()}). json(Entries, Key, Value) -> [{Key, Value} | Entries]. -file("src/agnostic/internals/json_object_builder.gleam", 17). -spec tagged(integer()) -> list({binary(), gleam@json:json()}). tagged(Kind) -> [{<<"kind"/utf8>>, gleam@json:int(Kind)}]. -file("src/agnostic/internals/json_object_builder.gleam", 21). -spec build(list({binary(), gleam@json:json()})) -> gleam@json:json(). build(Entries) -> gleam@json:object(Entries). -file("src/agnostic/internals/json_object_builder.gleam", 29). -spec string(list({binary(), gleam@json:json()}), binary(), binary()) -> list({binary(), gleam@json:json()}). string(Entries, Key, Value) -> case Value /= <<""/utf8>> of true -> [{Key, gleam@json:string(Value)} | Entries]; false -> Entries end. -file("src/agnostic/internals/json_object_builder.gleam", 36). -spec int(list({binary(), gleam@json:json()}), binary(), integer()) -> list({binary(), gleam@json:json()}). int(Entries, Key, Value) -> case Value /= 0 of true -> [{Key, gleam@json:int(Value)} | Entries]; false -> Entries end. -file("src/agnostic/internals/json_object_builder.gleam", 43). -spec bool(list({binary(), gleam@json:json()}), binary(), boolean()) -> list({binary(), gleam@json:json()}). bool(Entries, Key, Value) -> case Value of true -> [{Key, gleam@json:int(1)} | Entries]; false -> Entries end. -file("src/agnostic/internals/json_object_builder.gleam", 50). -spec list( list({binary(), gleam@json:json()}), binary(), list(FJO), fun((FJO) -> gleam@json:json()) ) -> list({binary(), gleam@json:json()}). list(Entries, Key, Values, To_json) -> case Values of [] -> Entries; _ -> [{Key, gleam@json:array(Values, To_json)} | Entries] end. -file("src/agnostic/internals/json_object_builder.gleam", 62). -spec object( list({binary(), gleam@json:json()}), binary(), list({binary(), gleam@json:json()}) ) -> list({binary(), gleam@json:json()}). object(Entries, Key, Nested) -> case Nested of [] -> Entries; _ -> [{Key, gleam@json:object(Nested)} | Entries] end.