-module(dagger@dsl@function). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/dagger/dsl/function.gleam"). -export([none/1, opt_description/2, default_value/2, default_path/2, ignore/2, opt_source_map/2, opt_deprecated/2, default_address/2, time_to_live/2, reason/2, function/2, args/4, deprecated/3, description/3, id/1, name/3, return_type/1, source_map/1, with_arg/4, with_cache_policy/3, with_check/1, with_deprecated/2, with_description/2, with_generator/1, with_source_map/2]). -export_type([opts/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. -type opts() :: {opts, gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(list(binary())), gleam@option:option(dagger@dsl@types:source_map()), gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(binary())}. -file("src/dagger/dsl/function.gleam", 24). -spec defaults() -> opts(). defaults() -> {opts, none, none, none, none, none, none, none, none, none}. -file("src/dagger/dsl/function.gleam", 38). -spec none(opts()) -> opts(). none(Opts) -> Opts. -file("src/dagger/dsl/function.gleam", 42). -spec opt_description(opts(), binary()) -> opts(). opt_description(Opts, Val) -> {opts, {some, Val}, erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 46). -spec default_value(opts(), binary()) -> opts(). default_value(Opts, Val) -> {opts, erlang:element(2, Opts), {some, Val}, erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 50). -spec default_path(opts(), binary()) -> opts(). default_path(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), {some, Val}, erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 54). -spec ignore(opts(), list(binary())) -> opts(). ignore(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), {some, Val}, erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 58). -spec opt_source_map(opts(), dagger@dsl@types:source_map()) -> opts(). opt_source_map(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), {some, Val}, erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 62). -spec opt_deprecated(opts(), binary()) -> opts(). opt_deprecated(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), {some, Val}, erlang:element(8, Opts), erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 66). -spec default_address(opts(), binary()) -> opts(). default_address(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), {some, Val}, erlang:element(9, Opts), erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 70). -spec time_to_live(opts(), binary()) -> opts(). time_to_live(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), {some, Val}, erlang:element(10, Opts)}. -file("src/dagger/dsl/function.gleam", 74). -spec reason(opts(), binary()) -> opts(). reason(Opts, Val) -> {opts, erlang:element(2, Opts), erlang:element(3, Opts), erlang:element(4, Opts), erlang:element(5, Opts), erlang:element(6, Opts), erlang:element(7, Opts), erlang:element(8, Opts), erlang:element(9, Opts), {some, Val}}. -file("src/dagger/dsl/function.gleam", 78). -spec function(binary(), dagger@dsl@types:type_def()) -> dagger@dsl@types:function_(). function(Name, Return_type) -> Field = {field, <<"function"/utf8>>, [{<<"name"/utf8>>, {g_string, Name}}, {<<"returnType"/utf8>>, {g_deferred, erlang:element(2, Return_type)}}], []}, {function, {pure, [Field]}}. -file("src/dagger/dsl/function.gleam", 84). ?DOC(" Arguments accepted by the function, if any.\n"). -spec args( dagger@dsl@types:function_(), fun((dagger@dsl@types:function_arg()) -> list(dagger@types:field())), dagger@types:client(), fun(({ok, list(dagger@dsl@types:function_arg())} | {error, dagger@types:query_error()}) -> QTL) ) -> QTL. args(Parent, Select, Client, Handler) -> Subfields = Select({function_arg, {pure, []}}), Field = {field, <<"args"/utf8>>, [], Subfields}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_dynamic/1} ) ) ) of {ok, Items} -> {pure, {ok, gleam@list:map( Items, fun(_) -> {function_arg, {pure, Full_query}} end )}}; {error, _} -> {pure, {error, {decoding_error, <<"args"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/function.gleam", 106). ?DOC(" The reason this function is deprecated, if any.\n"). -spec deprecated( dagger@dsl@types:function_(), dagger@types:client(), fun(({ok, binary()} | {error, dagger@types:query_error()}) -> QTN) ) -> QTN. deprecated(Parent, Client, Handler) -> Field = {field, <<"deprecated"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"deprecated"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/function.gleam", 127). ?DOC(" A doc string for the function, if any.\n"). -spec description( dagger@dsl@types:function_(), dagger@types:client(), fun(({ok, binary()} | {error, dagger@types:query_error()}) -> QTP) ) -> QTP. description(Parent, Client, Handler) -> Field = {field, <<"description"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"description"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/function.gleam", 148). ?DOC(" A unique identifier for this Function.\n"). -spec id(dagger@dsl@types:function_()) -> dagger@dsl@types:function_(). id(Parent) -> Field = {field, <<"id"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 158). ?DOC(" The name of the function.\n"). -spec name( dagger@dsl@types:function_(), dagger@types:client(), fun(({ok, binary()} | {error, dagger@types:query_error()}) -> QTR) ) -> QTR. name(Parent, Client, Handler) -> Field = {field, <<"name"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"name"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/function.gleam", 179). ?DOC(" The type returned by the function.\n"). -spec return_type(dagger@dsl@types:function_()) -> dagger@dsl@types:type_def(). return_type(Parent) -> Field = {field, <<"returnType"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {type_def, New_op}. -file("src/dagger/dsl/function.gleam", 189). ?DOC(" The location of this function declaration.\n"). -spec source_map(dagger@dsl@types:function_()) -> dagger@dsl@types:source_map(). source_map(Parent) -> Field = {field, <<"sourceMap"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {source_map, New_op}. -file("src/dagger/dsl/function.gleam", 198). -spec encode_with_arg(opts()) -> list({binary(), dagger@types:value()}). encode_with_arg(Opts) -> gleam@list:filter_map([case erlang:element(2, Opts) of {some, Val} -> {ok, {<<"description"/utf8>>, {g_string, Val}}}; none -> {error, nil} end, case erlang:element(3, Opts) of {some, Val@1} -> {ok, {<<"defaultValue"/utf8>>, {g_string, Val@1}}}; none -> {error, nil} end, case erlang:element(4, Opts) of {some, Val@2} -> {ok, {<<"defaultPath"/utf8>>, {g_string, Val@2}}}; none -> {error, nil} end, case erlang:element(5, Opts) of {some, Val@3} -> {ok, {<<"ignore"/utf8>>, {g_list, gleam@list:map( Val@3, fun(X) -> {g_string, X} end )}}}; none -> {error, nil} end, case erlang:element(6, Opts) of {some, Val@4} -> {ok, {<<"sourceMap"/utf8>>, {g_deferred, erlang:element(2, Val@4)}}}; none -> {error, nil} end, case erlang:element(7, Opts) of {some, Val@5} -> {ok, {<<"deprecated"/utf8>>, {g_string, Val@5}}}; none -> {error, nil} end, case erlang:element(8, Opts) of {some, Val@6} -> {ok, {<<"defaultAddress"/utf8>>, {g_string, Val@6}}}; none -> {error, nil} end], fun(X@1) -> X@1 end). -file("src/dagger/dsl/function.gleam", 232). ?DOC(" Returns the function with the provided argument\n"). -spec with_arg( dagger@dsl@types:function_(), binary(), dagger@dsl@types:type_def(), fun((opts()) -> opts()) ) -> dagger@dsl@types:function_(). with_arg(Parent, Name, Type_def, With_fn) -> Opts = With_fn(defaults()), Field = {field, <<"withArg"/utf8>>, lists:append( [{<<"name"/utf8>>, {g_string, Name}}, {<<"typeDef"/utf8>>, {g_deferred, erlang:element(2, Type_def)}}], encode_with_arg(Opts) ), []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 242). -spec encode_with_cache_policy(opts()) -> list({binary(), dagger@types:value()}). encode_with_cache_policy(Opts) -> gleam@list:filter_map([case erlang:element(9, Opts) of {some, Val} -> {ok, {<<"timeToLive"/utf8>>, {g_string, Val}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/function.gleam", 252). ?DOC(" Returns the function updated to use the provided cache policy.\n"). -spec with_cache_policy( dagger@dsl@types:function_(), dagger@dsl@types:function_cache_policy(), fun((opts()) -> opts()) ) -> dagger@dsl@types:function_(). with_cache_policy(Parent, Policy, With_fn) -> Opts = With_fn(defaults()), Field = {field, <<"withCachePolicy"/utf8>>, lists:append( [{<<"policy"/utf8>>, {g_string, dagger@dsl@types:function_cache_policy_to_json(Policy)}}], encode_with_cache_policy(Opts) ), []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 263). ?DOC(" Returns the function with a flag indicating it's a check.\n"). -spec with_check(dagger@dsl@types:function_()) -> dagger@dsl@types:function_(). with_check(Parent) -> Field = {field, <<"withCheck"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 272). -spec encode_with_deprecated(opts()) -> list({binary(), dagger@types:value()}). encode_with_deprecated(Opts) -> gleam@list:filter_map([case erlang:element(10, Opts) of {some, Val} -> {ok, {<<"reason"/utf8>>, {g_string, Val}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/function.gleam", 282). ?DOC(" Returns the function with the provided deprecation reason.\n"). -spec with_deprecated(dagger@dsl@types:function_(), fun((opts()) -> opts())) -> dagger@dsl@types:function_(). with_deprecated(Parent, With_fn) -> Opts = With_fn(defaults()), Field = {field, <<"withDeprecated"/utf8>>, encode_with_deprecated(Opts), []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 293). ?DOC(" Returns the function with the given doc string.\n"). -spec with_description(dagger@dsl@types:function_(), binary()) -> dagger@dsl@types:function_(). with_description(Parent, Description) -> Field = {field, <<"withDescription"/utf8>>, [{<<"description"/utf8>>, {g_string, Description}}], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 303). ?DOC(" Returns the function with a flag indicating it's a generator.\n"). -spec with_generator(dagger@dsl@types:function_()) -> dagger@dsl@types:function_(). with_generator(Parent) -> Field = {field, <<"withGenerator"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}. -file("src/dagger/dsl/function.gleam", 313). ?DOC(" Returns the function with the given source map.\n"). -spec with_source_map( dagger@dsl@types:function_(), dagger@dsl@types:source_map() ) -> dagger@dsl@types:function_(). with_source_map(Parent, Source_map) -> Field = {field, <<"withSourceMap"/utf8>>, [{<<"sourceMap"/utf8>>, {g_deferred, erlang:element(2, Source_map)}}], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {function, New_op}.