Current section
Files
Jump to
Current section
Files
src/dagger@dsl@type_def.erl
-module(dagger@dsl@type_def).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dagger/dsl/type_def.gleam").
-export([none/1, description/2, source_map/2, value/2, deprecated/2, type_def/0, as_enum/1, as_input/1, as_interface/1, as_list/1, as_object/1, as_scalar/1, id/1, kind/3, optional/3, with_constructor/2, with_enum/3, with_enum_member/3, with_field/4, with_function/2, with_interface/3, with_kind/2, with_list_of/2, with_object/3, with_optional/2, with_scalar/3]).
-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(dagger@dsl@types:source_map()),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-file("src/dagger/dsl/type_def.gleam", 19).
-spec defaults() -> opts().
defaults() ->
{opts, none, none, none, none}.
-file("src/dagger/dsl/type_def.gleam", 28).
-spec none(opts()) -> opts().
none(Opts) ->
Opts.
-file("src/dagger/dsl/type_def.gleam", 32).
-spec description(opts(), binary()) -> opts().
description(Opts, Val) ->
{opts,
{some, Val},
erlang:element(3, Opts),
erlang:element(4, Opts),
erlang:element(5, Opts)}.
-file("src/dagger/dsl/type_def.gleam", 36).
-spec source_map(opts(), dagger@dsl@types:source_map()) -> opts().
source_map(Opts, Val) ->
{opts,
erlang:element(2, Opts),
{some, Val},
erlang:element(4, Opts),
erlang:element(5, Opts)}.
-file("src/dagger/dsl/type_def.gleam", 40).
-spec value(opts(), binary()) -> opts().
value(Opts, Val) ->
{opts,
erlang:element(2, Opts),
erlang:element(3, Opts),
{some, Val},
erlang:element(5, Opts)}.
-file("src/dagger/dsl/type_def.gleam", 44).
-spec deprecated(opts(), binary()) -> opts().
deprecated(Opts, Val) ->
{opts,
erlang:element(2, Opts),
erlang:element(3, Opts),
erlang:element(4, Opts),
{some, Val}}.
-file("src/dagger/dsl/type_def.gleam", 48).
-spec type_def() -> dagger@dsl@types:type_def().
type_def() ->
Field = {field, <<"currentTypeDefs"/utf8>>, [], []},
{type_def, {pure, [Field]}}.
-file("src/dagger/dsl/type_def.gleam", 54).
?DOC(" If kind is ENUM, the enum-specific type definition. If kind is not ENUM, this will be null.\n").
-spec as_enum(dagger@dsl@types:type_def()) -> dagger@dsl@types:enum_type_def().
as_enum(Parent) ->
Field = {field, <<"asEnum"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{enum_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 64).
?DOC(" If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null.\n").
-spec as_input(dagger@dsl@types:type_def()) -> dagger@dsl@types:input_type_def().
as_input(Parent) ->
Field = {field, <<"asInput"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{input_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 74).
?DOC(" If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null.\n").
-spec as_interface(dagger@dsl@types:type_def()) -> dagger@dsl@types:interface_type_def().
as_interface(Parent) ->
Field = {field, <<"asInterface"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{interface_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 84).
?DOC(" If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null.\n").
-spec as_list(dagger@dsl@types:type_def()) -> dagger@dsl@types:list_type_def().
as_list(Parent) ->
Field = {field, <<"asList"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{list_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 94).
?DOC(" If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null.\n").
-spec as_object(dagger@dsl@types:type_def()) -> dagger@dsl@types:object_type_def().
as_object(Parent) ->
Field = {field, <<"asObject"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{object_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 104).
?DOC(" If kind is SCALAR, the scalar-specific type definition. If kind is not SCALAR, this will be null.\n").
-spec as_scalar(dagger@dsl@types:type_def()) -> dagger@dsl@types:scalar_type_def().
as_scalar(Parent) ->
Field = {field, <<"asScalar"/utf8>>, [], []},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{scalar_type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 114).
?DOC(" A unique identifier for this TypeDef.\n").
-spec id(dagger@dsl@types:type_def()) -> dagger@dsl@types:type_def().
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,
{type_def, New_op}.
-file("src/dagger/dsl/type_def.gleam", 124).
?DOC(" The kind of type this is (e.g. primitive, list, object).\n").
-spec kind(
dagger@dsl@types:type_def(),
dagger@types:client(),
fun(({ok, dagger@dsl@types:type_def_kind()} |
{error, dagger@types:query_error()}) -> YTA)
) -> YTA.
kind(Parent, Client, Handler) ->
Field = {field, <<"kind"/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,
gleam@dynamic@decode:map(
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(S) ->
dagger@dsl@types:type_def_kind_from_string(
S
)
end
)
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error, {decoding_error, <<"kind"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/type_def.gleam", 145).
?DOC(" Whether this type can be set to null. Defaults to false.\n").
-spec optional(
dagger@dsl@types:type_def(),
dagger@types:client(),
fun(({ok, boolean()} | {error, dagger@types:query_error()}) -> YTC)
) -> YTC.
optional(Parent, Client, Handler) ->
Field = {field, <<"optional"/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_bool/1}
)
) of
{ok, Val} ->
{pure, {ok, Val}};
{error, _} ->
{pure,
{error,
{decoding_error, <<"optional"/utf8>>}}}
end
end}
end
)
end,
Handler(dagger@interpreter:run(Op, Client)).
-file("src/dagger/dsl/type_def.gleam", 166).
?DOC(" Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.\n").
-spec with_constructor(
dagger@dsl@types:type_def(),
dagger@dsl@types:function_()
) -> dagger@dsl@types:type_def().
with_constructor(Parent, Function) ->
Field = {field,
<<"withConstructor"/utf8>>,
[{<<"function"/utf8>>, {g_deferred, erlang:element(2, Function)}}],
[]},
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/type_def.gleam", 175).
-spec encode_with_enum(opts()) -> list({binary(), dagger@types:value()}).
encode_with_enum(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,
{<<"sourceMap"/utf8>>,
{g_deferred, erlang:element(2, Val@1)}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 190).
?DOC(
" Returns a TypeDef of kind Enum with the provided name.\n"
" Note that an enum's values may be omitted if the intent is only to refer to an enum. This is how functions are able to return their own, or any other circular reference.\n"
).
-spec with_enum(dagger@dsl@types:type_def(), binary(), fun((opts()) -> opts())) -> dagger@dsl@types:type_def().
with_enum(Parent, Name, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withEnum"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}}],
encode_with_enum(Opts)
),
[]},
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/type_def.gleam", 200).
-spec encode_with_enum_member(opts()) -> list({binary(), dagger@types:value()}).
encode_with_enum_member(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,
{<<"sourceMap"/utf8>>,
{g_deferred, erlang:element(2, Val@1)}}};
none ->
{error, nil}
end, case erlang:element(4, Opts) of
{some, Val@2} ->
{ok, {<<"value"/utf8>>, {g_string, Val@2}}};
none ->
{error, nil}
end, case erlang:element(5, Opts) of
{some, Val@3} ->
{ok, {<<"deprecated"/utf8>>, {g_string, Val@3}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 222).
?DOC(" Adds a static value for an Enum TypeDef, failing if the type is not an enum.\n").
-spec with_enum_member(
dagger@dsl@types:type_def(),
binary(),
fun((opts()) -> opts())
) -> dagger@dsl@types:type_def().
with_enum_member(Parent, Name, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withEnumMember"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}}],
encode_with_enum_member(Opts)
),
[]},
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/type_def.gleam", 232).
-spec encode_with_field(opts()) -> list({binary(), dagger@types:value()}).
encode_with_field(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,
{<<"sourceMap"/utf8>>,
{g_deferred, erlang:element(2, Val@1)}}};
none ->
{error, nil}
end, case erlang:element(5, Opts) of
{some, Val@2} ->
{ok, {<<"deprecated"/utf8>>, {g_string, Val@2}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 250).
?DOC(" Adds a static field for an Object TypeDef, failing if the type is not an object.\n").
-spec with_field(
dagger@dsl@types:type_def(),
binary(),
dagger@dsl@types:type_def(),
fun((opts()) -> opts())
) -> dagger@dsl@types:type_def().
with_field(Parent, Name, Type_def, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withField"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}},
{<<"typeDef"/utf8>>, {g_deferred, erlang:element(2, Type_def)}}],
encode_with_field(Opts)
),
[]},
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/type_def.gleam", 261).
?DOC(" Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.\n").
-spec with_function(dagger@dsl@types:type_def(), dagger@dsl@types:function_()) -> dagger@dsl@types:type_def().
with_function(Parent, Function) ->
Field = {field,
<<"withFunction"/utf8>>,
[{<<"function"/utf8>>, {g_deferred, erlang:element(2, Function)}}],
[]},
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/type_def.gleam", 270).
-spec encode_with_interface(opts()) -> list({binary(), dagger@types:value()}).
encode_with_interface(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,
{<<"sourceMap"/utf8>>,
{g_deferred, erlang:element(2, Val@1)}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 284).
?DOC(" Returns a TypeDef of kind Interface with the provided name.\n").
-spec with_interface(
dagger@dsl@types:type_def(),
binary(),
fun((opts()) -> opts())
) -> dagger@dsl@types:type_def().
with_interface(Parent, Name, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withInterface"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}}],
encode_with_interface(Opts)
),
[]},
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/type_def.gleam", 295).
?DOC(" Sets the kind of the type.\n").
-spec with_kind(dagger@dsl@types:type_def(), dagger@dsl@types:type_def_kind()) -> dagger@dsl@types:type_def().
with_kind(Parent, Kind) ->
Field = {field,
<<"withKind"/utf8>>,
[{<<"kind"/utf8>>,
{g_string, dagger@dsl@types:type_def_kind_to_json(Kind)}}],
[]},
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/type_def.gleam", 305).
?DOC(" Returns a TypeDef of kind List with the provided type for its elements.\n").
-spec with_list_of(dagger@dsl@types:type_def(), dagger@dsl@types:type_def()) -> dagger@dsl@types:type_def().
with_list_of(Parent, Element_type) ->
Field = {field,
<<"withListOf"/utf8>>,
[{<<"elementType"/utf8>>, {g_deferred, erlang:element(2, Element_type)}}],
[]},
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/type_def.gleam", 314).
-spec encode_with_object(opts()) -> list({binary(), dagger@types:value()}).
encode_with_object(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,
{<<"sourceMap"/utf8>>,
{g_deferred, erlang:element(2, Val@1)}}};
none ->
{error, nil}
end, case erlang:element(5, Opts) of
{some, Val@2} ->
{ok, {<<"deprecated"/utf8>>, {g_string, Val@2}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 333).
?DOC(
" Returns a TypeDef of kind Object with the provided name.\n"
" Note that an object's fields and functions may be omitted if the intent is only to refer to an object. This is how functions are able to return their own object, or any other circular reference.\n"
).
-spec with_object(
dagger@dsl@types:type_def(),
binary(),
fun((opts()) -> opts())
) -> dagger@dsl@types:type_def().
with_object(Parent, Name, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withObject"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}}],
encode_with_object(Opts)
),
[]},
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/type_def.gleam", 344).
?DOC(" Sets whether this type can be set to null.\n").
-spec with_optional(dagger@dsl@types:type_def(), boolean()) -> dagger@dsl@types:type_def().
with_optional(Parent, Optional) ->
Field = {field,
<<"withOptional"/utf8>>,
[{<<"optional"/utf8>>, {g_bool, Optional}}],
[]},
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/type_def.gleam", 353).
-spec encode_with_scalar(opts()) -> list({binary(), dagger@types:value()}).
encode_with_scalar(Opts) ->
gleam@list:filter_map([case erlang:element(2, Opts) of
{some, Val} ->
{ok, {<<"description"/utf8>>, {g_string, Val}}};
none ->
{error, nil}
end], fun(X) -> X end).
-file("src/dagger/dsl/type_def.gleam", 363).
?DOC(" Returns a TypeDef of kind Scalar with the provided name.\n").
-spec with_scalar(
dagger@dsl@types:type_def(),
binary(),
fun((opts()) -> opts())
) -> dagger@dsl@types:type_def().
with_scalar(Parent, Name, With_fn) ->
Opts = With_fn(defaults()),
Field = {field,
<<"withScalar"/utf8>>,
lists:append(
[{<<"name"/utf8>>, {g_string, Name}}],
encode_with_scalar(Opts)
),
[]},
New_op = begin
dagger@types:bind(
erlang:element(2, Parent),
fun(Q) -> {pure, lists:append(Q, [Field])} end
)
end,
{type_def, New_op}.