From a895daa5d06b0546e18ce6ff822604d545fd43a4 Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Mon, 13 Nov 2023 22:50:34 +0700 Subject: [PATCH] feat(sdk/elixir): rework on Elixir codegen Signed-off-by: Thanabodee Charoenpiriyakij --- internal/mage/sdk/elixir.go | 31 +- sdk/elixir/dagger_codegen/.formatter.exs | 4 + sdk/elixir/dagger_codegen/.gitignore | 29 + sdk/elixir/dagger_codegen/README.md | 12 + .../dagger_codegen/lib/dagger/codegen.ex | 9 + .../dagger_codegen/lib/dagger/codegen/cli.ex | 51 + .../lib/dagger/codegen/elixir_generator.ex | 49 + .../codegen/elixir_generator/formatter.ex | 152 ++ .../elixir_generator/object_renderer.ex | 180 ++ .../codegen/elixir_generator/renderer.ex | 81 + .../codegen/introspection/types/enum_value.ex | 13 + .../codegen/introspection/types/field.ex | 24 + .../introspection/types/input_field.ex | 16 + .../codegen/introspection/types/query_type.ex | 4 + .../codegen/introspection/types/schema.ex | 25 + .../codegen/introspection/types/type.ex | 55 + .../codegen/introspection/types/type_ref.ex | 58 + .../dagger/codegen/introspection/visitor.ex | 43 + sdk/elixir/dagger_codegen/mix.exs | 31 + sdk/elixir/dagger_codegen/mix.lock | 17 + .../dagger_codegen/priv/introspection.graphql | 99 + .../priv/templates/elixir/enum.eex | 15 + .../priv/templates/elixir/input.eex | 15 + .../priv/templates/elixir/object.eex | 53 + .../priv/templates/elixir/scalar.eex | 9 + .../priv/templates/elixir/simple_object.eex | 23 + .../elixir_generator/formatter_test.exs | 98 + .../dagger/codegen/elixir_generator_test.exs | 442 ++++ .../test/dagger/codegen_test.exs | 4 + .../dagger_codegen/test/test_helper.exs | 1 + sdk/elixir/lib/dagger/codegen/compiler.ex | 62 - .../lib/dagger/codegen/elixir/function.ex | 119 - .../lib/dagger/codegen/elixir/module.ex | 50 - .../codegen/elixir/templates/enum_tmpl.ex | 60 - .../codegen/elixir/templates/input_tmpl.ex | 61 - .../codegen/elixir/templates/object_tmpl.ex | 563 ----- .../codegen/elixir/templates/scalar_tmpl.ex | 23 - sdk/elixir/lib/dagger/codegen/elixir/type.ex | 61 - sdk/elixir/lib/dagger/codegen/generator.ex | 12 - .../lib/dagger/codegen/introspection.ex | 14 - sdk/elixir/lib/dagger/core/query_builder.ex | 32 +- sdk/elixir/lib/dagger/gen/boolean.ex | 5 - sdk/elixir/lib/dagger/gen/build_arg.ex | 10 +- sdk/elixir/lib/dagger/gen/cache_id.ex | 5 - .../lib/dagger/gen/cache_sharing_mode.ex | 36 +- sdk/elixir/lib/dagger/gen/cache_volume.ex | 25 +- sdk/elixir/lib/dagger/gen/cache_volume_id.ex | 3 +- sdk/elixir/lib/dagger/gen/client.ex | 1391 ++++++----- sdk/elixir/lib/dagger/gen/container.ex | 2161 ++++++++--------- sdk/elixir/lib/dagger/gen/container_id.ex | 3 +- sdk/elixir/lib/dagger/gen/current_module.ex | 114 +- .../lib/dagger/gen/current_module_id.ex | 3 +- sdk/elixir/lib/dagger/gen/date_time.ex | 5 - sdk/elixir/lib/dagger/gen/directory.ex | 593 ++--- sdk/elixir/lib/dagger/gen/directory_id.ex | 3 +- sdk/elixir/lib/dagger/gen/env_variable.ex | 61 +- sdk/elixir/lib/dagger/gen/env_variable_id.ex | 3 +- sdk/elixir/lib/dagger/gen/field_type_def.ex | 88 +- .../lib/dagger/gen/field_type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/file.ex | 150 +- sdk/elixir/lib/dagger/gen/file_id.ex | 3 +- sdk/elixir/lib/dagger/gen/float.ex | 5 - sdk/elixir/lib/dagger/gen/function.ex | 198 +- sdk/elixir/lib/dagger/gen/function_arg.ex | 106 +- sdk/elixir/lib/dagger/gen/function_arg_id.ex | 3 +- sdk/elixir/lib/dagger/gen/function_call.ex | 136 +- .../lib/dagger/gen/function_call_arg_value.ex | 61 +- .../dagger/gen/function_call_arg_value_id.ex | 3 +- sdk/elixir/lib/dagger/gen/function_call_id.ex | 3 +- .../lib/dagger/gen/function_call_input.ex | 7 - sdk/elixir/lib/dagger/gen/function_id.ex | 3 +- sdk/elixir/lib/dagger/gen/generated_code.ex | 126 +- .../lib/dagger/gen/generated_code_id.ex | 3 +- sdk/elixir/lib/dagger/gen/git_module_ref.ex | 61 - .../lib/dagger/gen/git_module_ref_id.ex | 5 - .../lib/dagger/gen/git_module_source.ex | 136 +- .../lib/dagger/gen/git_module_source_id.ex | 3 +- sdk/elixir/lib/dagger/gen/git_ref.ex | 86 +- sdk/elixir/lib/dagger/gen/git_ref_id.ex | 3 +- sdk/elixir/lib/dagger/gen/git_repository.ex | 113 +- .../lib/dagger/gen/git_repository_id.ex | 3 +- sdk/elixir/lib/dagger/gen/host.ex | 219 +- sdk/elixir/lib/dagger/gen/host_id.ex | 3 +- sdk/elixir/lib/dagger/gen/host_variable.ex | 7 - sdk/elixir/lib/dagger/gen/id.ex | 5 - .../lib/dagger/gen/image_layer_compression.ex | 42 +- .../lib/dagger/gen/image_media_types.ex | 24 +- sdk/elixir/lib/dagger/gen/input_type_def.ex | 88 +- .../lib/dagger/gen/input_type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/int.ex | 5 - .../lib/dagger/gen/interactive_shell.ex | 25 - .../lib/dagger/gen/interactive_shell_id.ex | 5 - .../lib/dagger/gen/interface_type_def.ex | 117 +- .../lib/dagger/gen/interface_type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/json.ex | 3 +- sdk/elixir/lib/dagger/gen/label.ex | 61 +- sdk/elixir/lib/dagger/gen/label_id.ex | 3 +- sdk/elixir/lib/dagger/gen/list_type_def.ex | 46 +- sdk/elixir/lib/dagger/gen/list_type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/local_module_ref.ex | 25 - .../lib/dagger/gen/local_module_ref_id.ex | 5 - .../lib/dagger/gen/local_module_source.ex | 64 +- .../lib/dagger/gen/local_module_source_id.ex | 3 +- sdk/elixir/lib/dagger/gen/module.ex | 475 ++-- sdk/elixir/lib/dagger/gen/module_config.ex | 70 - sdk/elixir/lib/dagger/gen/module_config_id.ex | 5 - .../lib/dagger/gen/module_dependency.ex | 64 +- .../lib/dagger/gen/module_dependency_id.ex | 3 +- .../dagger/gen/module_environment_variable.ex | 7 - sdk/elixir/lib/dagger/gen/module_id.ex | 3 +- sdk/elixir/lib/dagger/gen/module_ref.ex | 80 - sdk/elixir/lib/dagger/gen/module_ref_id.ex | 5 - sdk/elixir/lib/dagger/gen/module_ref_kind.ex | 20 - sdk/elixir/lib/dagger/gen/module_source.ex | 479 ++-- sdk/elixir/lib/dagger/gen/module_source_id.ex | 3 +- .../lib/dagger/gen/module_source_kind.ex | 24 +- sdk/elixir/lib/dagger/gen/network_protocol.ex | 22 +- sdk/elixir/lib/dagger/gen/object_type_def.ex | 181 +- .../lib/dagger/gen/object_type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/pipeline_label.ex | 10 +- sdk/elixir/lib/dagger/gen/platform.ex | 9 +- sdk/elixir/lib/dagger/gen/port.ex | 97 +- sdk/elixir/lib/dagger/gen/port_forward.ex | 9 +- sdk/elixir/lib/dagger/gen/port_id.ex | 3 +- sdk/elixir/lib/dagger/gen/project.ex | 50 - sdk/elixir/lib/dagger/gen/project_command.ex | 61 - .../lib/dagger/gen/project_command_flag.ex | 7 - .../lib/dagger/gen/project_command_id.ex | 5 - sdk/elixir/lib/dagger/gen/project_id.ex | 5 - sdk/elixir/lib/dagger/gen/secret.ex | 43 +- sdk/elixir/lib/dagger/gen/secret_id.ex | 3 +- sdk/elixir/lib/dagger/gen/service.ex | 209 +- sdk/elixir/lib/dagger/gen/service_id.ex | 3 +- sdk/elixir/lib/dagger/gen/socket.ex | 25 +- sdk/elixir/lib/dagger/gen/socket_id.ex | 3 +- sdk/elixir/lib/dagger/gen/string.ex | 5 - sdk/elixir/lib/dagger/gen/terminal.ex | 43 +- sdk/elixir/lib/dagger/gen/terminal_id.ex | 3 +- sdk/elixir/lib/dagger/gen/type_def.ex | 404 ++- sdk/elixir/lib/dagger/gen/type_def_id.ex | 3 +- sdk/elixir/lib/dagger/gen/type_def_kind.ex | 108 +- sdk/elixir/lib/dagger/gen/void.ex | 9 +- sdk/elixir/lib/dagger/id.ex | 34 + sdk/elixir/scripts/fetch_introspection.exs | 4 + sdk/elixir/test/dagger/client_test.exs | 12 +- .../dagger/codegen/elixir/function_test.exs | 179 -- 146 files changed, 5986 insertions(+), 5992 deletions(-) create mode 100644 sdk/elixir/dagger_codegen/.formatter.exs create mode 100644 sdk/elixir/dagger_codegen/.gitignore create mode 100644 sdk/elixir/dagger_codegen/README.md create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/cli.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/formatter.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/object_renderer.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/renderer.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/enum_value.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/field.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/input_field.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/query_type.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/schema.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type_ref.ex create mode 100644 sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/visitor.ex create mode 100644 sdk/elixir/dagger_codegen/mix.exs create mode 100644 sdk/elixir/dagger_codegen/mix.lock create mode 100644 sdk/elixir/dagger_codegen/priv/introspection.graphql create mode 100644 sdk/elixir/dagger_codegen/priv/templates/elixir/enum.eex create mode 100644 sdk/elixir/dagger_codegen/priv/templates/elixir/input.eex create mode 100644 sdk/elixir/dagger_codegen/priv/templates/elixir/object.eex create mode 100644 sdk/elixir/dagger_codegen/priv/templates/elixir/scalar.eex create mode 100644 sdk/elixir/dagger_codegen/priv/templates/elixir/simple_object.eex create mode 100644 sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator/formatter_test.exs create mode 100644 sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator_test.exs create mode 100644 sdk/elixir/dagger_codegen/test/dagger/codegen_test.exs create mode 100644 sdk/elixir/dagger_codegen/test/test_helper.exs delete mode 100644 sdk/elixir/lib/dagger/codegen/compiler.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/function.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/module.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/templates/enum_tmpl.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/templates/input_tmpl.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/templates/object_tmpl.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/templates/scalar_tmpl.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/elixir/type.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/generator.ex delete mode 100644 sdk/elixir/lib/dagger/codegen/introspection.ex delete mode 100644 sdk/elixir/lib/dagger/gen/boolean.ex delete mode 100644 sdk/elixir/lib/dagger/gen/cache_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/date_time.ex delete mode 100644 sdk/elixir/lib/dagger/gen/float.ex delete mode 100644 sdk/elixir/lib/dagger/gen/function_call_input.ex delete mode 100644 sdk/elixir/lib/dagger/gen/git_module_ref.ex delete mode 100644 sdk/elixir/lib/dagger/gen/git_module_ref_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/host_variable.ex delete mode 100644 sdk/elixir/lib/dagger/gen/id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/int.ex delete mode 100644 sdk/elixir/lib/dagger/gen/interactive_shell.ex delete mode 100644 sdk/elixir/lib/dagger/gen/interactive_shell_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/local_module_ref.ex delete mode 100644 sdk/elixir/lib/dagger/gen/local_module_ref_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_config.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_config_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_environment_variable.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_ref.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_ref_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/module_ref_kind.ex delete mode 100644 sdk/elixir/lib/dagger/gen/project.ex delete mode 100644 sdk/elixir/lib/dagger/gen/project_command.ex delete mode 100644 sdk/elixir/lib/dagger/gen/project_command_flag.ex delete mode 100644 sdk/elixir/lib/dagger/gen/project_command_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/project_id.ex delete mode 100644 sdk/elixir/lib/dagger/gen/string.ex create mode 100644 sdk/elixir/lib/dagger/id.ex create mode 100644 sdk/elixir/scripts/fetch_introspection.exs delete mode 100644 sdk/elixir/test/dagger/codegen/elixir/function_test.exs diff --git a/internal/mage/sdk/elixir.go b/internal/mage/sdk/elixir.go index 43f52823beb..e41ace1e81d 100644 --- a/internal/mage/sdk/elixir.go +++ b/internal/mage/sdk/elixir.go @@ -21,11 +21,11 @@ const ( ) // https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=debian-buster -var elixirVersions = []string{"1.14.5", "1.15.4"} +var elixirVersions = []string{"1.16.0", "1.15.7", "1.14.5"} const ( - otpVersion = "25.3.2.4" - debianVersion = "20230612" + otpVersion = "26.2.1" + debianVersion = "20231009" ) var _ SDK = Elixir{} @@ -124,19 +124,28 @@ func (Elixir) Generate(ctx context.Context) error { cliBinPath := "/.dagger-cli" - generated := elixirBase(c, elixirVersions[1]). + generated, err := elixirBase(c, elixirVersions[0]). WithServiceBinding("dagger-engine", devEngine). WithEnvVariable("_EXPERIMENTAL_DAGGER_RUNNER_HOST", endpoint). WithMountedFile(cliBinPath, util.DevelDaggerBinary(ctx, c)). WithEnvVariable("_EXPERIMENTAL_DAGGER_CLI_BIN", cliBinPath). - WithExec([]string{"mix", "dagger.gen"}) + WithExec([]string{"mix", "run", "scripts/fetch_introspection.exs"}). + WithWorkdir("dagger_codegen"). + WithExec([]string{"mix", "deps.get"}). + WithExec([]string{"mix", "escript.build"}). + WithExec([]string{"./dagger_codegen", "generate", "--introspection", "../introspection.json", "--outdir", "gen"}). + WithExec([]string{"mix", "format", "gen/*.ex"}). + Sync(ctx) + if err != nil { + return err + } if err := os.RemoveAll(elixirSDKGeneratedPath); err != nil { return err } ok, err := generated. - Directory(strings.Replace(elixirSDKGeneratedPath, elixirSDKPath+"/", "", 1)). + Directory("gen"). Export(ctx, elixirSDKGeneratedPath) if err != nil { return err @@ -206,16 +215,12 @@ func (Elixir) Bump(ctx context.Context, engineVersion string) error { } func elixirBase(c *dagger.Client, elixirVersion string) *dagger.Container { - const appDir = "sdk/elixir" - - src := c.Directory().WithDirectory("/", util.Repository(c).Directory(appDir)) - - mountPath := fmt.Sprintf("/%s", appDir) + mountPath := fmt.Sprintf("/%s", elixirSDKPath) return c.Container(). - From(fmt.Sprintf("hexpm/elixir:%s-erlang-%s-debian-buster-%s-slim", elixirVersion, otpVersion, debianVersion)). + From(fmt.Sprintf("hexpm/elixir:%s-erlang-%s-debian-bookworm-%s-slim", elixirVersion, otpVersion, debianVersion)). WithWorkdir(mountPath). - WithDirectory(mountPath, src). + WithDirectory(mountPath, c.Directory().WithDirectory("/", util.Repository(c).Directory(elixirSDKPath))). WithExec([]string{"mix", "local.hex", "--force"}). WithExec([]string{"mix", "local.rebar", "--force"}). WithExec([]string{"mix", "deps.get"}) diff --git a/sdk/elixir/dagger_codegen/.formatter.exs b/sdk/elixir/dagger_codegen/.formatter.exs new file mode 100644 index 00000000000..d2cda26eddc --- /dev/null +++ b/sdk/elixir/dagger_codegen/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/sdk/elixir/dagger_codegen/.gitignore b/sdk/elixir/dagger_codegen/.gitignore new file mode 100644 index 00000000000..baec1c83947 --- /dev/null +++ b/sdk/elixir/dagger_codegen/.gitignore @@ -0,0 +1,29 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +dagger_codegen-*.tar + +# Temporary files, for example, from tests. +/tmp/ + +# Escript +dagger_codegen diff --git a/sdk/elixir/dagger_codegen/README.md b/sdk/elixir/dagger_codegen/README.md new file mode 100644 index 00000000000..5d0bb9f7c42 --- /dev/null +++ b/sdk/elixir/dagger_codegen/README.md @@ -0,0 +1,12 @@ +# Dagger.Codegen + +This packages provides a tool to generate Elixir code Dagger GraphQL. + +## How to build + +Run the following commands below: + +``` +$ mix deps.get +$ mix escript.build +``` diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen.ex new file mode 100644 index 00000000000..fc03d860e47 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen.ex @@ -0,0 +1,9 @@ +defmodule Dagger.Codegen do + @moduledoc """ + Functions for generating code from Dagger GraphQL. + """ + + def generate(generator, introspection_schema) do + generator.generate(introspection_schema) + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/cli.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/cli.ex new file mode 100644 index 00000000000..35571933f81 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/cli.ex @@ -0,0 +1,51 @@ +defmodule Dagger.Codegen.CLI do + @moduledoc """ + Main entrypoint for Dagger codegen binary. + """ + + def main(args) do + :argparse.run(Enum.map(args, &String.to_charlist/1), cli(), %{progname: :dagger_codegen}) + end + + defp cli() do + %{ + commands: %{ + ~c"generate" => %{ + arguments: [ + %{ + name: :outdir, + type: :binary, + long: ~c"-outdir", + required: true + }, + %{ + name: :introspection, + type: :binary, + long: ~c"-introspection", + required: true + } + ], + handler: &handle_generate/1 + } + } + } + end + + def handle_generate(%{outdir: outdir, introspection: introspection}) do + %{"__schema" => schema} = introspection |> File.read!() |> Jason.decode!() + + IO.puts("Generate code to #{Path.expand(outdir)}") + + File.mkdir_p!(outdir) + + Dagger.Codegen.generate( + Dagger.Codegen.ElixirGenerator, + Nestru.decode_from_map!(schema, Dagger.Codegen.Introspection.Types.Schema) + ) + |> Enum.flat_map(& &1) + |> Enum.each(fn {file, code} -> + Path.join(outdir, file) + |> File.write!(code) + end) + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator.ex new file mode 100644 index 00000000000..87190c04e1e --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator.ex @@ -0,0 +1,49 @@ +defmodule Dagger.Codegen.ElixirGenerator do + @moduledoc """ + Dagger Elixir code generator. + """ + + alias Dagger.Codegen.ElixirGenerator.Formatter + alias Dagger.Codegen.Introspection.Types.InputValue + alias Dagger.Codegen.Introspection.Types.TypeRef + alias Dagger.Codegen.Introspection.Visitor + alias Dagger.Codegen.Introspection.VisitorHandlers + + require EEx + + @template_dir Path.join([:code.priv_dir(:dagger_codegen), "templates", "elixir"]) + + @scalar_template Path.join(@template_dir, "scalar.eex") + @object_template Path.join(@template_dir, "object.eex") + @input_template Path.join(@template_dir, "input.eex") + @enum_template Path.join(@template_dir, "enum.eex") + + EEx.function_from_file(:defp, :scalar_template, @scalar_template, [:assigns]) + EEx.function_from_file(:defp, :object_template, @object_template, [:assigns]) + EEx.function_from_file(:defp, :input_template, @input_template, [:assigns]) + EEx.function_from_file(:defp, :enum_template, @enum_template, [:assigns]) + + def generate(schema) do + generate_code(schema) + end + + defp generate_code(schema) do + handlers = %VisitorHandlers{ + scalar: fn type -> + {"#{Formatter.format_var_name(type.name)}.ex", scalar_template(%{type: type})} + end, + object: fn type -> + {"#{Formatter.format_var_name(type.name)}.ex", + object_template(%{type: type, schema: schema})} + end, + input: fn type -> + {"#{Formatter.format_var_name(type.name)}.ex", input_template(%{type: type})} + end, + enum: fn type -> + {"#{Formatter.format_var_name(type.name)}.ex", enum_template(%{type: type})} + end + } + + Visitor.visit(schema, handlers) + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/formatter.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/formatter.ex new file mode 100644 index 00000000000..1d2a9e14170 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/formatter.ex @@ -0,0 +1,152 @@ +defmodule Dagger.Codegen.ElixirGenerator.Formatter do + alias Dagger.Codegen.Introspection.Types.TypeRef + + def format_module("Query"), do: format_module("Client") + + def format_module(name) do + Module.concat(Dagger, Macro.camelize(name)) + |> to_string() + |> String.trim_leading("Elixir.") + end + + def format_var_name("Query"), do: format_var_name("Client") + + def format_var_name(name) do + Macro.underscore(name) + end + + # Temporarily fixes for issue https://github.com/dagger/dagger/issues/6310. + @acronym_words %{ + "GPU" => "Gpu", + "VCS" => "Vcs" + } + + def format_function_name(name, acronym_words \\ @acronym_words) do + acronym_words + |> Enum.reduce(name, fn {word, new_word}, name -> + String.replace(name, word, new_word) + end) + |> Macro.underscore() + end + + def format_doc(doc) do + doc = String.replace(doc, "\"", "\\\"") + + for [text, api] <- Regex.scan(~r/`(?[a-zA-Z0-9]+)`/, doc), + reduce: doc do + reason -> String.replace(reason, text, "`#{format_function_name(api)}`") + end + end + + def format_type(%TypeRef{ + kind: "LIST", + of_type: %TypeRef{kind: "NON_NULL", of_type: type} + }) do + "[#{format_type(type, false)}]" + end + + def format_type(%TypeRef{kind: "NON_NULL", of_type: type}) do + if type.kind == "LIST" do + format_type(type) + else + format_type(type, false) + end + end + + def format_type(%TypeRef{} = type) do + format_type(type, true) + end + + defp format_type(%TypeRef{kind: "SCALAR", name: name}, nullable?) do + type = + case name do + "String" -> "String.t()" + "Int" -> "integer()" + "Float" -> "float()" + "Boolean" -> "boolean()" + "DateTime" -> "DateTime.t()" + otherwise -> "#{format_module(otherwise)}.t()" + end + + if nullable? do + "#{type} | nil" + else + type + end + end + + # OBJECT, INPUT_OBJECT, ENUM + defp format_type(%TypeRef{name: name}, nullable?) do + type = "#{format_module(name)}.t()" + + if nullable? do + "#{type} | nil" + else + type + end + end + + def format_typespec_output_type( + %TypeRef{ + kind: "NON_NULL", + of_type: %TypeRef{kind: "SCALAR"} + } = type + ) do + "{:ok, #{format_type(type)}} | {:error, term()}" + end + + def format_typespec_output_type( + %TypeRef{ + kind: "SCALAR" + } = type + ) do + "{:ok, #{format_type(type)}} | {:error, term()}" + end + + def format_typespec_output_type(%TypeRef{ + kind: "NON_NULL", + of_type: %TypeRef{kind: "LIST"} = type + }) do + "{:ok, #{format_type(type)}} | {:error, term()}" + end + + def format_typespec_output_type( + %TypeRef{ + kind: "LIST" + } = type + ) do + "{:ok, #{format_type(type)}} | {:error, term()}" + end + + def format_typespec_output_type(type) do + format_type(type) + end + + # TODO: clary which pattern match use. + def format_output_type(%TypeRef{ + kind: "NON_NULL", + of_type: %TypeRef{kind: "LIST", of_type: type} + }) do + format_output_type(type) + end + + def format_output_type(%TypeRef{ + kind: "NON_NULL", + of_type: type + }) do + format_output_type(type) + end + + def format_output_type(%TypeRef{ + kind: "LIST", + of_type: type + }) do + format_output_type(type) + end + + def format_output_type(%TypeRef{kind: "OBJECT", name: name}) do + format_module(name) + end + + def format_output_type(_type_ref), do: "DaggerInvalidOutput" +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/object_renderer.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/object_renderer.ex new file mode 100644 index 00000000000..9272cea5fe0 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/object_renderer.ex @@ -0,0 +1,180 @@ +defmodule Dagger.Codegen.ElixirGenerator.ObjectRenderer do + @moduledoc """ + Provides functions to render small part of Elixir object code. + """ + + alias Dagger.Codegen.ElixirGenerator.Formatter + alias Dagger.Codegen.ElixirGenerator.Renderer + alias Dagger.Codegen.Introspection.Types.Field + alias Dagger.Codegen.Introspection.Types.InputValue + alias Dagger.Codegen.Introspection.Types.Type + alias Dagger.Codegen.Introspection.Types.TypeRef + + @doc """ + Render `@derive` module attribute. + """ + def render_derive_type(%Type{} = type) do + [ + if has_id_field?(type) do + "@derive Dagger.ID" + else + "" + end, + "\n", + if has_sync_field?(type) do + "@derive Dagger.Sync" + else + "" + end + ] + |> IO.iodata_to_binary() + end + + @doc """ + Render `@spec` module attribute. + """ + def render_spec(%Field{name: name} = field, required_args, optional_args) do + map_arg = fn arg -> + if convert_id?(arg) do + arg.type.of_type.name + |> String.trim_trailing("ID") + |> Formatter.format_module() + |> Kernel.<>(".t()") + else + Formatter.format_type(arg.type) + end + end + + required_args = + case required_args do + [] -> + [] + + required_args -> + args = + required_args + |> Enum.map_intersperse(",", map_arg) + + [~c",", args] + end + + optional_args = + case optional_args do + [] -> + [] + + optional_args -> + args = + optional_args + |> Enum.map_intersperse(~c",", fn arg -> + [ + ?{, + arg.name |> Formatter.format_var_name() |> Renderer.render_atom(), + ~c",", + Formatter.format_type(arg.type), + ?} + ] + end) + + [~c",", ?[, args, ?]] + end + + [ + "@spec ", + Formatter.format_function_name(name), + ?(, + "t()", + required_args, + optional_args, + ?), + " :: ", + Formatter.format_typespec_output_type(field.type) + ] + end + + def render_function_args(module_var, required_args, optional_args) do + [ + "%__MODULE__{} =", + module_var, + render_function_required_args(required_args), + render_function_optional_args(optional_args) + ] + |> IO.iodata_to_binary() + end + + def render_function_required_args([]) do + [] + end + + def render_function_required_args(args) do + [ + ~c",", + Enum.map_intersperse(args, ~c",", &Formatter.format_var_name(&1.name)) + ] + end + + def render_function_optional_args([]), do: "" + + def render_function_optional_args(_args) do + ", optional_args \\\\ []" + end + + def render_put_arg(arg) do + var_name = Formatter.format_var_name(arg.name) + + if arg.name != "id" and TypeRef.id_type?(arg.type) do + ["Dagger.ID.id!(", var_name, ")"] + else + var_name + end + |> IO.iodata_to_binary() + end + + def render_maybe_put_arg(arg) do + key = arg.name |> Formatter.format_var_name() |> Renderer.render_atom() + + if TypeRef.is_list_of?(arg.type, "SCALAR") and + TypeRef.unwrap_list(arg.type) |> TypeRef.id_type?() do + [ + "if(optional_args[", + key, + "], do: Enum.map(optional_args[", + key, + "], &Dagger.ID.id!/1), else: nil)" + ] + else + ["optional_args[", key, ~c"]"] + end + |> IO.iodata_to_binary() + end + + def convert_id?(%InputValue{name: "id"}), do: false + def convert_id?(%InputValue{type: type_ref}), do: TypeRef.id_type?(type_ref) + def convert_id?(%InputValue{}), do: false + + defp has_sync_field?(%Type{fields: fields}) do + Enum.any?(fields, &(&1.name == "sync")) + end + + defp has_id_field?(%Type{fields: fields}) do + Enum.any?(fields, &(&1.name == "id")) + end + + def render_selection_chain(_schema, field, module_var, required_args, optional_args) do + [ + "#{module_var}.selection", + "|> select(\"#{field.name}\")", + for arg <- required_args do + ["|> put_arg(", ?", arg.name, ?", ~c",", render_put_arg(arg), ")"] + end, + for arg <- optional_args do + ["|> maybe_put_arg(", ?", arg.name, ?", ~c",", render_maybe_put_arg(arg), ")"] + end, + if TypeRef.is_list_of?(field.type, "OBJECT") do + ["|> select(\"id\")"] + else + [] + end + ] + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/renderer.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/renderer.ex new file mode 100644 index 00000000000..61cd0c94f73 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/elixir_generator/renderer.ex @@ -0,0 +1,81 @@ +defmodule Dagger.Codegen.ElixirGenerator.Renderer do + @moduledoc """ + Provides functions to render small part of Elixir code. + """ + + alias Dagger.Codegen.ElixirGenerator.Formatter + alias Dagger.Codegen.Introspection.Types.Type + alias Dagger.Codegen.Introspection.Types.Field + + @doc """ + Render the string. + + Uses multiline string when newline is detected. + """ + def render_string(s) do + if String.contains?(s, "\n") do + [ + "\"\"\"", + ?\n, + s, + ?\n, + "\"\"\"" + ] + else + [?", s, ?"] + end + end + + @doc "Render atom value." + def render_atom(string), do: ":#{string}" + + @doc """ + Render moduledoc from `type`. + + Uses the module name when no description in the type. + """ + def render_moduledoc(type) + + def render_moduledoc(%Type{description: desc, name: name} = type) + when desc == "" or is_nil(desc) do + # Prevent ExDoc ignore documentation when moduledoc were not found. + render_moduledoc(%{type | description: Formatter.format_module(name)}) + end + + def render_moduledoc(%Type{} = type) do + [ + "@moduledoc", + ~c" ", + render_string(type.description) + ] + |> IO.iodata_to_binary() + end + + @doc """ + Render function document. + """ + def render_doc(field_or_enum) + + def render_doc(%{description: ""}), do: "" + + def render_doc(%{description: description}) do + ["@doc", ~c" ", render_string(Formatter.format_doc(description))] + |> IO.iodata_to_binary() + end + + @doc """ + Render function deprecation message. + """ + def render_deprecated(field) + + def render_deprecated(%Field{deprecation_reason: ""}), do: "" + def render_deprecated(%Field{deprecation_reason: nil}), do: "" + + def render_deprecated(%Field{deprecation_reason: reason}) do + ["@deprecated", ~c" ", render_string(Formatter.format_doc(reason))] + |> IO.iodata_to_binary() + end + + @doc "Render possible values in typespec." + def render_union_type(types), do: Enum.join(types, " | ") +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/enum_value.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/enum_value.ex new file mode 100644 index 00000000000..4832b1b734d --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/enum_value.ex @@ -0,0 +1,13 @@ +defmodule Dagger.Codegen.Introspection.Types.EnumValue do + @derive [ + {Nestru.PreDecoder, + translate: %{"deprecationReason" => :deprecation_reason, "isDeprecated" => :is_deprecated}}, + Nestru.Decoder + ] + defstruct [ + :deprecation_reason, + :description, + :is_deprecated, + :name + ] +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/field.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/field.ex new file mode 100644 index 00000000000..835e3400ebf --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/field.ex @@ -0,0 +1,24 @@ +defmodule Dagger.Codegen.Introspection.Types.Field do + @derive [ + {Nestru.PreDecoder, + translate: %{"deprecationReason" => :deprecation_reason, "isDeprecated" => :is_deprecated}}, + {Nestru.Decoder, + hint: %{ + type: Dagger.Codegen.Introspection.Types.TypeRef, + args: [Dagger.Codegen.Introspection.Types.InputValue] + }} + ] + defstruct [ + :args, + :deprecation, + :deprecation_reason, + :description, + :is_deprecated, + :name, + :type + ] + + def no_args?(%__MODULE__{} = field) do + field.args == [] + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/input_field.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/input_field.ex new file mode 100644 index 00000000000..c649750f742 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/input_field.ex @@ -0,0 +1,16 @@ +defmodule Dagger.Codegen.Introspection.Types.InputValue do + @derive [ + {Nestru.PreDecoder, translate: %{"defaultValue" => :default_value}}, + {Nestru.Decoder, hint: %{type: Dagger.Codegen.Introspection.Types.TypeRef}} + ] + defstruct [ + :default_value, + :description, + :name, + :type + ] + + def is_optional?(%__MODULE__{} = input_value) do + input_value.type.kind != "NON_NULL" + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/query_type.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/query_type.ex new file mode 100644 index 00000000000..8961589bb16 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/query_type.ex @@ -0,0 +1,4 @@ +defmodule Dagger.Codegen.Introspection.Types.QueryType do + @derive Nestru.Decoder + defstruct [:name] +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/schema.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/schema.ex new file mode 100644 index 00000000000..3bffd711d91 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/schema.ex @@ -0,0 +1,25 @@ +defmodule Dagger.Codegen.Introspection.Types.Schema do + @derive [ + {Nestru.PreDecoder, + translate: %{ + "mutationType" => :mutation_type, + "queryType" => :query_type, + "subscriptionType" => :subscription_type + }}, + {Nestru.Decoder, + hint: %{ + query_type: Dagger.Codegen.Introspection.Types.QueryType, + types: [Dagger.Codegen.Introspection.Types.Type] + }} + ] + defstruct [ + :mutation_type, + :query_type, + :subscription_type, + :types + ] + + def get_type(%__MODULE__{} = schema, type) do + Enum.find(schema.types, &(&1.name == type.name)) + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type.ex new file mode 100644 index 00000000000..cc45cff0ecd --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type.ex @@ -0,0 +1,55 @@ +defmodule Dagger.Codegen.Introspection.Types.Type do + @derive [ + {Nestru.PreDecoder, + translate: %{ + "enumValues" => :enum_values, + "inputFields" => :input_fields, + "possibleTypes" => :possible_types + }} + ] + defstruct [ + :description, + :enum_values, + :fields, + :input_fields, + :interfaces, + :kind, + :name, + :possible_types + ] + + defimpl Nestru.Decoder do + def from_map_hint(_value, _context, map) do + hint = + %{} + |> put_hint( + map["inputFields"], + :input_fields, + [Dagger.Codegen.Introspection.Types.InputValue] + ) + |> put_hint( + map["enumValues"], + :enum_values, + [Dagger.Codegen.Introspection.Types.EnumValue] + ) + |> put_hint( + map["fields"], + :fields, + [Dagger.Codegen.Introspection.Types.Field] + ) + + {:ok, hint} + end + + # Nestru cannot convert `null` value into a list. So we need to + # add hint if the value is present + + defp put_hint(hint, value, _hint_key, _hint_fun) when is_nil(value) do + hint + end + + defp put_hint(hint, _value, hint_key, hint_fun) do + Map.put(hint, hint_key, hint_fun) + end + end +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type_ref.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type_ref.ex new file mode 100644 index 00000000000..96b1b8f0270 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/types/type_ref.ex @@ -0,0 +1,58 @@ +defmodule Dagger.Codegen.Introspection.Types.TypeRef do + @derive [ + {Nestru.PreDecoder, translate: %{"ofType" => :of_type}}, + {Nestru.Decoder, hint: %{of_type: Dagger.Codegen.Introspection.Types.TypeRef}} + ] + defstruct [ + :kind, + :name, + :of_type + ] + + def is_scalar?(%__MODULE__{kind: "NON_NULL", of_type: type}), do: is_scalar?(type) + def is_scalar?(%__MODULE__{kind: "SCALAR"}), do: true + def is_scalar?(%__MODULE__{kind: "ENUM"}), do: true + def is_scalar?(_), do: false + + def is_list_of?(%__MODULE__{kind: "NON_NULL", of_type: type}, of_kind), + do: is_list_of?(type, of_kind) + + def is_list_of?( + %__MODULE__{ + kind: "LIST", + of_type: %__MODULE__{kind: "NON_NULL", of_type: %__MODULE__{kind: of_kind}} + }, + of_kind + ), + do: true + + def is_list_of?(_, _), do: false + + # TODO: refactor me. + def unwrap_list(%__MODULE__{ + kind: "NON_NULL", + of_type: %__MODULE__{ + kind: "LIST", + of_type: %__MODULE__{ + kind: "NON_NULL", + of_type: type + } + } + }) do + type + end + + def unwrap_list(%__MODULE__{ + kind: "LIST", + of_type: %__MODULE__{ + kind: "NON_NULL", + of_type: type + } + }) do + type + end + + def id_type?(%__MODULE__{kind: "NON_NULL", of_type: type}), do: id_type?(type) + def id_type?(%__MODULE__{kind: "SCALAR", name: name}), do: String.ends_with?(name, "ID") + def id_type?(_), do: false +end diff --git a/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/visitor.ex b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/visitor.ex new file mode 100644 index 00000000000..09994e60730 --- /dev/null +++ b/sdk/elixir/dagger_codegen/lib/dagger/codegen/introspection/visitor.ex @@ -0,0 +1,43 @@ +defmodule Dagger.Codegen.Introspection.VisitorHandlers do + defstruct [:scalar, :object, :input, :enum] +end + +defmodule Dagger.Codegen.Introspection.Visitor do + alias Dagger.Codegen.Introspection.VisitorHandlers, as: VH + + def visit(schema, %VH{} = handlers) do + [ + {"SCALAR", handlers.scalar, ["String", "Float", "Int", "Boolean", "DateTime", "ID"]}, + {"INPUT_OBJECT", handlers.input, []}, + {"OBJECT", handlers.object, []}, + {"ENUM", handlers.enum, []} + ] + |> Enum.map(&visit(schema, &1)) + end + + def visit(schema, {kind, handler, ignore}) do + schema.types + |> Stream.filter(&(&1.kind == kind)) + |> Stream.reject(&String.starts_with?(&1.name, "__")) + |> Stream.reject(&(&1.name in ignore)) + |> Stream.map(fn type -> + %{ + type + | fields: + if type.fields do + Enum.sort_by(type.fields, & &1.name) + else + nil + end, + input_fields: + if type.input_fields do + Enum.sort_by(type.input_fields, & &1.name) + else + nil + end + } + end) + |> Enum.sort_by(& &1.name) + |> Enum.map(handler) + end +end diff --git a/sdk/elixir/dagger_codegen/mix.exs b/sdk/elixir/dagger_codegen/mix.exs new file mode 100644 index 00000000000..e130af3ef61 --- /dev/null +++ b/sdk/elixir/dagger_codegen/mix.exs @@ -0,0 +1,31 @@ +defmodule Dagger.Codegen.MixProject do + use Mix.Project + + def project do + [ + app: :dagger_codegen, + version: "0.1.0", + elixir: "~> 1.15", + start_permanent: Mix.env() == :prod, + deps: deps(), + escript: escript() + ] + end + + def application do + [ + extra_applications: [:logger, :eex] + ] + end + + defp escript do + [main_module: Dagger.Codegen.CLI] + end + + defp deps do + [ + {:jason, "~> 1.0"}, + {:nestru, "~> 0.3"} + ] + end +end diff --git a/sdk/elixir/dagger_codegen/mix.lock b/sdk/elixir/dagger_codegen/mix.lock new file mode 100644 index 00000000000..b3e0aa43c07 --- /dev/null +++ b/sdk/elixir/dagger_codegen/mix.lock @@ -0,0 +1,17 @@ +%{ + "absinthe_client": {:hex, :absinthe_client, "0.1.0", "a3bafc1dff141073a2a7fd926942fb10afb4d45295f0b6df46f6f1955ececaac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:req, "~> 0.3.0", [hex: :req, repo: "hexpm", optional: false]}, {:slipstream, "~> 1.0", [hex: :slipstream, repo: "hexpm", optional: false]}], "hexpm", "a7ec3e13da9b463cb024dba4733c2fa31a0690a3bfa897b9df6bdd544a4d6f91"}, + "castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"}, + "dagger": {:hex, :dagger, "0.9.3", "d4b3ba7df03c25d39edb227a8eddb7067da00b7b71233ff0566c0ba4556037c5", [:mix], [{:absinthe_client, "~> 0.1", [hex: :absinthe_client, repo: "hexpm", optional: false]}, {:nestru, "~> 0.3", [hex: :nestru, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:req, "~> 0.3", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "7441074e46a1ffe13ecbfce814554da7ad62158758b1cf244408bf67f0fbdefe"}, + "finch": {:hex, :finch, "0.16.0", "40733f02c89f94a112518071c0a91fe86069560f5dbdb39f9150042f44dcfb1a", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f660174c4d519e5fec629016054d60edd822cdfe2b7270836739ac2f97735ec5"}, + "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, + "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, + "mint": {:hex, :mint, "1.5.1", "8db5239e56738552d85af398798c80648db0e90f343c8469f6c6d8898944fb6f", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "4a63e1e76a7c3956abd2c72f370a0d0aecddc3976dea5c27eccbecfa5e7d5b1e"}, + "mint_web_socket": {:hex, :mint_web_socket, "1.0.3", "aab42fff792a74649916236d0b01f560a0b3f03ca5dea693c230d1c44736b50e", [:mix], [{:mint, ">= 1.4.1 and < 2.0.0-0", [hex: :mint, repo: "hexpm", optional: false]}], "hexpm", "ca3810ca44cc8532e3dce499cc17f958596695d226bb578b2fbb88c09b5954b0"}, + "nestru": {:hex, :nestru, "0.3.3", "50793bb15031479b50d6b4b6abc3f7699a9c3822b3eaabe745d070a154e8f5d8", [:mix], [], "hexpm", "fa248b779c182896b01feb28686abc79de975018a2c30e282cd1d8c18fb715ae"}, + "nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"}, + "nimble_pool": {:hex, :nimble_pool, "1.0.0", "5eb82705d138f4dd4423f69ceb19ac667b3b492ae570c9f5c900bb3d2f50a847", [:mix], [], "hexpm", "80be3b882d2d351882256087078e1b1952a28bf98d0a287be87e4a24a710b67a"}, + "req": {:hex, :req, "0.3.12", "f84c2f9e7cc71c81d7cbeacf7c61e763e53ab5f3065703792a4ab264b4f22672", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "c91103d4d1c8edeba90c84e0ba223a59865b673eaab217bfd17da3aa54ab136c"}, + "slipstream": {:hex, :slipstream, "1.1.0", "e3581e9bc73036e4283b33447475499d18c813c7662aa6b86e131633a7e912f3", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mint_web_socket, "~> 0.2 or ~> 1.0", [hex: :mint_web_socket, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.1 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "66eb1ac7c43573511b5bad90c24c128bb4e69f588bff65d0c409adf4c7eb02e6"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, +} diff --git a/sdk/elixir/dagger_codegen/priv/introspection.graphql b/sdk/elixir/dagger_codegen/priv/introspection.graphql new file mode 100644 index 00000000000..d17da75f352 --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/introspection.graphql @@ -0,0 +1,99 @@ +query IntrospectionQuery { + __schema { + queryType { + name + } + mutationType { + name + } + subscriptionType { + name + } + types { + ...FullType + } + directives { + name + description + locations + args { + ...InputValue + } + } + } +} + +fragment FullType on __Type { + kind + name + description + fields(includeDeprecated: true) { + name + description + args { + ...InputValue + } + type { + ...TypeRef + } + isDeprecated + deprecationReason + } + inputFields { + ...InputValue + } + interfaces { + ...TypeRef + } + enumValues(includeDeprecated: true) { + name + description + isDeprecated + deprecationReason + } + possibleTypes { + ...TypeRef + } +} + +fragment InputValue on __InputValue { + name + description + type { + ...TypeRef + } + defaultValue +} + +fragment TypeRef on __Type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } +} diff --git a/sdk/elixir/dagger_codegen/priv/templates/elixir/enum.eex b/sdk/elixir/dagger_codegen/priv/templates/elixir/enum.eex new file mode 100644 index 00000000000..2f7258645a9 --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/templates/elixir/enum.eex @@ -0,0 +1,15 @@ +<% alias Dagger.Codegen.ElixirGenerator.Formatter %> +<% alias Dagger.Codegen.ElixirGenerator.Renderer %> + +# This file generated by `dagger_codegen`. Please DO NOT EDIT. +defmodule <%= Formatter.format_module(@type.name) %> do + <%= Renderer.render_moduledoc(@type) %> + + @type t() :: <%= @type.enum_values |> Enum.map(&Renderer.render_atom(&1.name)) |> Renderer.render_union_type() %> + + <%= for enum_value <- @type.enum_values do %> + <%= Renderer.render_doc(enum_value) %> + @spec <%= Formatter.format_function_name(enum_value.name) %>() :: <%= Renderer.render_atom(enum_value.name) %> + def <%= Formatter.format_function_name(enum_value.name) %>(), do: <%= Renderer.render_atom(enum_value.name) %> + <% end %> +end diff --git a/sdk/elixir/dagger_codegen/priv/templates/elixir/input.eex b/sdk/elixir/dagger_codegen/priv/templates/elixir/input.eex new file mode 100644 index 00000000000..ef226d99619 --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/templates/elixir/input.eex @@ -0,0 +1,15 @@ +<% alias Dagger.Codegen.ElixirGenerator.Formatter %> +<% alias Dagger.Codegen.ElixirGenerator.Renderer %> + +# This file generated by `dagger_codegen`. Please DO NOT EDIT. +defmodule <%= Formatter.format_module(@type.name) %> do + <%= Renderer.render_moduledoc(@type) %> + + @type t() :: %__MODULE__{ + <%= for field <- @type.input_fields do %> + <%= Formatter.format_var_name(field.name) %>: <%= Formatter.format_type(field.type) %>, + <% end %> + } + + defstruct [<%= Enum.map_join(@type.input_fields, ",", &(&1.name |> Formatter.format_var_name() |> Renderer.render_atom())) %>] +end diff --git a/sdk/elixir/dagger_codegen/priv/templates/elixir/object.eex b/sdk/elixir/dagger_codegen/priv/templates/elixir/object.eex new file mode 100644 index 00000000000..5f89065648a --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/templates/elixir/object.eex @@ -0,0 +1,53 @@ +<% alias Dagger.Codegen.ElixirGenerator.Formatter %> +<% alias Dagger.Codegen.ElixirGenerator.Renderer %> +<% alias Dagger.Codegen.ElixirGenerator.ObjectRenderer %> +<% alias Dagger.Codegen.Introspection.Types.InputValue %> +<% alias Dagger.Codegen.Introspection.Types.TypeRef %> + +# This file generated by `dagger_codegen`. Please DO NOT EDIT. +defmodule <%= Formatter.format_module(@type.name) %> do + <%= Renderer.render_moduledoc(@type) %> + + use Dagger.Core.QueryBuilder + + <%= ObjectRenderer.render_derive_type(@type) %> + defstruct [:selection, :client] + + @type t() :: %__MODULE__{} + + <% module_var = Formatter.format_var_name(@type.name) %> + <%= for field <- @type.fields, + {optional_args, required_args} = Enum.split_with(field.args, &InputValue.is_optional?/1) do %> + <%= Renderer.render_deprecated(field) %> + <%= Renderer.render_doc(field) %> + <%= ObjectRenderer.render_spec(field, required_args, optional_args) %> + def <%= Formatter.format_function_name(field.name) %>(<%= ObjectRenderer.render_function_args(module_var, required_args, optional_args) %>) do + selection = + <%= ObjectRenderer.render_selection_chain(@schema, field, module_var, required_args, optional_args) %> + + <%= if TypeRef.is_list_of?(field.type, "OBJECT") do %> + with {:ok, items} <- execute(selection, <%= module_var %>.client) do + {:ok, + for %{"id" => id} <- items do + %<%= Formatter.format_output_type(field.type.of_type) %>{ + selection: + query() + |> select("load<%= field.type.of_type.of_type.of_type.name %>FromID") + |> arg("id", id), + client: <%= module_var %>.client + } + end} + end + <% else %> + <%= if TypeRef.is_scalar?(field.type) or TypeRef.is_list_of?(field.type, "SCALAR") do %> + execute(selection, <%= module_var %>.client) + <% else %> + %<%= Formatter.format_output_type(field.type) %>{ + selection: selection, + client: <%= module_var %>.client + } + <% end %> + <% end %> + end + <% end %> +end diff --git a/sdk/elixir/dagger_codegen/priv/templates/elixir/scalar.eex b/sdk/elixir/dagger_codegen/priv/templates/elixir/scalar.eex new file mode 100644 index 00000000000..8fe440d4810 --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/templates/elixir/scalar.eex @@ -0,0 +1,9 @@ +<% alias Dagger.Codegen.ElixirGenerator.Formatter %> +<% alias Dagger.Codegen.ElixirGenerator.Renderer %> + +# This file generated by `dagger_codegen`. Please DO NOT EDIT. +defmodule <%= Formatter.format_module(@type.name) %> do + <%= Renderer.render_moduledoc(@type) %> + + @type t() :: String.t() +end diff --git a/sdk/elixir/dagger_codegen/priv/templates/elixir/simple_object.eex b/sdk/elixir/dagger_codegen/priv/templates/elixir/simple_object.eex new file mode 100644 index 00000000000..9df227620d7 --- /dev/null +++ b/sdk/elixir/dagger_codegen/priv/templates/elixir/simple_object.eex @@ -0,0 +1,23 @@ +<% alias Dagger.Codegen.ElixirGenerator.Formatter %> +<% alias Dagger.Codegen.ElixirGenerator.Renderer %> + +# This file generated by `dagger_codegen`. Please DO NOT EDIT. +defmodule <%= Formatter.format_module(@type.name) %> do + <%= Renderer.render_moduledoc(@type) %> + + @type t() :: %__MODULE__{ + <%= for field <- @type.fields do %> + <%= field.name |> Formatter.format_var_name() %>: <%= Formatter.format_type(field.type) %>, + <% end %> + } + + @derive [ + {Nestru.PreDecoder, translate: %{ + <%= for field <- @type.fields do %> + "<%= field.name %>" => <%= field.name |> Formatter.format_var_name() |> Renderer.render_atom() %>, + <% end %> + }}, + Nestru.Decoder + ] + defstruct [<%= Enum.map_join(@type.fields, ",", &(&1.name |> Formatter.format_var_name() |> Renderer.render_atom())) %>, :selection, :client] +end diff --git a/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator/formatter_test.exs b/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator/formatter_test.exs new file mode 100644 index 00000000000..746dfcefae6 --- /dev/null +++ b/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator/formatter_test.exs @@ -0,0 +1,98 @@ +defmodule Dagger.Codegen.ElixirGenerator.FormatterTest do + use ExUnit.Case, async: true + + alias Dagger.Codegen.ElixirGenerator.Formatter + alias Dagger.Codegen.Introspection.Types.TypeRef + + test "format_module/1" do + assert Formatter.format_module("Container") == "Dagger.Container" + assert Formatter.format_module("BuildArg") == "Dagger.BuildArg" + end + + test "format_var_name/1" do + assert Formatter.format_var_name("Container") == "container" + assert Formatter.format_var_name("CacheVolume") == "cache_volume" + end + + test "format_function_name/1" do + assert Formatter.format_function_name("withEnvVariable") == "with_env_variable" + assert Formatter.format_function_name("loadSecretFromID") == "load_secret_from_id" + + assert Formatter.format_function_name("experimentalWithAllGPUs") == + "experimental_with_all_gpus" + end + + test "format_doc/1" do + assert Formatter.format_doc("A simple document") == "A simple document" + + assert Formatter.format_doc("A simple document that reference to `someFunction`") == + "A simple document that reference to `some_function`" + end + + test "format_type/1" do + type = %TypeRef{ + kind: "LIST", + name: nil, + of_type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "OBJECT", name: "EnvVariable", of_type: nil} + } + } + + assert Formatter.format_type(type) == "[Dagger.EnvVariable.t()]" + + type = %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "OBJECT", name: "EnvVariable", of_type: nil} + } + + assert Formatter.format_type(type) == "Dagger.EnvVariable.t()" + + type = %TypeRef{kind: "OBJECT", name: "EnvVariable", of_type: nil} + + assert Formatter.format_type(type) == "Dagger.EnvVariable.t() | nil" + + type = %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "LIST", + name: nil, + of_type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "OBJECT", name: "EnvVariable", of_type: nil} + } + } + } + + assert Formatter.format_type(type) == "[Dagger.EnvVariable.t()]" + end + + test "format_typespec_output_type/1" do + type = %TypeRef{kind: "NON_NULL", of_type: %TypeRef{kind: "SCALAR", name: "String"}} + assert Formatter.format_typespec_output_type(type) == "{:ok, String.t()} | {:error, term()}" + + type = %TypeRef{kind: "NON_NULL", of_type: %TypeRef{kind: "OBJECT", name: "CacheVolume"}} + assert Formatter.format_typespec_output_type(type) == "Dagger.CacheVolume.t()" + + type = %TypeRef{ + kind: "LIST", + name: nil, + of_type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "SCALAR", name: "String", of_type: nil} + } + } + + assert Formatter.format_typespec_output_type(type) == "{:ok, [String.t()]} | {:error, term()}" + + type = %TypeRef{kind: "SCALAR", name: "String", of_type: nil} + + assert Formatter.format_typespec_output_type(type) == + "{:ok, String.t() | nil} | {:error, term()}" + end +end diff --git a/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator_test.exs b/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator_test.exs new file mode 100644 index 00000000000..a49ba6e3a43 --- /dev/null +++ b/sdk/elixir/dagger_codegen/test/dagger/codegen/elixir_generator_test.exs @@ -0,0 +1,442 @@ +defmodule Dagger.Codegen.ElixirGeneratorTest do + use ExUnit.Case, async: true + + alias Dagger.Codegen.ElixirGenerator + alias Dagger.Codegen.Introspection.Types.{Schema, Type, TypeRef, InputValue, Field} + + test "source file name" do + schema = %Schema{ + types: [ + %Type{ + description: "A global cache volume identifier.", + enum_values: nil, + fields: nil, + input_fields: nil, + interfaces: nil, + kind: "SCALAR", + name: "CacheVolumeID", + possible_types: nil + } + ] + } + + assert [[{"cache_volume_id.ex", _}], [], [], []] = ElixirGenerator.generate(schema) + end + + test "scalar type" do + schema = %Schema{ + types: [ + %Type{ + description: "A global cache volume identifier.", + enum_values: nil, + fields: nil, + input_fields: nil, + interfaces: nil, + kind: "SCALAR", + name: "CacheVolumeID", + possible_types: nil + } + ] + } + + assert [[{_, source}], [], [], []] = ElixirGenerator.generate(schema) + + assert format!(source) == + """ + # This file generated by `dagger_codegen`. Please DO NOT EDIT. + defmodule Dagger.CacheVolumeID do + @moduledoc \"A global cache volume identifier.\" + + @type t() :: String.t() + end + """ + |> format!() + end + + test "object type chainable" do + schema = %Schema{ + types: [ + %Type{ + description: "", + enum_values: nil, + input_fields: nil, + interfaces: [], + kind: "OBJECT", + name: "Query", + possible_types: nil, + fields: [ + %Field{ + args: [ + %InputValue{ + default_value: nil, + description: + "A string identifier to target this cache volume (e.g., \"modules-cache\").", + name: "key", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "SCALAR", + name: "String", + of_type: nil + } + } + } + ], + deprecation_reason: nil, + description: "Constructs a cache volume for a given cache key.", + is_deprecated: false, + name: "cacheVolume", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "OBJECT", + name: "CacheVolume", + of_type: nil + } + } + } + ] + } + ] + } + + assert [[], [], [{_, source}], []] = ElixirGenerator.generate(schema) + + assert format!(source) == + """ + # This file generated by `dagger_codegen`. Please DO NOT EDIT. + defmodule Dagger.Client do + @moduledoc \"Dagger.Client\" + + use Dagger.Core.QueryBuilder + + defstruct [:selection, :client] + + @type t() :: %__MODULE__{} + + @doc \"Constructs a cache volume for a given cache key.\" + @spec cache_volume(t(), String.t()) :: Dagger.CacheVolume.t() + def cache_volume(%__MODULE__{} = client, key) do + selection = + client.selection |> select(\"cacheVolume\") |> put_arg(\"key\", key) + + %Dagger.CacheVolume{ + selection: selection, + client: client.client + } + end + end + """ + |> format!() + end + + test "object type execute" do + schema = %Schema{ + types: [ + %Type{ + description: "", + enum_values: nil, + input_fields: nil, + interfaces: [], + kind: "OBJECT", + name: "Query", + possible_types: nil, + fields: [ + %Field{ + args: [ + %InputValue{ + default_value: nil, + description: "Dummy argument", + name: "dummy", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "SCALAR", + name: "String", + of_type: nil + } + } + } + ], + deprecation_reason: nil, + description: + "The output stream of the last executed command.\n\nWill execute default command if none is set, or error if there's no default.", + is_deprecated: false, + name: "stdout", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "SCALAR", name: "String", of_type: nil} + } + } + ] + } + ] + } + + assert [[], [], [{_, source}], []] = ElixirGenerator.generate(schema) + + assert format!(source) == + """ + # This file generated by `dagger_codegen`. Please DO NOT EDIT. + defmodule Dagger.Client do + @moduledoc \"Dagger.Client\" + + use Dagger.Core.QueryBuilder + + defstruct [:selection, :client] + + @type t() :: %__MODULE__{} + + @doc \"\"\" + The output stream of the last executed command. + + Will execute default command if none is set, or error if there's no default. + \"\"\" + @spec stdout(t(), String.t()) :: {:ok, String.t()} | {:error, term()} + def stdout(%__MODULE__{} = client, dummy) do + selection = + client.selection |> select(\"stdout\") |> put_arg(\"dummy\", dummy) + + execute(selection, client.client) + end + end + """ + |> format!() + end + + test "object type execute list" do + schema = %Schema{ + types: [ + %Type{ + description: "", + enum_values: nil, + input_fields: nil, + interfaces: [], + kind: "OBJECT", + name: "Container", + possible_types: nil, + fields: [ + %Field{ + args: [ + %InputValue{ + default_value: nil, + description: "Dummy argument", + name: "dummy", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "SCALAR", + name: "String", + of_type: nil + } + } + } + ], + deprecation_reason: nil, + description: "Retrieves the list of environment variables passed to commands.", + is_deprecated: false, + name: "envVariables", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "LIST", + name: nil, + of_type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "OBJECT", + name: "EnvVariable", + of_type: nil + } + } + } + } + } + ] + }, + %Type{ + description: "A simple key value object that represents an environment variable.", + enum_values: nil, + fields: [ + %Field{ + args: [], + deprecation_reason: nil, + description: "The environment variable name.", + is_deprecated: false, + name: "name", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "SCALAR", name: "String", of_type: nil} + } + }, + %Field{ + args: [], + deprecation_reason: nil, + description: "The environment variable value.", + is_deprecated: false, + name: "value", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{kind: "SCALAR", name: "String", of_type: nil} + } + } + ], + input_fields: nil, + interfaces: [], + kind: "OBJECT", + name: "EnvVariable", + possible_types: nil + } + ] + } + + assert [[], [], [{"container.ex", source} | _], []] = ElixirGenerator.generate(schema) + + assert format!(source) == + """ + # This file generated by `dagger_codegen`. Please DO NOT EDIT. + defmodule Dagger.Container do + @moduledoc \"Dagger.Container\" + + use Dagger.Core.QueryBuilder + + defstruct [:selection, :client] + + @type t() :: %__MODULE__{} + + @doc \"Retrieves the list of environment variables passed to commands." + @spec env_variables(t(), String.t()) :: {:ok, [Dagger.EnvVariable.t()]} | {:error, term()} + def env_variables(%__MODULE__{} = container, dummy) do + selection = + container.selection |> select(\"envVariables\") |> put_arg(\"dummy\", dummy) |> select(\"id\") + + with {:ok, items} <- execute(selection, container.client) do + {:ok, + for %{\"id\" => id} <- items do + %Dagger.EnvVariable{ + selection: + query() + |> select(\"loadEnvVariableFromID\") + |> arg(\"id\", id), + client: container.client + } + end} + end + end + end + """ + |> format!() + end + + test "id argument" do + schema = %Schema{ + types: [ + %Type{ + description: "", + enum_values: nil, + input_fields: nil, + interfaces: [], + kind: "OBJECT", + name: "Container", + possible_types: nil, + fields: [ + %Field{ + args: [ + %InputValue{ + default_value: nil, + description: "Identifier of the service container", + name: "service", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "SCALAR", + name: "ServiceID", + of_type: nil + } + } + } + ], + deprecation_reason: nil, + description: "...", + is_deprecated: false, + name: "withServiceBinding", + type: %TypeRef{ + kind: "NON_NULL", + name: nil, + of_type: %TypeRef{ + kind: "OBJECT", + name: "Container", + of_type: nil + } + } + } + ] + } + ] + } + + assert [[], [], [{_, source} | _], []] = ElixirGenerator.generate(schema) + + assert format!(source) == + """ + # This file generated by `dagger_codegen`. Please DO NOT EDIT. + defmodule Dagger.Container do + @moduledoc \"Dagger.Container\" + + use Dagger.Core.QueryBuilder + + defstruct [:selection, :client] + + @type t() :: %__MODULE__{} + + @doc \"...\" + @spec with_service_binding(t(), Dagger.Service.t()) :: Dagger.Container.t() + def with_service_binding(%__MODULE__{} = container, service) do + selection = + container.selection |> select(\"withServiceBinding\") |> put_arg(\"service\", Dagger.ID.id!(service)) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + end + """ + |> format!() + end + + test "ignore primitive scalar type" do + schema = %Schema{ + types: + Enum.map(["String", "Float", "Int", "Boolean", "DateTime", "ID"], fn name -> + %Type{ + description: "", + enum_values: nil, + fields: nil, + input_fields: nil, + interfaces: nil, + kind: "SCALAR", + name: name, + possible_types: nil + } + end) + } + + assert [[], [], [], []] = ElixirGenerator.generate(schema) + end + + defp format!(source) do + Code.format_string!(source) + |> IO.iodata_to_binary() + end +end diff --git a/sdk/elixir/dagger_codegen/test/dagger/codegen_test.exs b/sdk/elixir/dagger_codegen/test/dagger/codegen_test.exs new file mode 100644 index 00000000000..996b8ad396d --- /dev/null +++ b/sdk/elixir/dagger_codegen/test/dagger/codegen_test.exs @@ -0,0 +1,4 @@ +defmodule Dagger.CodegenTest do + use ExUnit.Case + doctest Dagger.Codegen +end diff --git a/sdk/elixir/dagger_codegen/test/test_helper.exs b/sdk/elixir/dagger_codegen/test/test_helper.exs new file mode 100644 index 00000000000..869559e709e --- /dev/null +++ b/sdk/elixir/dagger_codegen/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/sdk/elixir/lib/dagger/codegen/compiler.ex b/sdk/elixir/lib/dagger/codegen/compiler.ex deleted file mode 100644 index a09342cf00b..00000000000 --- a/sdk/elixir/lib/dagger/codegen/compiler.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule Dagger.Codegen.Compiler do - @moduledoc false - - # Compile GraphQL introspection into Elixir code. - - alias Dagger.Codegen.Elixir.Templates.Enum, as: EnumTmpl - alias Dagger.Codegen.Elixir.Templates.Input - alias Dagger.Codegen.Elixir.Templates.Object - alias Dagger.Codegen.Elixir.Templates.Scalar - - def compile( - %{ - "__schema" => %{ - "types" => types - } - } = _introspection - ) do - types - |> Enum.filter(fn type -> - not_graphql_introspection_types(type) - end) - |> Enum.map(&render(&1, types)) - end - - defp not_graphql_introspection_types(%{"name" => name}) do - name not in graphql_introspection_types() - end - - defp graphql_introspection_types() do - [ - "__Type", - "__Directive", - "__Field", - "__InputValue", - "__EnumValue", - "__Schema", - "__TypeKind", - "__DirectiveLocation" - ] - end - - defp render(%{"name" => name, "kind" => kind} = full_type, types) do - q = - case kind do - "OBJECT" -> - Object.render(full_type, types) - - "SCALAR" -> - Scalar.render(full_type) - - "ENUM" -> - EnumTmpl.render(full_type) - - "INPUT_OBJECT" -> - Input.render(full_type) - end - - name = if(name == "Query", do: "Client", else: name) - - {"#{Macro.underscore(name)}.ex", q} - end -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/function.ex b/sdk/elixir/lib/dagger/codegen/elixir/function.ex deleted file mode 100644 index ae91973d982..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/function.ex +++ /dev/null @@ -1,119 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Function do - @moduledoc false - - # TODO: retire this and find a better way - @id_modules_map %{ - "CacheVolumeID" => "CacheVolume", - "ContainerID" => "Container", - "DirectoryID" => "Directory", - "EnvVariableID" => "EnvVariable", - "FieldTypeDefID" => "FieldTypeDef", - "FileID" => "File", - "FunctionArgID" => "FunctionArg", - "FunctionCallArgValueID" => "FunctionCallArgValue", - "FunctionCallID" => "FunctionCall", - "FunctionID" => "Function", - "GeneratedCodeID" => "GeneratedCode", - "GitRefID" => "GitRef", - "GitRepositoryID" => "GitRepository", - "HostID" => "Host", - "InterfaceTypeDefID" => "InterfaceTypeDef", - "LabelID" => "Label", - "ListTypeDefID" => "ListTypeDef", - "ModuleConfigID" => "ModuleConfig", - "ModuleID" => "Module", - "ObjectTypeDefID" => "ObjectTypeDef", - "PortID" => "Port", - "SecretID" => "Secret", - "ServiceID" => "Service", - "SocketID" => "Socket", - "TypeDefID" => "TypeDef" - } - - def id_module_to_var_name(id_mod), do: Map.fetch!(@id_modules_map, id_mod) - - def format_var_name(name) when is_binary(name) do - format_name(name) - end - - defp format_fun_name(name) when is_atom(name) do - name - |> to_string() - |> format_fun_name() - end - - defp format_fun_name(name) when is_binary(name) do - format_name(name) - end - - defp format_name(name) when is_binary(name) do - name - |> Macro.underscore() - |> String.to_atom() - end - - def define(fun_name, args, guard \\ nil, body, opts \\ []) when is_list(args) do - fun_name = format_fun_name(fun_name) - doc = opts[:doc] |> doc_to_quote() - deprecated = opts[:deprecated] |> deprecated_to_quote() - typespec = opts[:spec] |> spec_to_quote(fun_name) - - fun = [ - case guard do - nil -> - quote do - def unquote(fun_name)(unquote_splicing(args)) do - unquote(body) - end - end - - guard -> - quote do - def unquote(fun_name)(unquote_splicing(args)) when unquote(guard) do - unquote(body) - end - end - end - ] - - quote do - (unquote_splicing(doc ++ deprecated ++ typespec ++ fun)) - end - end - - defp doc_to_quote(nil) do - [ - quote do - @doc false - end - ] - end - - defp doc_to_quote(doc) when is_binary(doc) do - [ - quote do - @doc unquote(doc) - end - ] - end - - defp deprecated_to_quote(nil), do: [] - - defp deprecated_to_quote(deprecated) do - [ - quote do - @deprecated unquote(deprecated) - end - ] - end - - defp spec_to_quote(nil, _), do: [] - - defp spec_to_quote({arg_types, return_type}, fun_name) do - [ - quote do - @spec unquote(fun_name)(unquote_splicing(arg_types)) :: unquote(return_type) - end - ] - end -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/module.ex b/sdk/elixir/lib/dagger/codegen/elixir/module.ex deleted file mode 100644 index 8706dfc5f1c..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/module.ex +++ /dev/null @@ -1,50 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Module do - @moduledoc false - - # TODO: retire this and find a better way - @id_modules_map %{ - "CacheVolumeID" => "CacheVolume", - "ContainerID" => "Container", - "DirectoryID" => "Directory", - "EnvVariableID" => "EnvVariable", - "FieldTypeDefID" => "FieldTypeDef", - "FileID" => "File", - "FunctionArgID" => "FunctionArg", - "FunctionCallArgValueID" => "FunctionCallArgValue", - "FunctionCallID" => "FunctionCall", - "FunctionID" => "Function", - "GeneratedCodeID" => "GeneratedCode", - "GitRefID" => "GitRef", - "GitRepositoryID" => "GitRepository", - "HostID" => "Host", - "InterfaceTypeDefID" => "InterfaceTypeDef", - "LabelID" => "Label", - "ListTypeDefID" => "ListTypeDef", - "ModuleConfigID" => "ModuleConfig", - "ModuleID" => "Module", - "ObjectTypeDefID" => "ObjectTypeDef", - "PortID" => "Port", - "SecretID" => "Secret", - "ServiceID" => "Service", - "SocketID" => "Socket", - "TypeDefID" => "TypeDef" - } - - defmacro id_modules(), do: quote(do: Map.keys(@id_modules_map)) - - def id_module_to_module(id_mod), do: Map.fetch!(@id_modules_map, id_mod) - - def format_name(name) when is_binary(name) do - name - |> Macro.camelize() - |> String.to_atom() - end - - def from_name("Query") do - from_name("Client") - end - - def from_name(name) do - Module.concat([Dagger, format_name(name)]) - end -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/templates/enum_tmpl.ex b/sdk/elixir/lib/dagger/codegen/elixir/templates/enum_tmpl.ex deleted file mode 100644 index 8c68f242e1f..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/templates/enum_tmpl.ex +++ /dev/null @@ -1,60 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Templates.Enum do - @moduledoc false - - alias Dagger.Codegen.Elixir.Function - alias Dagger.Codegen.Elixir.Module, as: Mod - - def render(%{ - "name" => name, - "description" => desc, - "enumValues" => enum_values - }) do - mod_name = Mod.from_name(name) - - enum_values = - enum_values - |> Enum.sort_by(fn %{"name" => name} -> name end) - - type = render_possible_enum_values(enum_values) - - funs = - enum_values - |> Enum.map(&render_function/1) - - quote do - defmodule unquote(mod_name) do - @moduledoc unquote(desc) - - @type t() :: unquote(type) - - unquote_splicing(funs) - end - end - end - - defp render_function(%{ - "name" => value, - "description" => desc, - "deprecationReason" => deprecated_reason - }) do - Function.define( - value, - [], - nil, - quote do - unquote(String.to_atom(value)) - end, - doc: desc, - deprecated: deprecated_reason, - spec: {[], quote(do: unquote(String.to_atom(value)))} - ) - end - - defp render_possible_enum_values([%{"name" => v1}, %{"name" => v2}]) do - {:|, [], [String.to_atom(v1), String.to_atom(v2)]} - end - - defp render_possible_enum_values([%{"name" => v1} | rest]) do - {:|, [], [String.to_atom(v1), render_possible_enum_values(rest)]} - end -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/templates/input_tmpl.ex b/sdk/elixir/lib/dagger/codegen/elixir/templates/input_tmpl.ex deleted file mode 100644 index 8dd7270f100..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/templates/input_tmpl.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Templates.Input do - @moduledoc false - - alias Dagger.Codegen.Elixir.Module, as: Mod - alias Dagger.Codegen.Elixir.Type - - def render(%{ - "name" => name, - "description" => desc, - "inputFields" => fields - }) do - mod_name = Mod.from_name(name) - - desc = - if desc == "" do - name - else - desc - end - - fields = - fields - |> Enum.sort_by(fn %{"name" => name} -> name end) - - struct_fields = Enum.map(fields, &to_struct_field/1) - - data_type_t = - {:%, [], - [ - {:__MODULE__, [], Elixir}, - {:%{}, [], - fields - |> Enum.map(fn %{"type" => type} = field -> - type = - case type do - %{"kind" => "NON_NULL", "ofType" => type} -> Type.render_type(type) - type -> Type.render_type(type) |> Type.render_nullable_type() - end - - {to_struct_field(field), type} - end)} - ]} - - quote do - defmodule unquote(mod_name) do - @moduledoc unquote(desc) - - @type t() :: unquote(data_type_t) - - @derive Nestru.Decoder - defstruct unquote(struct_fields) - end - end - end - - defp to_struct_field(%{"name" => name}) do - name - |> Macro.underscore() - |> String.to_atom() - end -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/templates/object_tmpl.ex b/sdk/elixir/lib/dagger/codegen/elixir/templates/object_tmpl.ex deleted file mode 100644 index 4110e0ae260..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/templates/object_tmpl.ex +++ /dev/null @@ -1,563 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Templates.Object do - @moduledoc false - - alias Dagger.Codegen.Elixir.Function - alias Dagger.Codegen.Elixir.Module, as: Mod - alias Dagger.Codegen.Elixir.Type - - # TODO: retire this and find a better way - @id_modules [ - "CacheVolumeID", - "ContainerID", - "DirectoryID", - "EnvVariableID", - "FieldTypeDefID", - "FileID", - "FunctionArgID", - "FunctionCallArgValueID", - "FunctionCallID", - "FunctionID", - "GeneratedCodeID", - "GitRefID", - "GitRepositoryID", - "HostID", - "InterfaceTypeDefID", - "LabelID", - "ListTypeDefID", - "ModuleConfigID", - "ModuleID", - "ObjectTypeDefID", - "PortID", - "SecretID", - "ServiceID", - "SocketID", - "TypeDefID" - ] - - def render(full_type, types) do - if is_simple_object?(full_type) do - render_data_module(full_type, types) - else - render_api_module(full_type, types) - end - end - - defp is_simple_object?(%{"fields" => fields}) do - not has_id_fields?(fields) and empty_args?(fields) - end - - defp has_id_fields?(fields) do - fields - |> Enum.any?(fn %{"name" => name} -> name == "id" end) - end - - defp empty_args?(fields) do - fields - |> Enum.all?(fn %{"args" => args} -> args == [] end) - end - - defp render_data_module( - %{ - "name" => name, - "fields" => fields, - "description" => desc - }, - _ - ) - when name not in @id_modules do - mod_name = Mod.from_name(name) - - desc = - if desc == "" do - name - else - desc - end - - struct_fields = Enum.map(fields, &to_struct_field/1) - - data_type_t = - {:%, [], - [ - {:__MODULE__, [], Elixir}, - {:%{}, [], - fields - |> Enum.map(fn %{"type" => type} = field -> - type = - case type do - %{"kind" => "NON_NULL", "ofType" => type} -> Type.render_type(type) - type -> Type.render_type(type) |> Type.render_nullable_type() - end - - {to_struct_field(field), type} - end)} - ]} - - quote do - defmodule unquote(mod_name) do - @moduledoc unquote(desc) - - @type t() :: unquote(data_type_t) - - @derive Nestru.Decoder - defstruct unquote(struct_fields) - end - end - end - - defp to_struct_field(%{"name" => name}) do - name - |> Macro.underscore() - |> String.to_atom() - end - - defp render_api_module( - %{ - "name" => name, - "fields" => fields, - "description" => desc - }, - types - ) do - mod_name = Mod.from_name(name) - funs = Enum.map(fields, &render_function(&1, Function.format_var_name(name), types)) - - derive_sync = - if Enum.any?(fields, fn %{"name" => name} -> name == "sync" end) do - [ - quote do - @derive Dagger.Sync - end - ] - else - [] - end - - desc = - if desc == "" do - name - else - desc - end - - quote do - defmodule unquote(mod_name) do - @moduledoc unquote(desc) - - use Dagger.Core.QueryBuilder - - @type t() :: %__MODULE__{} - - unquote_splicing(derive_sync) - defstruct [:selection, :client] - - unquote_splicing(funs) - end - end - end - - defp render_function( - %{ - "name" => name, - "args" => args, - "type" => type - } = field, - mod_var_name, - types - ) do - mod_var_name = to_macro_var(mod_var_name) - fun_args = [module_fun_arg(mod_var_name) | fun_args(args)] - fun_body = format_function_body(name, {mod_var_name, args}, type, types) - - Function.define(name, fun_args, nil, fun_body, - doc: format_doc(field), - deprecated: deprecated_reason(field), - spec: format_spec(field) - ) - end - - defp format_function_body( - field_name, - {mod_var_name, [%{"name" => "id"} = arg]}, - type_ref, - _types - ) - when field_name in ["file", "secret"] do - name = - case type_ref do - %{"kind" => "OBJECT", "name" => name} -> - name - - %{"kind" => "NON_NULL", "ofType" => %{"kind" => "OBJECT", "name" => name}} -> - name - end - - mod_name = Mod.from_name(name) - arg_name = arg |> fun_arg_name() |> Function.format_var_name() - - quote do - selection = select(unquote(mod_var_name).selection, unquote(field_name)) - selection = arg(selection, "id", unquote(to_macro_var(arg_name))) - - %unquote(mod_name){ - selection: selection, - client: unquote(mod_var_name).client - } - end - end - - defp format_function_body( - field_name, - {mod_var_name, args}, - %{"kind" => "NON_NULL", "ofType" => %{"kind" => "OBJECT", "name" => name}}, - _types - ) - when field_name != "moduleConfig" do - name = if(name == "Query", do: "Client", else: name) - mod_name = Mod.from_name(name) - args = render_args(field_name, args) - - quote do - selection = select(unquote(mod_var_name).selection, unquote(field_name)) - - unquote_splicing(args) - - %unquote(mod_name){ - selection: selection, - client: unquote(mod_var_name).client - } - end - end - - defp format_function_body( - field_name, - {mod_var_name, args}, - %{ - "kind" => "NON_NULL", - "ofType" => %{ - "kind" => "LIST", - "ofType" => %{"ofType" => %{"kind" => "OBJECT", "name" => name}} - } - }, - types - ) do - args = render_args(field_name, args) - - return_module = Mod.from_name(name) - loader = "load#{name}FromID" - - # TODO(vito): technically we just need to select the ID, but selecting a - # single field here seems to confuse the query builder. maybe pre-fetching - # fields will come in useful anyway? - selection_fields = - types - |> Enum.find(fn %{"name" => typename} -> typename == name end) - |> then(fn %{"fields" => fields} -> get_in(fields, [Access.all(), "name"]) end) - |> Enum.join(" ") - - quote do - selection = select(unquote(mod_var_name).selection, unquote(field_name)) - selection = select(selection, unquote(selection_fields)) - - unquote_splicing(args) - - with {:ok, data} <- execute(selection, unquote(mod_var_name).client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, unquote(loader)) - elem_selection = arg(elem_selection, "id", value["id"]) - - %unquote(return_module){ - selection: elem_selection, - client: unquote(mod_var_name).client - } - end)} - end - end - end - - defp format_function_body(field_name, {mod_var_name, args}, type_ref, _types) do - args = render_args(field_name, args) - - execute_block = - case type_ref do - %{"kind" => "OBJECT", "name" => name} -> - return_module = Mod.from_name(name) - - quote do - case execute(selection, unquote(mod_var_name).client) do - {:ok, nil} -> - {:ok, nil} - - {:ok, data} -> - Nestru.decode_from_map(data, unquote(return_module)) - - error -> - error - end - end - - _ -> - quote do - execute(selection, unquote(mod_var_name).client) - end - end - - quote do - selection = select(unquote(mod_var_name).selection, unquote(field_name)) - - unquote_splicing(args) - - unquote(execute_block) - end - end - - defp deprecated_reason(%{"isDeprecated" => true, "deprecationReason" => reason}) do - reason = String.trim_trailing(reason, ".") - - for [text, api] <- Regex.scan(~r/`(?[a-zA-Z0-9]+)`/, reason), - reduce: reason do - reason -> String.replace(reason, text, "`#{Macro.underscore(api)}`") - end - end - - defp deprecated_reason(_), do: nil - - defp format_doc(%{"description" => desc, "args" => args}) do - sep = [~c"\n", ~c"\n"] - doc = [desc] - - required_args_doc = - case format_required_args_doc(args) do - [] -> [] - args_doc -> ["## Required Arguments", ~c"\n", ~c"\n", args_doc] - end - - optional_args_doc = - case format_optional_args_doc(args) do - [] -> [] - args_doc -> ["## Optional Arguments", ~c"\n", ~c"\n", args_doc] - end - - (doc ++ sep ++ required_args_doc ++ sep ++ optional_args_doc) - |> IO.iodata_to_binary() - |> String.trim() - end - - defp format_required_args_doc(args) do - args - |> Enum.filter(&required_arg?/1) - |> Enum.map(&format_arg_doc/1) - |> Enum.intersperse(~c"\n") - end - - defp format_optional_args_doc(args) do - args - |> Enum.filter(&(not required_arg?(&1))) - |> Enum.map(&format_arg_doc/1) - |> Enum.intersperse(~c"\n") - end - - defp required_arg?(arg) do - arg["type"]["kind"] == "NON_NULL" - end - - defp format_arg_doc(%{"name" => name, "description" => description}) do - name = Function.format_var_name(name) - "* `#{name}` - #{description}" - end - - defp render_args(field_name, args) do - required_args = render_required_args(field_name, args) - optional_args = render_optional_args(args) - - required_args ++ optional_args - end - - defp render_required_args(field_name, args) do - for arg <- args, - arg["type"]["kind"] == "NON_NULL" do - name = arg |> fun_arg_name() |> Function.format_var_name() - - basic = - quote do - selection = arg(selection, unquote(arg["name"]), unquote(to_macro_var(name))) - end - - if String.starts_with?(field_name, "load") and String.ends_with?(field_name, "FromID") do - # The point of loadFooFromID is to take an ID, so we don't want to - # translate it to the real object. - basic - else - case arg do - %{"type" => %{"ofType" => %{"name" => type_name}}} - when type_name in @id_modules -> - mod = Mod.from_name(Mod.id_module_to_module(type_name)) - - quote do - {:ok, id} = unquote(mod).id(unquote(to_macro_var(name))) - selection = arg(selection, unquote(arg["name"]), id) - end - - _ -> - basic - end - end - end - end - - defp render_optional_args(args) do - for arg <- args, not required_arg?(arg) do - name = arg["name"] - arg_name = Function.format_var_name(name) - - render = - case arg do - %{ - "type" => %{ - "kind" => "LIST", - "name" => nil, - "ofType" => %{ - "kind" => "NON_NULL", - "name" => nil, - "ofType" => %{"kind" => "SCALAR", "name" => type_name, "ofType" => nil} - } - } - } - when type_name in @id_modules -> - mod = Mod.from_name(Mod.id_module_to_module(type_name)) - - quote do - ids = - optional_args[unquote(arg_name)] - |> Enum.map(fn value -> - {:ok, id} = unquote(mod).id(value) - id - end) - - arg(selection, unquote(name), ids) - end - - %{ - "type" => %{"kind" => "SCALAR", "name" => type_name, "ofType" => nil} - } - when type_name in @id_modules -> - mod = Mod.from_name(Mod.id_module_to_module(type_name)) - - quote do - {:ok, id} = unquote(mod).id(optional_args[unquote(arg_name)]) - arg(selection, unquote(name), id) - end - - _ -> - quote do - arg(selection, unquote(name), optional_args[unquote(arg_name)]) - end - end - - quote do - selection = - if is_nil(optional_args[unquote(arg_name)]) do - selection - else - unquote(render) - end - end - end - end - - defp format_spec(%{"name" => name, "type" => type} = field) do - return_type = - case type do - %{"kind" => "NON_NULL", "ofType" => %{"kind" => "OBJECT"} = type} -> - Type.render_type(type) - - %{"kind" => "NON_NULL", "ofType" => type} -> - Type.render_type(type) - |> Type.render_result_type() - - type -> - Type.render_type(type) - |> Type.render_nullable_type() - |> Type.render_result_type() - end - - {[quote(do: t()) | render_arg_types(field["args"], name not in ["file", "secret"])], - return_type} - end - - defp render_arg_types(args, strip_id?) do - {required_args, optional_args} = - args - |> Enum.split_with(&required_arg?/1) - - required_arg_types = - for %{"type" => type} <- required_args do - case type do - %{"kind" => "NON_NULL", "ofType" => %{"kind" => "SCALAR"}} = type -> - if strip_id? do - update_in(type, ["ofType", "name"], fn name -> - String.trim_trailing(name, "ID") - end) - else - type - end - - type -> - type - end - |> Type.render_type() - end - - if optional_args != [] do - required_arg_types ++ [quote(do: keyword())] - else - required_arg_types - end - end - - defp module_fun_arg(mod_var_name) do - quote do - %__MODULE__{} = unquote(mod_var_name) - end - end - - defp fun_args([]), do: [] - - defp fun_args(args) do - {required_args, optional_args} = - args - |> Enum.split_with(&required_arg?/1) - - required_fun_args(required_args) ++ optional_fun_args(optional_args) - end - - defp required_fun_args(args) do - args - |> Enum.map(&Function.format_var_name(fun_arg_name(&1))) - |> Enum.map(&to_macro_var/1) - end - - defp optional_fun_args([]), do: [] - - defp optional_fun_args(_args) do - [ - quote do - unquote(to_macro_var(:optional_args)) \\ [] - end - ] - end - - defp fun_arg_name(%{"name" => "id", "type" => %{"ofType" => %{"name" => id_mod}}}) - when id_mod in @id_modules do - Function.id_module_to_var_name(id_mod) - end - - defp fun_arg_name(%{"name" => name}) do - name - end - - defp to_macro_var(var), do: Macro.var(var, __MODULE__) -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/templates/scalar_tmpl.ex b/sdk/elixir/lib/dagger/codegen/elixir/templates/scalar_tmpl.ex deleted file mode 100644 index 4b708ea7d03..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/templates/scalar_tmpl.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Templates.Scalar do - @moduledoc false - - alias Dagger.Codegen.Elixir.Module, as: Mod - - def render(%{"name" => name, "description" => desc}) do - mod_name = name |> Mod.from_name() - type = name_to_type(name) - - quote do - defmodule unquote(mod_name) do - @moduledoc unquote(desc) - @type t() :: unquote(type) - end - end - end - - defp name_to_type("Int"), do: quote(do: integer()) - defp name_to_type("Float"), do: quote(do: float()) - defp name_to_type("Boolean"), do: quote(do: boolean()) - defp name_to_type("DateTime"), do: quote(do: DateTime.t()) - defp name_to_type(_), do: quote(do: String.t()) -end diff --git a/sdk/elixir/lib/dagger/codegen/elixir/type.ex b/sdk/elixir/lib/dagger/codegen/elixir/type.ex deleted file mode 100644 index 8a866a3794a..00000000000 --- a/sdk/elixir/lib/dagger/codegen/elixir/type.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule Dagger.Codegen.Elixir.Type do - @moduledoc false - - alias Dagger.Codegen.Elixir.Module, as: Mod - - def render_result_type(type) do - quote do - {:ok, unquote(type)} | {:error, term()} - end - end - - def render_nullable_type(type) do - quote do - unquote(type) | nil - end - end - - def render_type(%{"kind" => "NON_NULL", "ofType" => type}) do - render_type(type) - end - - def render_type(%{"kind" => "OBJECT", "name" => name}) do - mod_name = Mod.from_name(name) - - quote do - unquote(mod_name).t() - end - end - - def render_type(%{"kind" => "LIST", "ofType" => type}) do - type = render_type(type) - - quote do - [unquote(type)] - end - end - - def render_type(%{"kind" => "ENUM", "name" => name}) do - mod_name = Mod.from_name(name) - - quote do - unquote(mod_name).t() - end - end - - def render_type(%{"kind" => "SCALAR", "name" => name}) do - mod_name = Mod.from_name(name) - - quote do - unquote(mod_name).t() - end - end - - def render_type(%{"kind" => "INPUT_OBJECT", "name" => name}) do - mod_name = Mod.from_name(name) - - quote do - unquote(mod_name).t() - end - end -end diff --git a/sdk/elixir/lib/dagger/codegen/generator.ex b/sdk/elixir/lib/dagger/codegen/generator.ex deleted file mode 100644 index 178087f7bc9..00000000000 --- a/sdk/elixir/lib/dagger/codegen/generator.ex +++ /dev/null @@ -1,12 +0,0 @@ -defmodule Dagger.Codegen.Generator do - @moduledoc false - - def generate() do - {:ok, client} = Dagger.Core.Client.connect() - - {:ok, %{status: 200, body: resp}} = - Dagger.Core.Client.query(client, Dagger.Codegen.Introspection.query()) - - Dagger.Codegen.Compiler.compile(resp["data"]) - end -end diff --git a/sdk/elixir/lib/dagger/codegen/introspection.ex b/sdk/elixir/lib/dagger/codegen/introspection.ex deleted file mode 100644 index 45053a10713..00000000000 --- a/sdk/elixir/lib/dagger/codegen/introspection.ex +++ /dev/null @@ -1,14 +0,0 @@ -defmodule Dagger.Codegen.Introspection do - @moduledoc false - - @introspection_query_path Path.join([ - Application.app_dir(:dagger), - "priv", - "introspection.graphql" - ]) - @external_resource @introspection_query_path - - def query() do - File.read!(@introspection_query_path) - end -end diff --git a/sdk/elixir/lib/dagger/core/query_builder.ex b/sdk/elixir/lib/dagger/core/query_builder.ex index 99e89bc220c..3d13e777692 100644 --- a/sdk/elixir/lib/dagger/core/query_builder.ex +++ b/sdk/elixir/lib/dagger/core/query_builder.ex @@ -18,12 +18,23 @@ defmodule Dagger.Core.QueryBuilder.Selection do } end - def arg(%__MODULE__{args: args} = selection, name, value) when is_binary(name) do + # TODO: Remove me. + def arg(selection, name, value) do + put_arg(selection, name, value) + end + + def put_arg(%__MODULE__{args: args} = selection, name, value) when is_binary(name) do args = args || %{} %{selection | args: Map.put(args, name, value)} end + def maybe_put_arg(%__MODULE__{} = selection, _name, nil), do: selection + + def maybe_put_arg(%__MODULE__{} = selection, name, value) do + put_arg(selection, name, value) + end + def build(%__MODULE__{} = selection) do fields = build_fields(selection, []) Enum.join(fields, "{") <> String.duplicate("}", Enum.count(fields) - 1) @@ -109,24 +120,21 @@ defmodule Dagger.Core.QueryBuilder do {:error, %Dagger.QueryError{errors: errors}} {:ok, %{status: 200, body: %{"data" => data}}} -> - {:ok, select_data(data, Selection.path(selection) |> Enum.reverse())} + {:ok, select_data(data, Selection.path(selection))} otherwise -> otherwise end end - defp select_data(data, [sub_selection | path]) do - case sub_selection |> String.split() do - [selection] -> - get_in(data, Enum.reverse([selection | path])) + defp select_data(data, []), do: data - selections -> - case get_in(data, Enum.reverse(path)) do - data when is_list(data) -> Enum.map(data, &Map.take(&1, selections)) - data when is_map(data) -> Map.take(data, selections) - end - end + defp select_data(data, _selectors) when is_list(data) do + data + end + + defp select_data(data, [selector | selectors]) do + select_data(Map.get(data, selector), selectors) end defmacro __using__(_opts) do diff --git a/sdk/elixir/lib/dagger/gen/boolean.ex b/sdk/elixir/lib/dagger/gen/boolean.ex deleted file mode 100644 index be458a3e1df..00000000000 --- a/sdk/elixir/lib/dagger/gen/boolean.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.Boolean do - @moduledoc "The `Boolean` scalar type represents `true` or `false`." - @type t() :: boolean() -end diff --git a/sdk/elixir/lib/dagger/gen/build_arg.ex b/sdk/elixir/lib/dagger/gen/build_arg.ex index 692d3cdc2aa..42889522dca 100644 --- a/sdk/elixir/lib/dagger/gen/build_arg.ex +++ b/sdk/elixir/lib/dagger/gen/build_arg.ex @@ -1,7 +1,11 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.BuildArg do @moduledoc "Key value object that represents a build argument." - @type t() :: %__MODULE__{name: Dagger.String.t(), value: Dagger.String.t()} - @derive Nestru.Decoder + + @type t() :: %__MODULE__{ + name: String.t(), + value: String.t() + } + defstruct [:name, :value] end diff --git a/sdk/elixir/lib/dagger/gen/cache_id.ex b/sdk/elixir/lib/dagger/gen/cache_id.ex deleted file mode 100644 index 3e6bdae3315..00000000000 --- a/sdk/elixir/lib/dagger/gen/cache_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.CacheID do - @moduledoc "A global cache volume identifier." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/cache_sharing_mode.ex b/sdk/elixir/lib/dagger/gen/cache_sharing_mode.ex index e6f83b8dcdf..549f9d6a7c1 100644 --- a/sdk/elixir/lib/dagger/gen/cache_sharing_mode.ex +++ b/sdk/elixir/lib/dagger/gen/cache_sharing_mode.ex @@ -1,28 +1,18 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.CacheSharingMode do @moduledoc "Sharing mode of the cache volume." - @type t() :: :LOCKED | :PRIVATE | :SHARED - ( - @doc "Shares the cache volume amongst many build pipelines, but will serialize the writes" - @spec locked() :: :LOCKED - def locked() do - :LOCKED - end - ) - ( - @doc "Keeps a cache volume for a single build pipeline" - @spec private() :: :PRIVATE - def private() do - :PRIVATE - end - ) + @type t() :: :SHARED | :PRIVATE | :LOCKED - ( - @doc "Shares the cache volume amongst many build pipelines" - @spec shared() :: :SHARED - def shared() do - :SHARED - end - ) + @doc "Shares the cache volume amongst many build pipelines" + @spec shared() :: :SHARED + def shared(), do: :SHARED + + @doc "Keeps a cache volume for a single build pipeline" + @spec private() :: :PRIVATE + def private(), do: :PRIVATE + + @doc "Shares the cache volume amongst many build pipelines, but will serialize the writes" + @spec locked() :: :LOCKED + def locked(), do: :LOCKED end diff --git a/sdk/elixir/lib/dagger/gen/cache_volume.ex b/sdk/elixir/lib/dagger/gen/cache_volume.ex index 25ab60db217..873be95e68a 100644 --- a/sdk/elixir/lib/dagger/gen/cache_volume.ex +++ b/sdk/elixir/lib/dagger/gen/cache_volume.ex @@ -1,16 +1,21 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.CacheVolume do @moduledoc "A directory whose contents persist across runs." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this CacheVolume." - @spec id(t()) :: {:ok, Dagger.CacheVolumeID.t()} | {:error, term()} - def id(%__MODULE__{} = cache_volume) do - selection = select(cache_volume.selection, "id") - execute(selection, cache_volume.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this CacheVolume." + @spec id(t()) :: {:ok, Dagger.CacheVolumeID.t()} | {:error, term()} + def id(%__MODULE__{} = cache_volume) do + selection = + cache_volume.selection |> select("id") + + execute(selection, cache_volume.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/cache_volume_id.ex b/sdk/elixir/lib/dagger/gen/cache_volume_id.ex index b7c00c2698a..772cfa40e75 100644 --- a/sdk/elixir/lib/dagger/gen/cache_volume_id.ex +++ b/sdk/elixir/lib/dagger/gen/cache_volume_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.CacheVolumeID do @moduledoc "The `CacheVolumeID` scalar type represents an identifier for an object of type CacheVolume." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/client.ex b/sdk/elixir/lib/dagger/gen/client.ex index c0310cb7d51..28a84a31082 100644 --- a/sdk/elixir/lib/dagger/gen/client.ex +++ b/sdk/elixir/lib/dagger/gen/client.ex @@ -1,680 +1,725 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Client do @moduledoc "The root of the DAG." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - ( - @doc "Retrieves a content-addressed blob.\n\n## Required Arguments\n\n* `digest` - Digest of the blob\n* `size` - Size of the blob\n* `media_type` - Media type of the blob\n* `uncompressed` - Digest of the uncompressed blob" - @spec blob(t(), Dagger.String.t(), Dagger.Int.t(), Dagger.String.t(), Dagger.String.t()) :: - Dagger.Directory.t() - def blob(%__MODULE__{} = query, digest, size, media_type, uncompressed) do - selection = select(query.selection, "blob") - selection = arg(selection, "digest", digest) - selection = arg(selection, "size", size) - selection = arg(selection, "mediaType", media_type) - selection = arg(selection, "uncompressed", uncompressed) - %Dagger.Directory{selection: selection, client: query.client} - end - ) - - ( - @doc "Constructs a cache volume for a given cache key.\n\n## Required Arguments\n\n* `key` - A string identifier to target this cache volume (e.g., \"modules-cache\")." - @spec cache_volume(t(), Dagger.String.t()) :: Dagger.CacheVolume.t() - def cache_volume(%__MODULE__{} = query, key) do - selection = select(query.selection, "cacheVolume") - selection = arg(selection, "key", key) - %Dagger.CacheVolume{selection: selection, client: query.client} - end - ) - - ( - @doc "Checks if the current Dagger Engine is compatible with an SDK's required version.\n\n## Required Arguments\n\n* `version` - Version required by the SDK." - @spec check_version_compatibility(t(), Dagger.String.t()) :: - {:ok, Dagger.Boolean.t()} | {:error, term()} - def check_version_compatibility(%__MODULE__{} = query, version) do - selection = select(query.selection, "checkVersionCompatibility") - selection = arg(selection, "version", version) - execute(selection, query.client) - end - ) - - ( - @doc "Creates a scratch container.\n\nOptional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.\n\n\n\n## Optional Arguments\n\n* `id` - DEPRECATED: Use `loadContainerFromID` instead.\n* `platform` - Platform to initialize the container with." - @spec container(t(), keyword()) :: Dagger.Container.t() - def container(%__MODULE__{} = query, optional_args \\ []) do - selection = select(query.selection, "container") - - selection = - if is_nil(optional_args[:id]) do - selection - else - {:ok, id} = Dagger.Container.id(optional_args[:id]) - arg(selection, "id", id) - end - - selection = - if is_nil(optional_args[:platform]) do - selection - else - arg(selection, "platform", optional_args[:platform]) - end - - %Dagger.Container{selection: selection, client: query.client} - end - ) - - ( - @doc "The FunctionCall context that the SDK caller is currently executing in.\n\nIf the caller is not currently executing in a function, this will return an error." - @spec current_function_call(t()) :: Dagger.FunctionCall.t() - def current_function_call(%__MODULE__{} = query) do - selection = select(query.selection, "currentFunctionCall") - %Dagger.FunctionCall{selection: selection, client: query.client} - end - ) - - ( - @doc "The module currently being served in the session, if any." - @spec current_module(t()) :: Dagger.CurrentModule.t() - def current_module(%__MODULE__{} = query) do - selection = select(query.selection, "currentModule") - %Dagger.CurrentModule{selection: selection, client: query.client} - end - ) - - ( - @doc "The TypeDef representations of the objects currently being served in the session." - @spec current_type_defs(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} - def current_type_defs(%__MODULE__{} = query) do - selection = select(query.selection, "currentTypeDefs") - - selection = - select( - selection, - "asInput asInterface asList asObject id kind optional withConstructor withField withFunction withInterface withKind withListOf withObject withOptional" - ) - - with {:ok, data} <- execute(selection, query.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadTypeDefFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.TypeDef{selection: elem_selection, client: query.client} - end)} - end - end - ) - - ( - @doc "The default platform of the engine." - @spec default_platform(t()) :: {:ok, Dagger.Platform.t()} | {:error, term()} - def default_platform(%__MODULE__{} = query) do - selection = select(query.selection, "defaultPlatform") - execute(selection, query.client) - end - ) - - ( - @doc "Creates an empty directory.\n\n\n\n## Optional Arguments\n\n* `id` - DEPRECATED: Use `loadDirectoryFromID` isntead." - @spec directory(t(), keyword()) :: Dagger.Directory.t() - def directory(%__MODULE__{} = query, optional_args \\ []) do - selection = select(query.selection, "directory") - - selection = - if is_nil(optional_args[:id]) do - selection - else - {:ok, id} = Dagger.Directory.id(optional_args[:id]) - arg(selection, "id", id) - end - - %Dagger.Directory{selection: selection, client: query.client} - end - ) - - ( - @doc "## Required Arguments\n\n* `id` -" - @deprecated "Use `load_file_from_id` instead" - @spec file(t(), Dagger.FileID.t()) :: Dagger.File.t() - def file(%__MODULE__{} = query, file) do - selection = select(query.selection, "file") - selection = arg(selection, "id", file) - %Dagger.File{selection: selection, client: query.client} - end - ) - - ( - @doc "Creates a function.\n\n## Required Arguments\n\n* `name` - Name of the function, in its original format from the implementation language.\n* `return_type` - Return type of the function." - @spec function(t(), Dagger.String.t(), Dagger.TypeDef.t()) :: Dagger.Function.t() - def function(%__MODULE__{} = query, name, return_type) do - selection = select(query.selection, "function") - selection = arg(selection, "name", name) - - ( - {:ok, id} = Dagger.TypeDef.id(return_type) - selection = arg(selection, "returnType", id) - ) - - %Dagger.Function{selection: selection, client: query.client} - end - ) - - ( - @doc "Create a code generation result, given a directory containing the generated code.\n\n## Required Arguments\n\n* `code` -" - @spec generated_code(t(), Dagger.Directory.t()) :: Dagger.GeneratedCode.t() - def generated_code(%__MODULE__{} = query, code) do - selection = select(query.selection, "generatedCode") - - ( - {:ok, id} = Dagger.Directory.id(code) - selection = arg(selection, "code", id) - ) - - %Dagger.GeneratedCode{selection: selection, client: query.client} - end - ) - - ( - @doc "Queries a Git repository.\n\n## Required Arguments\n\n* `url` - URL of the git repository.\n\nCan be formatted as `https://{host}/{owner}/{repo}`, `git@{host}:{owner}/{repo}`.\n\nSuffix \".git\" is optional.\n\n## Optional Arguments\n\n* `keep_git_dir` - Set to true to keep .git directory.\n* `experimental_service_host` - A service which must be started before the repo is fetched.\n* `ssh_known_hosts` - Set SSH known hosts\n* `ssh_auth_socket` - Set SSH auth socket" - @spec git(t(), Dagger.String.t(), keyword()) :: Dagger.GitRepository.t() - def git(%__MODULE__{} = query, url, optional_args \\ []) do - selection = select(query.selection, "git") - selection = arg(selection, "url", url) - - selection = - if is_nil(optional_args[:keep_git_dir]) do - selection - else - arg(selection, "keepGitDir", optional_args[:keep_git_dir]) - end - - selection = - if is_nil(optional_args[:experimental_service_host]) do - selection - else - {:ok, id} = Dagger.Service.id(optional_args[:experimental_service_host]) - arg(selection, "experimentalServiceHost", id) - end - - selection = - if is_nil(optional_args[:ssh_known_hosts]) do - selection - else - arg(selection, "sshKnownHosts", optional_args[:ssh_known_hosts]) - end - - selection = - if is_nil(optional_args[:ssh_auth_socket]) do - selection - else - {:ok, id} = Dagger.Socket.id(optional_args[:ssh_auth_socket]) - arg(selection, "sshAuthSocket", id) - end - - %Dagger.GitRepository{selection: selection, client: query.client} - end - ) - - ( - @doc "Queries the host environment." - @spec host(t()) :: Dagger.Host.t() - def host(%__MODULE__{} = query) do - selection = select(query.selection, "host") - %Dagger.Host{selection: selection, client: query.client} - end - ) - - ( - @doc "Returns a file containing an http remote url content.\n\n## Required Arguments\n\n* `url` - HTTP url to get the content from (e.g., \"https://docs.dagger.io\").\n\n## Optional Arguments\n\n* `experimental_service_host` - A service which must be started before the URL is fetched." - @spec http(t(), Dagger.String.t(), keyword()) :: Dagger.File.t() - def http(%__MODULE__{} = query, url, optional_args \\ []) do - selection = select(query.selection, "http") - selection = arg(selection, "url", url) - - selection = - if is_nil(optional_args[:experimental_service_host]) do - selection - else - {:ok, id} = Dagger.Service.id(optional_args[:experimental_service_host]) - arg(selection, "experimentalServiceHost", id) - end - - %Dagger.File{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a CacheVolume from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_cache_volume_from_id(t(), Dagger.CacheVolume.t()) :: Dagger.CacheVolume.t() - def load_cache_volume_from_id(%__MODULE__{} = query, cache_volume) do - selection = select(query.selection, "loadCacheVolumeFromID") - selection = arg(selection, "id", cache_volume) - %Dagger.CacheVolume{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Container from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_container_from_id(t(), Dagger.Container.t()) :: Dagger.Container.t() - def load_container_from_id(%__MODULE__{} = query, container) do - selection = select(query.selection, "loadContainerFromID") - selection = arg(selection, "id", container) - %Dagger.Container{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a CurrentModule from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_current_module_from_id(t(), Dagger.CurrentModule.t()) :: Dagger.CurrentModule.t() - def load_current_module_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadCurrentModuleFromID") - selection = arg(selection, "id", id) - %Dagger.CurrentModule{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Directory from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_directory_from_id(t(), Dagger.Directory.t()) :: Dagger.Directory.t() - def load_directory_from_id(%__MODULE__{} = query, directory) do - selection = select(query.selection, "loadDirectoryFromID") - selection = arg(selection, "id", directory) - %Dagger.Directory{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a EnvVariable from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_env_variable_from_id(t(), Dagger.EnvVariable.t()) :: Dagger.EnvVariable.t() - def load_env_variable_from_id(%__MODULE__{} = query, env_variable) do - selection = select(query.selection, "loadEnvVariableFromID") - selection = arg(selection, "id", env_variable) - %Dagger.EnvVariable{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a FieldTypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_field_type_def_from_id(t(), Dagger.FieldTypeDef.t()) :: Dagger.FieldTypeDef.t() - def load_field_type_def_from_id(%__MODULE__{} = query, field_type_def) do - selection = select(query.selection, "loadFieldTypeDefFromID") - selection = arg(selection, "id", field_type_def) - %Dagger.FieldTypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a File from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_file_from_id(t(), Dagger.File.t()) :: Dagger.File.t() - def load_file_from_id(%__MODULE__{} = query, file) do - selection = select(query.selection, "loadFileFromID") - selection = arg(selection, "id", file) - %Dagger.File{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a FunctionArg from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_function_arg_from_id(t(), Dagger.FunctionArg.t()) :: Dagger.FunctionArg.t() - def load_function_arg_from_id(%__MODULE__{} = query, function_arg) do - selection = select(query.selection, "loadFunctionArgFromID") - selection = arg(selection, "id", function_arg) - %Dagger.FunctionArg{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a FunctionCallArgValue from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_function_call_arg_value_from_id(t(), Dagger.FunctionCallArgValue.t()) :: - Dagger.FunctionCallArgValue.t() - def load_function_call_arg_value_from_id(%__MODULE__{} = query, function_call_arg_value) do - selection = select(query.selection, "loadFunctionCallArgValueFromID") - selection = arg(selection, "id", function_call_arg_value) - %Dagger.FunctionCallArgValue{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a FunctionCall from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_function_call_from_id(t(), Dagger.FunctionCall.t()) :: Dagger.FunctionCall.t() - def load_function_call_from_id(%__MODULE__{} = query, function_call) do - selection = select(query.selection, "loadFunctionCallFromID") - selection = arg(selection, "id", function_call) - %Dagger.FunctionCall{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Function from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_function_from_id(t(), Dagger.Function.t()) :: Dagger.Function.t() - def load_function_from_id(%__MODULE__{} = query, function) do - selection = select(query.selection, "loadFunctionFromID") - selection = arg(selection, "id", function) - %Dagger.Function{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a GeneratedCode from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_generated_code_from_id(t(), Dagger.GeneratedCode.t()) :: Dagger.GeneratedCode.t() - def load_generated_code_from_id(%__MODULE__{} = query, generated_code) do - selection = select(query.selection, "loadGeneratedCodeFromID") - selection = arg(selection, "id", generated_code) - %Dagger.GeneratedCode{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a GitModuleSource from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_git_module_source_from_id(t(), Dagger.GitModuleSource.t()) :: - Dagger.GitModuleSource.t() - def load_git_module_source_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadGitModuleSourceFromID") - selection = arg(selection, "id", id) - %Dagger.GitModuleSource{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a GitRef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_git_ref_from_id(t(), Dagger.GitRef.t()) :: Dagger.GitRef.t() - def load_git_ref_from_id(%__MODULE__{} = query, git_ref) do - selection = select(query.selection, "loadGitRefFromID") - selection = arg(selection, "id", git_ref) - %Dagger.GitRef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a GitRepository from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_git_repository_from_id(t(), Dagger.GitRepository.t()) :: Dagger.GitRepository.t() - def load_git_repository_from_id(%__MODULE__{} = query, git_repository) do - selection = select(query.selection, "loadGitRepositoryFromID") - selection = arg(selection, "id", git_repository) - %Dagger.GitRepository{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Host from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_host_from_id(t(), Dagger.Host.t()) :: Dagger.Host.t() - def load_host_from_id(%__MODULE__{} = query, host) do - selection = select(query.selection, "loadHostFromID") - selection = arg(selection, "id", host) - %Dagger.Host{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a InputTypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_input_type_def_from_id(t(), Dagger.InputTypeDef.t()) :: Dagger.InputTypeDef.t() - def load_input_type_def_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadInputTypeDefFromID") - selection = arg(selection, "id", id) - %Dagger.InputTypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a InterfaceTypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_interface_type_def_from_id(t(), Dagger.InterfaceTypeDef.t()) :: - Dagger.InterfaceTypeDef.t() - def load_interface_type_def_from_id(%__MODULE__{} = query, interface_type_def) do - selection = select(query.selection, "loadInterfaceTypeDefFromID") - selection = arg(selection, "id", interface_type_def) - %Dagger.InterfaceTypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Label from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_label_from_id(t(), Dagger.Label.t()) :: Dagger.Label.t() - def load_label_from_id(%__MODULE__{} = query, label) do - selection = select(query.selection, "loadLabelFromID") - selection = arg(selection, "id", label) - %Dagger.Label{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a ListTypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_list_type_def_from_id(t(), Dagger.ListTypeDef.t()) :: Dagger.ListTypeDef.t() - def load_list_type_def_from_id(%__MODULE__{} = query, list_type_def) do - selection = select(query.selection, "loadListTypeDefFromID") - selection = arg(selection, "id", list_type_def) - %Dagger.ListTypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a LocalModuleSource from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_local_module_source_from_id(t(), Dagger.LocalModuleSource.t()) :: - Dagger.LocalModuleSource.t() - def load_local_module_source_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadLocalModuleSourceFromID") - selection = arg(selection, "id", id) - %Dagger.LocalModuleSource{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a ModuleDependency from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_module_dependency_from_id(t(), Dagger.ModuleDependency.t()) :: - Dagger.ModuleDependency.t() - def load_module_dependency_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadModuleDependencyFromID") - selection = arg(selection, "id", id) - %Dagger.ModuleDependency{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Module from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_module_from_id(t(), Dagger.Module.t()) :: Dagger.Module.t() - def load_module_from_id(%__MODULE__{} = query, module) do - selection = select(query.selection, "loadModuleFromID") - selection = arg(selection, "id", module) - %Dagger.Module{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a ModuleSource from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_module_source_from_id(t(), Dagger.ModuleSource.t()) :: Dagger.ModuleSource.t() - def load_module_source_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadModuleSourceFromID") - selection = arg(selection, "id", id) - %Dagger.ModuleSource{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a ObjectTypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_object_type_def_from_id(t(), Dagger.ObjectTypeDef.t()) :: Dagger.ObjectTypeDef.t() - def load_object_type_def_from_id(%__MODULE__{} = query, object_type_def) do - selection = select(query.selection, "loadObjectTypeDefFromID") - selection = arg(selection, "id", object_type_def) - %Dagger.ObjectTypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Port from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_port_from_id(t(), Dagger.Port.t()) :: Dagger.Port.t() - def load_port_from_id(%__MODULE__{} = query, port) do - selection = select(query.selection, "loadPortFromID") - selection = arg(selection, "id", port) - %Dagger.Port{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Secret from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_secret_from_id(t(), Dagger.Secret.t()) :: Dagger.Secret.t() - def load_secret_from_id(%__MODULE__{} = query, secret) do - selection = select(query.selection, "loadSecretFromID") - selection = arg(selection, "id", secret) - %Dagger.Secret{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Service from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_service_from_id(t(), Dagger.Service.t()) :: Dagger.Service.t() - def load_service_from_id(%__MODULE__{} = query, service) do - selection = select(query.selection, "loadServiceFromID") - selection = arg(selection, "id", service) - %Dagger.Service{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Socket from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_socket_from_id(t(), Dagger.Socket.t()) :: Dagger.Socket.t() - def load_socket_from_id(%__MODULE__{} = query, socket) do - selection = select(query.selection, "loadSocketFromID") - selection = arg(selection, "id", socket) - %Dagger.Socket{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a Terminal from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_terminal_from_id(t(), Dagger.Terminal.t()) :: Dagger.Terminal.t() - def load_terminal_from_id(%__MODULE__{} = query, id) do - selection = select(query.selection, "loadTerminalFromID") - selection = arg(selection, "id", id) - %Dagger.Terminal{selection: selection, client: query.client} - end - ) - - ( - @doc "Load a TypeDef from its ID.\n\n## Required Arguments\n\n* `id` -" - @spec load_type_def_from_id(t(), Dagger.TypeDef.t()) :: Dagger.TypeDef.t() - def load_type_def_from_id(%__MODULE__{} = query, type_def) do - selection = select(query.selection, "loadTypeDefFromID") - selection = arg(selection, "id", type_def) - %Dagger.TypeDef{selection: selection, client: query.client} - end - ) - - ( - @doc "Create a new module." - @spec module(t()) :: Dagger.Module.t() - def module(%__MODULE__{} = query) do - selection = select(query.selection, "module") - %Dagger.Module{selection: selection, client: query.client} - end - ) - - ( - @doc "Create a new module dependency configuration from a module source and name\n\n## Required Arguments\n\n* `source` - The source of the dependency\n\n## Optional Arguments\n\n* `name` - If set, the name to use for the dependency. Otherwise, once installed to a parent module, the name of the dependency module will be used by default." - @spec module_dependency(t(), Dagger.ModuleSource.t(), keyword()) :: - Dagger.ModuleDependency.t() - def module_dependency(%__MODULE__{} = query, source, optional_args \\ []) do - selection = select(query.selection, "moduleDependency") - selection = arg(selection, "source", source) - - selection = - if is_nil(optional_args[:name]) do - selection - else - arg(selection, "name", optional_args[:name]) - end - - %Dagger.ModuleDependency{selection: selection, client: query.client} - end - ) - - ( - @doc "Create a new module source instance from a source ref string.\n\n## Required Arguments\n\n* `ref_string` - The string ref representation of the module source\n\n## Optional Arguments\n\n* `stable` - If true, enforce that the source is a stable version for source kinds that support versioning." - @spec module_source(t(), Dagger.String.t(), keyword()) :: Dagger.ModuleSource.t() - def module_source(%__MODULE__{} = query, ref_string, optional_args \\ []) do - selection = select(query.selection, "moduleSource") - selection = arg(selection, "refString", ref_string) - - selection = - if is_nil(optional_args[:stable]) do - selection - else - arg(selection, "stable", optional_args[:stable]) - end - - %Dagger.ModuleSource{selection: selection, client: query.client} - end - ) - - ( - @doc "Creates a named sub-pipeline.\n\n## Required Arguments\n\n* `name` - Name of the sub-pipeline.\n\n## Optional Arguments\n\n* `description` - Description of the sub-pipeline.\n* `labels` - Labels to apply to the sub-pipeline." - @spec pipeline(t(), Dagger.String.t(), keyword()) :: Dagger.Client.t() - def pipeline(%__MODULE__{} = query, name, optional_args \\ []) do - selection = select(query.selection, "pipeline") - selection = arg(selection, "name", name) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - selection = - if is_nil(optional_args[:labels]) do - selection - else - arg(selection, "labels", optional_args[:labels]) - end - - %Dagger.Client{selection: selection, client: query.client} - end - ) - - ( - @doc "Reference a secret by name.\n\n## Required Arguments\n\n* `name` -" - @spec secret(t(), Dagger.String.t()) :: Dagger.Secret.t() - def secret(%__MODULE__{} = query, name) do - selection = select(query.selection, "secret") - selection = arg(selection, "name", name) - %Dagger.Secret{selection: selection, client: query.client} - end - ) - - ( - @doc "Sets a secret given a user defined name to its plaintext and returns the secret.\n\nThe plaintext value is limited to a size of 128000 bytes.\n\n## Required Arguments\n\n* `name` - The user defined name for this secret\n* `plaintext` - The plaintext of the secret" - @spec set_secret(t(), Dagger.String.t(), Dagger.String.t()) :: Dagger.Secret.t() - def set_secret(%__MODULE__{} = query, name, plaintext) do - selection = select(query.selection, "setSecret") - selection = arg(selection, "name", name) - selection = arg(selection, "plaintext", plaintext) - %Dagger.Secret{selection: selection, client: query.client} - end - ) + use Dagger.Core.QueryBuilder - ( - @doc "Loads a socket by its ID.\n\n## Required Arguments\n\n* `id` -" - @deprecated "Use `load_socket_from_id` instead" - @spec socket(t(), Dagger.Socket.t()) :: Dagger.Socket.t() - def socket(%__MODULE__{} = query, socket) do - selection = select(query.selection, "socket") + defstruct [:selection, :client] - ( - {:ok, id} = Dagger.Socket.id(socket) - selection = arg(selection, "id", id) - ) + @type t() :: %__MODULE__{} - %Dagger.Socket{selection: selection, client: query.client} - end - ) - - ( - @doc "Create a new TypeDef." - @spec type_def(t()) :: Dagger.TypeDef.t() - def type_def(%__MODULE__{} = query) do - selection = select(query.selection, "typeDef") - %Dagger.TypeDef{selection: selection, client: query.client} - end - ) + @doc "Retrieves a content-addressed blob." + @spec blob(t(), String.t(), integer(), String.t(), String.t()) :: Dagger.Directory.t() + def blob(%__MODULE__{} = client, digest, size, media_type, uncompressed) do + selection = + client.selection + |> select("blob") + |> put_arg("digest", digest) + |> put_arg("size", size) + |> put_arg("mediaType", media_type) + |> put_arg("uncompressed", uncompressed) + + %Dagger.Directory{ + selection: selection, + client: client.client + } + end + + @doc "Constructs a cache volume for a given cache key." + @spec cache_volume(t(), String.t()) :: Dagger.CacheVolume.t() + def cache_volume(%__MODULE__{} = client, key) do + selection = + client.selection |> select("cacheVolume") |> put_arg("key", key) + + %Dagger.CacheVolume{ + selection: selection, + client: client.client + } + end + + @doc "Checks if the current Dagger Engine is compatible with an SDK's required version." + @spec check_version_compatibility(t(), String.t()) :: {:ok, boolean()} | {:error, term()} + def check_version_compatibility(%__MODULE__{} = client, version) do + selection = + client.selection |> select("checkVersionCompatibility") |> put_arg("version", version) + + execute(selection, client.client) + end + + @doc """ + Creates a scratch container. + + Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host. + """ + @spec container(t(), [ + {:id, Dagger.ContainerID.t() | nil}, + {:platform, Dagger.Platform.t() | nil} + ]) :: Dagger.Container.t() + def container(%__MODULE__{} = client, optional_args \\ []) do + selection = + client.selection + |> select("container") + |> maybe_put_arg("id", optional_args[:id]) + |> maybe_put_arg("platform", optional_args[:platform]) + + %Dagger.Container{ + selection: selection, + client: client.client + } + end + + @doc """ + The FunctionCall context that the SDK caller is currently executing in. + + If the caller is not currently executing in a function, this will return an error. + """ + @spec current_function_call(t()) :: Dagger.FunctionCall.t() + def current_function_call(%__MODULE__{} = client) do + selection = + client.selection |> select("currentFunctionCall") + + %Dagger.FunctionCall{ + selection: selection, + client: client.client + } + end + + @doc "The module currently being served in the session, if any." + @spec current_module(t()) :: Dagger.CurrentModule.t() + def current_module(%__MODULE__{} = client) do + selection = + client.selection |> select("currentModule") + + %Dagger.CurrentModule{ + selection: selection, + client: client.client + } + end + + @doc "The TypeDef representations of the objects currently being served in the session." + @spec current_type_defs(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} + def current_type_defs(%__MODULE__{} = client) do + selection = + client.selection |> select("currentTypeDefs") |> select("id") + + with {:ok, items} <- execute(selection, client.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.TypeDef{ + selection: + query() + |> select("loadTypeDefFromID") + |> arg("id", id), + client: client.client + } + end} + end + end + + @doc "The default platform of the engine." + @spec default_platform(t()) :: {:ok, Dagger.Platform.t()} | {:error, term()} + def default_platform(%__MODULE__{} = client) do + selection = + client.selection |> select("defaultPlatform") + + execute(selection, client.client) + end + + @doc "Creates an empty directory." + @spec directory(t(), [{:id, Dagger.DirectoryID.t() | nil}]) :: Dagger.Directory.t() + def directory(%__MODULE__{} = client, optional_args \\ []) do + selection = + client.selection |> select("directory") |> maybe_put_arg("id", optional_args[:id]) + + %Dagger.Directory{ + selection: selection, + client: client.client + } + end + + @deprecated "Use `load_file_from_id` instead." + + @spec file(t(), Dagger.FileID.t()) :: Dagger.File.t() + def file(%__MODULE__{} = client, id) do + selection = + client.selection |> select("file") |> put_arg("id", id) + + %Dagger.File{ + selection: selection, + client: client.client + } + end + + @doc "Creates a function." + @spec function(t(), String.t(), Dagger.TypeDef.t()) :: Dagger.Function.t() + def function(%__MODULE__{} = client, name, return_type) do + selection = + client.selection + |> select("function") + |> put_arg("name", name) + |> put_arg("returnType", Dagger.ID.id!(return_type)) + + %Dagger.Function{ + selection: selection, + client: client.client + } + end + + @doc "Create a code generation result, given a directory containing the generated code." + @spec generated_code(t(), Dagger.Directory.t()) :: Dagger.GeneratedCode.t() + def generated_code(%__MODULE__{} = client, code) do + selection = + client.selection |> select("generatedCode") |> put_arg("code", Dagger.ID.id!(code)) + + %Dagger.GeneratedCode{ + selection: selection, + client: client.client + } + end + + @doc "Queries a Git repository." + @spec git(t(), String.t(), [ + {:keep_git_dir, boolean() | nil}, + {:experimental_service_host, Dagger.ServiceID.t() | nil}, + {:ssh_known_hosts, String.t() | nil}, + {:ssh_auth_socket, Dagger.SocketID.t() | nil} + ]) :: Dagger.GitRepository.t() + def git(%__MODULE__{} = client, url, optional_args \\ []) do + selection = + client.selection + |> select("git") + |> put_arg("url", url) + |> maybe_put_arg("keepGitDir", optional_args[:keep_git_dir]) + |> maybe_put_arg("experimentalServiceHost", optional_args[:experimental_service_host]) + |> maybe_put_arg("sshKnownHosts", optional_args[:ssh_known_hosts]) + |> maybe_put_arg("sshAuthSocket", optional_args[:ssh_auth_socket]) + + %Dagger.GitRepository{ + selection: selection, + client: client.client + } + end + + @doc "Queries the host environment." + @spec host(t()) :: Dagger.Host.t() + def host(%__MODULE__{} = client) do + selection = + client.selection |> select("host") + + %Dagger.Host{ + selection: selection, + client: client.client + } + end + + @doc "Returns a file containing an http remote url content." + @spec http(t(), String.t(), [{:experimental_service_host, Dagger.ServiceID.t() | nil}]) :: + Dagger.File.t() + def http(%__MODULE__{} = client, url, optional_args \\ []) do + selection = + client.selection + |> select("http") + |> put_arg("url", url) + |> maybe_put_arg("experimentalServiceHost", optional_args[:experimental_service_host]) + + %Dagger.File{ + selection: selection, + client: client.client + } + end + + @doc "Load a CacheVolume from its ID." + @spec load_cache_volume_from_id(t(), Dagger.CacheVolumeID.t()) :: Dagger.CacheVolume.t() + def load_cache_volume_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadCacheVolumeFromID") |> put_arg("id", id) + + %Dagger.CacheVolume{ + selection: selection, + client: client.client + } + end + + @doc "Load a Container from its ID." + @spec load_container_from_id(t(), Dagger.ContainerID.t()) :: Dagger.Container.t() + def load_container_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadContainerFromID") |> put_arg("id", id) + + %Dagger.Container{ + selection: selection, + client: client.client + } + end + + @doc "Load a CurrentModule from its ID." + @spec load_current_module_from_id(t(), Dagger.CurrentModuleID.t()) :: Dagger.CurrentModule.t() + def load_current_module_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadCurrentModuleFromID") |> put_arg("id", id) + + %Dagger.CurrentModule{ + selection: selection, + client: client.client + } + end + + @doc "Load a Directory from its ID." + @spec load_directory_from_id(t(), Dagger.DirectoryID.t()) :: Dagger.Directory.t() + def load_directory_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadDirectoryFromID") |> put_arg("id", id) + + %Dagger.Directory{ + selection: selection, + client: client.client + } + end + + @doc "Load a EnvVariable from its ID." + @spec load_env_variable_from_id(t(), Dagger.EnvVariableID.t()) :: Dagger.EnvVariable.t() + def load_env_variable_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadEnvVariableFromID") |> put_arg("id", id) + + %Dagger.EnvVariable{ + selection: selection, + client: client.client + } + end + + @doc "Load a FieldTypeDef from its ID." + @spec load_field_type_def_from_id(t(), Dagger.FieldTypeDefID.t()) :: Dagger.FieldTypeDef.t() + def load_field_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFieldTypeDefFromID") |> put_arg("id", id) + + %Dagger.FieldTypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Load a File from its ID." + @spec load_file_from_id(t(), Dagger.FileID.t()) :: Dagger.File.t() + def load_file_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFileFromID") |> put_arg("id", id) + + %Dagger.File{ + selection: selection, + client: client.client + } + end + + @doc "Load a FunctionArg from its ID." + @spec load_function_arg_from_id(t(), Dagger.FunctionArgID.t()) :: Dagger.FunctionArg.t() + def load_function_arg_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFunctionArgFromID") |> put_arg("id", id) + + %Dagger.FunctionArg{ + selection: selection, + client: client.client + } + end + + @doc "Load a FunctionCallArgValue from its ID." + @spec load_function_call_arg_value_from_id(t(), Dagger.FunctionCallArgValueID.t()) :: + Dagger.FunctionCallArgValue.t() + def load_function_call_arg_value_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFunctionCallArgValueFromID") |> put_arg("id", id) + + %Dagger.FunctionCallArgValue{ + selection: selection, + client: client.client + } + end + + @doc "Load a FunctionCall from its ID." + @spec load_function_call_from_id(t(), Dagger.FunctionCallID.t()) :: Dagger.FunctionCall.t() + def load_function_call_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFunctionCallFromID") |> put_arg("id", id) + + %Dagger.FunctionCall{ + selection: selection, + client: client.client + } + end + + @doc "Load a Function from its ID." + @spec load_function_from_id(t(), Dagger.FunctionID.t()) :: Dagger.Function.t() + def load_function_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadFunctionFromID") |> put_arg("id", id) + + %Dagger.Function{ + selection: selection, + client: client.client + } + end + + @doc "Load a GeneratedCode from its ID." + @spec load_generated_code_from_id(t(), Dagger.GeneratedCodeID.t()) :: Dagger.GeneratedCode.t() + def load_generated_code_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadGeneratedCodeFromID") |> put_arg("id", id) + + %Dagger.GeneratedCode{ + selection: selection, + client: client.client + } + end + + @doc "Load a GitModuleSource from its ID." + @spec load_git_module_source_from_id(t(), Dagger.GitModuleSourceID.t()) :: + Dagger.GitModuleSource.t() + def load_git_module_source_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadGitModuleSourceFromID") |> put_arg("id", id) + + %Dagger.GitModuleSource{ + selection: selection, + client: client.client + } + end + + @doc "Load a GitRef from its ID." + @spec load_git_ref_from_id(t(), Dagger.GitRefID.t()) :: Dagger.GitRef.t() + def load_git_ref_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadGitRefFromID") |> put_arg("id", id) + + %Dagger.GitRef{ + selection: selection, + client: client.client + } + end + + @doc "Load a GitRepository from its ID." + @spec load_git_repository_from_id(t(), Dagger.GitRepositoryID.t()) :: Dagger.GitRepository.t() + def load_git_repository_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadGitRepositoryFromID") |> put_arg("id", id) + + %Dagger.GitRepository{ + selection: selection, + client: client.client + } + end + + @doc "Load a Host from its ID." + @spec load_host_from_id(t(), Dagger.HostID.t()) :: Dagger.Host.t() + def load_host_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadHostFromID") |> put_arg("id", id) + + %Dagger.Host{ + selection: selection, + client: client.client + } + end + + @doc "Load a InputTypeDef from its ID." + @spec load_input_type_def_from_id(t(), Dagger.InputTypeDefID.t()) :: Dagger.InputTypeDef.t() + def load_input_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadInputTypeDefFromID") |> put_arg("id", id) + + %Dagger.InputTypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Load a InterfaceTypeDef from its ID." + @spec load_interface_type_def_from_id(t(), Dagger.InterfaceTypeDefID.t()) :: + Dagger.InterfaceTypeDef.t() + def load_interface_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadInterfaceTypeDefFromID") |> put_arg("id", id) + + %Dagger.InterfaceTypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Load a Label from its ID." + @spec load_label_from_id(t(), Dagger.LabelID.t()) :: Dagger.Label.t() + def load_label_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadLabelFromID") |> put_arg("id", id) + + %Dagger.Label{ + selection: selection, + client: client.client + } + end + + @doc "Load a ListTypeDef from its ID." + @spec load_list_type_def_from_id(t(), Dagger.ListTypeDefID.t()) :: Dagger.ListTypeDef.t() + def load_list_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadListTypeDefFromID") |> put_arg("id", id) + + %Dagger.ListTypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Load a LocalModuleSource from its ID." + @spec load_local_module_source_from_id(t(), Dagger.LocalModuleSourceID.t()) :: + Dagger.LocalModuleSource.t() + def load_local_module_source_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadLocalModuleSourceFromID") |> put_arg("id", id) + + %Dagger.LocalModuleSource{ + selection: selection, + client: client.client + } + end + + @doc "Load a ModuleDependency from its ID." + @spec load_module_dependency_from_id(t(), Dagger.ModuleDependencyID.t()) :: + Dagger.ModuleDependency.t() + def load_module_dependency_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadModuleDependencyFromID") |> put_arg("id", id) + + %Dagger.ModuleDependency{ + selection: selection, + client: client.client + } + end + + @doc "Load a Module from its ID." + @spec load_module_from_id(t(), Dagger.ModuleID.t()) :: Dagger.Module.t() + def load_module_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadModuleFromID") |> put_arg("id", id) + + %Dagger.Module{ + selection: selection, + client: client.client + } + end + + @doc "Load a ModuleSource from its ID." + @spec load_module_source_from_id(t(), Dagger.ModuleSourceID.t()) :: Dagger.ModuleSource.t() + def load_module_source_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadModuleSourceFromID") |> put_arg("id", id) + + %Dagger.ModuleSource{ + selection: selection, + client: client.client + } + end + + @doc "Load a ObjectTypeDef from its ID." + @spec load_object_type_def_from_id(t(), Dagger.ObjectTypeDefID.t()) :: Dagger.ObjectTypeDef.t() + def load_object_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadObjectTypeDefFromID") |> put_arg("id", id) + + %Dagger.ObjectTypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Load a Port from its ID." + @spec load_port_from_id(t(), Dagger.PortID.t()) :: Dagger.Port.t() + def load_port_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadPortFromID") |> put_arg("id", id) + + %Dagger.Port{ + selection: selection, + client: client.client + } + end + + @doc "Load a Secret from its ID." + @spec load_secret_from_id(t(), Dagger.SecretID.t()) :: Dagger.Secret.t() + def load_secret_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadSecretFromID") |> put_arg("id", id) + + %Dagger.Secret{ + selection: selection, + client: client.client + } + end + + @doc "Load a Service from its ID." + @spec load_service_from_id(t(), Dagger.ServiceID.t()) :: Dagger.Service.t() + def load_service_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadServiceFromID") |> put_arg("id", id) + + %Dagger.Service{ + selection: selection, + client: client.client + } + end + + @doc "Load a Socket from its ID." + @spec load_socket_from_id(t(), Dagger.SocketID.t()) :: Dagger.Socket.t() + def load_socket_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadSocketFromID") |> put_arg("id", id) + + %Dagger.Socket{ + selection: selection, + client: client.client + } + end + + @doc "Load a Terminal from its ID." + @spec load_terminal_from_id(t(), Dagger.TerminalID.t()) :: Dagger.Terminal.t() + def load_terminal_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadTerminalFromID") |> put_arg("id", id) + + %Dagger.Terminal{ + selection: selection, + client: client.client + } + end + + @doc "Load a TypeDef from its ID." + @spec load_type_def_from_id(t(), Dagger.TypeDefID.t()) :: Dagger.TypeDef.t() + def load_type_def_from_id(%__MODULE__{} = client, id) do + selection = + client.selection |> select("loadTypeDefFromID") |> put_arg("id", id) + + %Dagger.TypeDef{ + selection: selection, + client: client.client + } + end + + @doc "Create a new module." + @spec module(t()) :: Dagger.Module.t() + def module(%__MODULE__{} = client) do + selection = + client.selection |> select("module") + + %Dagger.Module{ + selection: selection, + client: client.client + } + end + + @doc "Create a new module dependency configuration from a module source and name" + @spec module_dependency(t(), Dagger.ModuleSource.t(), [{:name, String.t() | nil}]) :: + Dagger.ModuleDependency.t() + def module_dependency(%__MODULE__{} = client, source, optional_args \\ []) do + selection = + client.selection + |> select("moduleDependency") + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("name", optional_args[:name]) + + %Dagger.ModuleDependency{ + selection: selection, + client: client.client + } + end + + @doc "Create a new module source instance from a source ref string." + @spec module_source(t(), String.t(), [{:stable, boolean() | nil}]) :: Dagger.ModuleSource.t() + def module_source(%__MODULE__{} = client, ref_string, optional_args \\ []) do + selection = + client.selection + |> select("moduleSource") + |> put_arg("refString", ref_string) + |> maybe_put_arg("stable", optional_args[:stable]) + + %Dagger.ModuleSource{ + selection: selection, + client: client.client + } + end + + @doc "Creates a named sub-pipeline." + @spec pipeline(t(), String.t(), [ + {:description, String.t() | nil}, + {:labels, [Dagger.PipelineLabel.t()]} + ]) :: Dagger.Client.t() + def pipeline(%__MODULE__{} = client, name, optional_args \\ []) do + selection = + client.selection + |> select("pipeline") + |> put_arg("name", name) + |> maybe_put_arg("description", optional_args[:description]) + |> maybe_put_arg("labels", optional_args[:labels]) + + %Dagger.Client{ + selection: selection, + client: client.client + } + end + + @doc "Reference a secret by name." + @spec secret(t(), String.t()) :: Dagger.Secret.t() + def secret(%__MODULE__{} = client, name) do + selection = + client.selection |> select("secret") |> put_arg("name", name) + + %Dagger.Secret{ + selection: selection, + client: client.client + } + end + + @doc """ + Sets a secret given a user defined name to its plaintext and returns the secret. + + The plaintext value is limited to a size of 128000 bytes. + """ + @spec set_secret(t(), String.t(), String.t()) :: Dagger.Secret.t() + def set_secret(%__MODULE__{} = client, name, plaintext) do + selection = + client.selection + |> select("setSecret") + |> put_arg("name", name) + |> put_arg("plaintext", plaintext) + + %Dagger.Secret{ + selection: selection, + client: client.client + } + end + + @deprecated "Use `load_socket_from_id` instead." + @doc "Loads a socket by its ID." + @spec socket(t(), Dagger.SocketID.t()) :: Dagger.Socket.t() + def socket(%__MODULE__{} = client, id) do + selection = + client.selection |> select("socket") |> put_arg("id", id) + + %Dagger.Socket{ + selection: selection, + client: client.client + } + end + + @doc "Create a new TypeDef." + @spec type_def(t()) :: Dagger.TypeDef.t() + def type_def(%__MODULE__{} = client) do + selection = + client.selection |> select("typeDef") + + %Dagger.TypeDef{ + selection: selection, + client: client.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/container.ex b/sdk/elixir/lib/dagger/gen/container.ex index d75133ad0d6..dba2713da76 100644 --- a/sdk/elixir/lib/dagger/gen/container.ex +++ b/sdk/elixir/lib/dagger/gen/container.ex @@ -1,1143 +1,1050 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Container do @moduledoc "An OCI-compatible container, also known as a Docker container." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID @derive Dagger.Sync defstruct [:selection, :client] - ( - @doc "Turn the container into a Service.\n\nBe sure to set any exposed ports before this conversion." - @spec as_service(t()) :: Dagger.Service.t() - def as_service(%__MODULE__{} = container) do - selection = select(container.selection, "asService") - %Dagger.Service{selection: selection, client: container.client} - end - ) - - ( - @doc "Returns a File representing the container serialized to a tarball.\n\n\n\n## Optional Arguments\n\n* `platform_variants` - Identifiers for other platform specific containers.\n\nUsed for multi-platform images.\n* `forced_compression` - Force each layer of the image to use the specified compression algorithm.\n\nIf this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip.\n* `media_types` - Use the specified media types for the image's layers.\n\nDefaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support." - @spec as_tarball(t(), keyword()) :: Dagger.File.t() - def as_tarball(%__MODULE__{} = container, optional_args \\ []) do - selection = select(container.selection, "asTarball") - - selection = - if is_nil(optional_args[:platform_variants]) do - selection - else - ids = - optional_args[:platform_variants] - |> Enum.map(fn value -> - {:ok, id} = Dagger.Container.id(value) - id - end) - - arg(selection, "platformVariants", ids) - end - - selection = - if is_nil(optional_args[:forced_compression]) do - selection - else - arg(selection, "forcedCompression", optional_args[:forced_compression]) - end - - selection = - if is_nil(optional_args[:media_types]) do - selection - else - arg(selection, "mediaTypes", optional_args[:media_types]) - end - - %Dagger.File{selection: selection, client: container.client} - end - ) - - ( - @doc "Initializes this container from a Dockerfile build.\n\n## Required Arguments\n\n* `context` - Directory context used by the Dockerfile.\n\n## Optional Arguments\n\n* `dockerfile` - Path to the Dockerfile to use.\n* `target` - Target build stage to build.\n* `build_args` - Additional build arguments.\n* `secrets` - Secrets to pass to the build.\n\nThey will be mounted at /run/secrets/[secret-name] in the build container\n\nThey can be accessed in the Dockerfile using the \"secret\" mount type and mount path /run/secrets/[secret-name], e.g. RUN --mount=type=secret,id=my-secret curl http://example.com?token=$(cat /run/secrets/my-secret)" - @spec build(t(), Dagger.Directory.t(), keyword()) :: Dagger.Container.t() - def build(%__MODULE__{} = container, context, optional_args \\ []) do - selection = select(container.selection, "build") - - ( - {:ok, id} = Dagger.Directory.id(context) - selection = arg(selection, "context", id) - ) - - selection = - if is_nil(optional_args[:dockerfile]) do - selection - else - arg(selection, "dockerfile", optional_args[:dockerfile]) - end - - selection = - if is_nil(optional_args[:target]) do - selection - else - arg(selection, "target", optional_args[:target]) - end - - selection = - if is_nil(optional_args[:build_args]) do - selection - else - arg(selection, "buildArgs", optional_args[:build_args]) - end - - selection = - if is_nil(optional_args[:secrets]) do - selection - else - ids = - optional_args[:secrets] - |> Enum.map(fn value -> - {:ok, id} = Dagger.Secret.id(value) - id - end) - - arg(selection, "secrets", ids) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves default arguments for future commands." - @spec default_args(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def default_args(%__MODULE__{} = container) do - selection = select(container.selection, "defaultArgs") - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves a directory at the given path.\n\nMounts are included.\n\n## Required Arguments\n\n* `path` - The path of the directory to retrieve (e.g., \"./src\")." - @spec directory(t(), Dagger.String.t()) :: Dagger.Directory.t() - def directory(%__MODULE__{} = container, path) do - selection = select(container.selection, "directory") - selection = arg(selection, "path", path) - %Dagger.Directory{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves entrypoint to be prepended to the arguments of all commands." - @spec entrypoint(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def entrypoint(%__MODULE__{} = container) do - selection = select(container.selection, "entrypoint") - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves the value of the specified environment variable.\n\n## Required Arguments\n\n* `name` - The name of the environment variable to retrieve (e.g., \"PATH\")." - @spec env_variable(t(), Dagger.String.t()) :: - {:ok, Dagger.String.t() | nil} | {:error, term()} - def env_variable(%__MODULE__{} = container, name) do - selection = select(container.selection, "envVariable") - selection = arg(selection, "name", name) - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves the list of environment variables passed to commands." - @spec env_variables(t()) :: {:ok, [Dagger.EnvVariable.t()]} | {:error, term()} - def env_variables(%__MODULE__{} = container) do - selection = select(container.selection, "envVariables") - selection = select(selection, "id name value") - - with {:ok, data} <- execute(selection, container.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadEnvVariableFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.EnvVariable{selection: elem_selection, client: container.client} - end)} - end - end - ) - - ( - @doc "EXPERIMENTAL API! Subject to change/removal at any time.\n\nConfigures all available GPUs on the host to be accessible to this container.\n\nThis currently works for Nvidia devices only." - @spec experimental_with_all_gp_us(t()) :: Dagger.Container.t() - def experimental_with_all_gp_us(%__MODULE__{} = container) do - selection = select(container.selection, "experimentalWithAllGPUs") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "EXPERIMENTAL API! Subject to change/removal at any time.\n\nConfigures the provided list of devices to be accesible to this container.\n\nThis currently works for Nvidia devices only.\n\n## Required Arguments\n\n* `devices` - List of devices to be accessible to this container." - @spec experimental_with_gpu(t(), [Dagger.String.t()]) :: Dagger.Container.t() - def experimental_with_gpu(%__MODULE__{} = container, devices) do - selection = select(container.selection, "experimentalWithGPU") - selection = arg(selection, "devices", devices) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Writes the container as an OCI tarball to the destination file path on the host.\n\nReturn true on success.\n\nIt can also export platform variants.\n\n## Required Arguments\n\n* `path` - Host's destination path (e.g., \"./tarball\").\n\nPath can be relative to the engine's workdir or absolute.\n\n## Optional Arguments\n\n* `platform_variants` - Identifiers for other platform specific containers.\n\nUsed for multi-platform image.\n* `forced_compression` - Force each layer of the exported image to use the specified compression algorithm.\n\nIf this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip.\n* `media_types` - Use the specified media types for the exported image's layers.\n\nDefaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support." - @spec export(t(), Dagger.String.t(), keyword()) :: - {:ok, Dagger.Boolean.t()} | {:error, term()} - def export(%__MODULE__{} = container, path, optional_args \\ []) do - selection = select(container.selection, "export") - selection = arg(selection, "path", path) - - selection = - if is_nil(optional_args[:platform_variants]) do - selection - else - ids = - optional_args[:platform_variants] - |> Enum.map(fn value -> - {:ok, id} = Dagger.Container.id(value) - id - end) - - arg(selection, "platformVariants", ids) - end - - selection = - if is_nil(optional_args[:forced_compression]) do - selection - else - arg(selection, "forcedCompression", optional_args[:forced_compression]) - end - - selection = - if is_nil(optional_args[:media_types]) do - selection - else - arg(selection, "mediaTypes", optional_args[:media_types]) - end - - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves the list of exposed ports.\n\nThis includes ports already exposed by the image, even if not explicitly added with dagger." - @spec exposed_ports(t()) :: {:ok, [Dagger.Port.t()]} | {:error, term()} - def exposed_ports(%__MODULE__{} = container) do - selection = select(container.selection, "exposedPorts") - selection = select(selection, "description experimentalSkipHealthcheck id port protocol") - - with {:ok, data} <- execute(selection, container.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadPortFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Port{selection: elem_selection, client: container.client} - end)} - end - end - ) - - ( - @doc "Retrieves a file at the given path.\n\nMounts are included.\n\n## Required Arguments\n\n* `path` - The path of the file to retrieve (e.g., \"./README.md\")." - @spec file(t(), Dagger.String.t()) :: Dagger.File.t() - def file(%__MODULE__{} = container, path) do - selection = select(container.selection, "file") - selection = arg(selection, "path", path) - %Dagger.File{selection: selection, client: container.client} - end - ) - - ( - @doc "Initializes this container from a pulled base image.\n\n## Required Arguments\n\n* `address` - Image's address from its registry.\n\nFormatted as [host]/[user]/[repo]:[tag] (e.g., \"docker.io/dagger/dagger:main\")." - @spec from(t(), Dagger.String.t()) :: Dagger.Container.t() - def from(%__MODULE__{} = container, address) do - selection = select(container.selection, "from") - selection = arg(selection, "address", address) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "A unique identifier for this Container." - @spec id(t()) :: {:ok, Dagger.ContainerID.t()} | {:error, term()} - def id(%__MODULE__{} = container) do - selection = select(container.selection, "id") - execute(selection, container.client) - end - ) - - ( - @doc "The unique image reference which can only be retrieved immediately after the 'Container.From' call." - @spec image_ref(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def image_ref(%__MODULE__{} = container) do - selection = select(container.selection, "imageRef") - execute(selection, container.client) - end - ) - - ( - @doc "Reads the container from an OCI tarball.\n\n## Required Arguments\n\n* `source` - File to read the container from.\n\n## Optional Arguments\n\n* `tag` - Identifies the tag to import from the archive, if the archive bundles multiple tags." - @spec import(t(), Dagger.File.t(), keyword()) :: Dagger.Container.t() - def import(%__MODULE__{} = container, source, optional_args \\ []) do - selection = select(container.selection, "import") - - ( - {:ok, id} = Dagger.File.id(source) - selection = arg(selection, "source", id) - ) - - selection = - if is_nil(optional_args[:tag]) do - selection - else - arg(selection, "tag", optional_args[:tag]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves the value of the specified label.\n\n## Required Arguments\n\n* `name` - The name of the label (e.g., \"org.opencontainers.artifact.created\")." - @spec label(t(), Dagger.String.t()) :: {:ok, Dagger.String.t() | nil} | {:error, term()} - def label(%__MODULE__{} = container, name) do - selection = select(container.selection, "label") - selection = arg(selection, "name", name) - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves the list of labels passed to container." - @spec labels(t()) :: {:ok, [Dagger.Label.t()]} | {:error, term()} - def labels(%__MODULE__{} = container) do - selection = select(container.selection, "labels") - selection = select(selection, "id name value") - - with {:ok, data} <- execute(selection, container.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadLabelFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Label{selection: elem_selection, client: container.client} - end)} - end - end - ) - - ( - @doc "Retrieves the list of paths where a directory is mounted." - @spec mounts(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def mounts(%__MODULE__{} = container) do - selection = select(container.selection, "mounts") - execute(selection, container.client) - end - ) - - ( - @doc "Creates a named sub-pipeline.\n\n## Required Arguments\n\n* `name` - Name of the sub-pipeline.\n\n## Optional Arguments\n\n* `description` - Description of the sub-pipeline.\n* `labels` - Labels to apply to the sub-pipeline." - @spec pipeline(t(), Dagger.String.t(), keyword()) :: Dagger.Container.t() - def pipeline(%__MODULE__{} = container, name, optional_args \\ []) do - selection = select(container.selection, "pipeline") - selection = arg(selection, "name", name) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - selection = - if is_nil(optional_args[:labels]) do - selection - else - arg(selection, "labels", optional_args[:labels]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "The platform this container executes and publishes as." - @spec platform(t()) :: {:ok, Dagger.Platform.t()} | {:error, term()} - def platform(%__MODULE__{} = container) do - selection = select(container.selection, "platform") - execute(selection, container.client) - end - ) - - ( - @doc "Publishes this container as a new image to the specified address.\n\nPublish returns a fully qualified ref.\n\nIt can also publish platform variants.\n\n## Required Arguments\n\n* `address` - Registry's address to publish the image to.\n\nFormatted as [host]/[user]/[repo]:[tag] (e.g. \"docker.io/dagger/dagger:main\").\n\n## Optional Arguments\n\n* `platform_variants` - Identifiers for other platform specific containers.\n\nUsed for multi-platform image.\n* `forced_compression` - Force each layer of the published image to use the specified compression algorithm.\n\nIf this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip.\n* `media_types` - Use the specified media types for the published image's layers.\n\nDefaults to OCI, which is largely compatible with most recent registries, but Docker may be needed for older registries without OCI support." - @spec publish(t(), Dagger.String.t(), keyword()) :: - {:ok, Dagger.String.t()} | {:error, term()} - def publish(%__MODULE__{} = container, address, optional_args \\ []) do - selection = select(container.selection, "publish") - selection = arg(selection, "address", address) - - selection = - if is_nil(optional_args[:platform_variants]) do - selection - else - ids = - optional_args[:platform_variants] - |> Enum.map(fn value -> - {:ok, id} = Dagger.Container.id(value) - id - end) - - arg(selection, "platformVariants", ids) - end - - selection = - if is_nil(optional_args[:forced_compression]) do - selection - else - arg(selection, "forcedCompression", optional_args[:forced_compression]) - end - - selection = - if is_nil(optional_args[:media_types]) do - selection - else - arg(selection, "mediaTypes", optional_args[:media_types]) - end - - execute(selection, container.client) - end - ) - - ( - @doc "Retrieves this container's root filesystem. Mounts are not included." - @spec rootfs(t()) :: Dagger.Directory.t() - def rootfs(%__MODULE__{} = container) do - selection = select(container.selection, "rootfs") - %Dagger.Directory{selection: selection, client: container.client} - end - ) - - ( - @doc "The error stream of the last executed command.\n\nWill execute default command if none is set, or error if there's no default." - @spec stderr(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def stderr(%__MODULE__{} = container) do - selection = select(container.selection, "stderr") - execute(selection, container.client) - end - ) - - ( - @doc "The output stream of the last executed command.\n\nWill execute default command if none is set, or error if there's no default." - @spec stdout(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def stdout(%__MODULE__{} = container) do - selection = select(container.selection, "stdout") - execute(selection, container.client) - end - ) - - ( - @doc "Forces evaluation of the pipeline in the engine.\n\nIt doesn't run the default command if no exec has been set." - @spec sync(t()) :: {:ok, Dagger.ContainerID.t()} | {:error, term()} - def sync(%__MODULE__{} = container) do - selection = select(container.selection, "sync") - execute(selection, container.client) - end - ) - - ( - @doc "Return an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default).\n\n\n\n## Optional Arguments\n\n* `cmd` - If set, override the container's default terminal command and invoke these command arguments instead." - @spec terminal(t(), keyword()) :: Dagger.Terminal.t() - def terminal(%__MODULE__{} = container, optional_args \\ []) do - selection = select(container.selection, "terminal") - - selection = - if is_nil(optional_args[:cmd]) do - selection - else - arg(selection, "cmd", optional_args[:cmd]) - end - - %Dagger.Terminal{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves the user to be set for all commands." - @spec user(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def user(%__MODULE__{} = container) do - selection = select(container.selection, "user") - execute(selection, container.client) - end - ) - - ( - @doc "Configures default arguments for future commands.\n\n## Required Arguments\n\n* `args` - Arguments to prepend to future executions (e.g., [\"-v\", \"--no-cache\"])." - @spec with_default_args(t(), [Dagger.String.t()]) :: Dagger.Container.t() - def with_default_args(%__MODULE__{} = container, args) do - selection = select(container.selection, "withDefaultArgs") - selection = arg(selection, "args", args) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Set the default command to invoke for the container's terminal API.\n\n## Required Arguments\n\n* `args` - The args of the command." - @spec with_default_terminal_cmd(t(), [Dagger.String.t()]) :: Dagger.Container.t() - def with_default_terminal_cmd(%__MODULE__{} = container, args) do - selection = select(container.selection, "withDefaultTerminalCmd") - selection = arg(selection, "args", args) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a directory written at the given path.\n\n## Required Arguments\n\n* `path` - Location of the written directory (e.g., \"/tmp/directory\").\n* `directory` - Identifier of the directory to write\n\n## Optional Arguments\n\n* `exclude` - Patterns to exclude in the written directory (e.g. [\"node_modules/**\", \".gitignore\", \".git/\"]).\n* `include` - Patterns to include in the written directory (e.g. [\"*.go\", \"go.mod\", \"go.sum\"]).\n* `owner` - A user:group to set for the directory and its contents.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_directory(t(), Dagger.String.t(), Dagger.Directory.t(), keyword()) :: - Dagger.Container.t() - def with_directory(%__MODULE__{} = container, path, directory, optional_args \\ []) do - selection = select(container.selection, "withDirectory") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.Directory.id(directory) - selection = arg(selection, "directory", id) - ) - - selection = - if is_nil(optional_args[:exclude]) do - selection - else - arg(selection, "exclude", optional_args[:exclude]) - end - - selection = - if is_nil(optional_args[:include]) do - selection - else - arg(selection, "include", optional_args[:include]) - end - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container but with a different command entrypoint.\n\n## Required Arguments\n\n* `args` - Entrypoint to use for future executions (e.g., [\"go\", \"run\"]).\n\n## Optional Arguments\n\n* `keep_default_args` - Don't remove the default arguments when setting the entrypoint." - @spec with_entrypoint(t(), [Dagger.String.t()], keyword()) :: Dagger.Container.t() - def with_entrypoint(%__MODULE__{} = container, args, optional_args \\ []) do - selection = select(container.selection, "withEntrypoint") - selection = arg(selection, "args", args) - - selection = - if is_nil(optional_args[:keep_default_args]) do - selection - else - arg(selection, "keepDefaultArgs", optional_args[:keep_default_args]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus the given environment variable.\n\n## Required Arguments\n\n* `name` - The name of the environment variable (e.g., \"HOST\").\n* `value` - The value of the environment variable. (e.g., \"localhost\").\n\n## Optional Arguments\n\n* `expand` - Replace `${VAR}` or `$VAR` in the value according to the current environment variables defined in the container (e.g., \"/opt/bin:$PATH\")." - @spec with_env_variable(t(), Dagger.String.t(), Dagger.String.t(), keyword()) :: - Dagger.Container.t() - def with_env_variable(%__MODULE__{} = container, name, value, optional_args \\ []) do - selection = select(container.selection, "withEnvVariable") - selection = arg(selection, "name", name) - selection = arg(selection, "value", value) - - selection = - if is_nil(optional_args[:expand]) do - selection - else - arg(selection, "expand", optional_args[:expand]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container after executing the specified command inside it.\n\n## Required Arguments\n\n* `args` - Command to run instead of the container's default command (e.g., [\"run\", \"main.go\"]).\n\nIf empty, the container's default command is used.\n\n## Optional Arguments\n\n* `skip_entrypoint` - If the container has an entrypoint, ignore it for args rather than using it to wrap them.\n* `stdin` - Content to write to the command's standard input before closing (e.g., \"Hello world\").\n* `redirect_stdout` - Redirect the command's standard output to a file in the container (e.g., \"/tmp/stdout\").\n* `redirect_stderr` - Redirect the command's standard error to a file in the container (e.g., \"/tmp/stderr\").\n* `experimental_privileged_nesting` - Provides dagger access to the executed command.\n\nDo not use this option unless you trust the command being executed; the command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.\n* `insecure_root_capabilities` - Execute the command with all root capabilities. This is similar to running a command with \"sudo\" or executing \"docker run\" with the \"--privileged\" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands." - @spec with_exec(t(), [Dagger.String.t()], keyword()) :: Dagger.Container.t() - def with_exec(%__MODULE__{} = container, args, optional_args \\ []) do - selection = select(container.selection, "withExec") - selection = arg(selection, "args", args) - - selection = - if is_nil(optional_args[:skip_entrypoint]) do - selection - else - arg(selection, "skipEntrypoint", optional_args[:skip_entrypoint]) - end - - selection = - if is_nil(optional_args[:stdin]) do - selection - else - arg(selection, "stdin", optional_args[:stdin]) - end - - selection = - if is_nil(optional_args[:redirect_stdout]) do - selection - else - arg(selection, "redirectStdout", optional_args[:redirect_stdout]) - end - - selection = - if is_nil(optional_args[:redirect_stderr]) do - selection - else - arg(selection, "redirectStderr", optional_args[:redirect_stderr]) - end - - selection = - if is_nil(optional_args[:experimental_privileged_nesting]) do - selection - else - arg( - selection, - "experimentalPrivilegedNesting", - optional_args[:experimental_privileged_nesting] - ) - end - - selection = - if is_nil(optional_args[:insecure_root_capabilities]) do - selection - else - arg(selection, "insecureRootCapabilities", optional_args[:insecure_root_capabilities]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Expose a network port.\n\nExposed ports serve two purposes:\n\n- For health checks and introspection, when running services\n\n- For setting the EXPOSE OCI field when publishing the container\n\n## Required Arguments\n\n* `port` - Port number to expose\n\n## Optional Arguments\n\n* `protocol` - Transport layer network protocol\n* `description` - Optional port description\n* `experimental_skip_healthcheck` - Skip the health check when run as a service." - @spec with_exposed_port(t(), Dagger.Int.t(), keyword()) :: Dagger.Container.t() - def with_exposed_port(%__MODULE__{} = container, port, optional_args \\ []) do - selection = select(container.selection, "withExposedPort") - selection = arg(selection, "port", port) - - selection = - if is_nil(optional_args[:protocol]) do - selection - else - arg(selection, "protocol", optional_args[:protocol]) - end - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - selection = - if is_nil(optional_args[:experimental_skip_healthcheck]) do - selection - else - arg( - selection, - "experimentalSkipHealthcheck", - optional_args[:experimental_skip_healthcheck] - ) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus the contents of the given file copied to the given path.\n\n## Required Arguments\n\n* `path` - Location of the copied file (e.g., \"/tmp/file.txt\").\n* `source` - Identifier of the file to copy.\n\n## Optional Arguments\n\n* `permissions` - Permission given to the copied file (e.g., 0600).\n* `owner` - A user:group to set for the file.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_file(t(), Dagger.String.t(), Dagger.File.t(), keyword()) :: Dagger.Container.t() - def with_file(%__MODULE__{} = container, path, source, optional_args \\ []) do - selection = select(container.selection, "withFile") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.File.id(source) - selection = arg(selection, "source", id) - ) - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus the contents of the given files copied to the given path.\n\n## Required Arguments\n\n* `path` - Location where copied files should be placed (e.g., \"/src\").\n* `sources` - Identifiers of the files to copy.\n\n## Optional Arguments\n\n* `permissions` - Permission given to the copied files (e.g., 0600).\n* `owner` - A user:group to set for the files.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_files(t(), Dagger.String.t(), [Dagger.FileID.t()], keyword()) :: - Dagger.Container.t() - def with_files(%__MODULE__{} = container, path, sources, optional_args \\ []) do - selection = select(container.selection, "withFiles") - selection = arg(selection, "path", path) - selection = arg(selection, "sources", sources) - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Indicate that subsequent operations should be featured more prominently in the UI." - @spec with_focus(t()) :: Dagger.Container.t() - def with_focus(%__MODULE__{} = container) do - selection = select(container.selection, "withFocus") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus the given label.\n\n## Required Arguments\n\n* `name` - The name of the label (e.g., \"org.opencontainers.artifact.created\").\n* `value` - The value of the label (e.g., \"2023-01-01T00:00:00Z\")." - @spec with_label(t(), Dagger.String.t(), Dagger.String.t()) :: Dagger.Container.t() - def with_label(%__MODULE__{} = container, name, value) do - selection = select(container.selection, "withLabel") - selection = arg(selection, "name", name) - selection = arg(selection, "value", value) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a cache volume mounted at the given path.\n\n## Required Arguments\n\n* `path` - Location of the cache directory (e.g., \"/cache/node_modules\").\n* `cache` - Identifier of the cache volume to mount.\n\n## Optional Arguments\n\n* `source` - Identifier of the directory to use as the cache volume's root.\n* `sharing` - Sharing mode of the cache volume.\n* `owner` - A user:group to set for the mounted cache directory.\n\nNote that this changes the ownership of the specified mount along with the initial filesystem provided by source (if any). It does not have any effect if/when the cache has already been created.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_mounted_cache(t(), Dagger.String.t(), Dagger.CacheVolume.t(), keyword()) :: - Dagger.Container.t() - def with_mounted_cache(%__MODULE__{} = container, path, cache, optional_args \\ []) do - selection = select(container.selection, "withMountedCache") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.CacheVolume.id(cache) - selection = arg(selection, "cache", id) - ) - - selection = - if is_nil(optional_args[:source]) do - selection - else - {:ok, id} = Dagger.Directory.id(optional_args[:source]) - arg(selection, "source", id) - end - - selection = - if is_nil(optional_args[:sharing]) do - selection - else - arg(selection, "sharing", optional_args[:sharing]) - end - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a directory mounted at the given path.\n\n## Required Arguments\n\n* `path` - Location of the mounted directory (e.g., \"/mnt/directory\").\n* `source` - Identifier of the mounted directory.\n\n## Optional Arguments\n\n* `owner` - A user:group to set for the mounted directory and its contents.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_mounted_directory(t(), Dagger.String.t(), Dagger.Directory.t(), keyword()) :: - Dagger.Container.t() - def with_mounted_directory(%__MODULE__{} = container, path, source, optional_args \\ []) do - selection = select(container.selection, "withMountedDirectory") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.Directory.id(source) - selection = arg(selection, "source", id) - ) - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a file mounted at the given path.\n\n## Required Arguments\n\n* `path` - Location of the mounted file (e.g., \"/tmp/file.txt\").\n* `source` - Identifier of the mounted file.\n\n## Optional Arguments\n\n* `owner` - A user or user:group to set for the mounted file.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_mounted_file(t(), Dagger.String.t(), Dagger.File.t(), keyword()) :: - Dagger.Container.t() - def with_mounted_file(%__MODULE__{} = container, path, source, optional_args \\ []) do - selection = select(container.selection, "withMountedFile") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.File.id(source) - selection = arg(selection, "source", id) - ) - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end + @type t() :: %__MODULE__{} - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a secret mounted into a file at the given path.\n\n## Required Arguments\n\n* `path` - Location of the secret file (e.g., \"/tmp/secret.txt\").\n* `source` - Identifier of the secret to mount.\n\n## Optional Arguments\n\n* `owner` - A user:group to set for the mounted secret.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user.\n* `mode` - Permission given to the mounted secret (e.g., 0600).\n\nThis option requires an owner to be set to be active." - @spec with_mounted_secret(t(), Dagger.String.t(), Dagger.Secret.t(), keyword()) :: - Dagger.Container.t() - def with_mounted_secret(%__MODULE__{} = container, path, source, optional_args \\ []) do - selection = select(container.selection, "withMountedSecret") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.Secret.id(source) - selection = arg(selection, "source", id) + @doc """ + Turn the container into a Service. + + Be sure to set any exposed ports before this conversion. + """ + @spec as_service(t()) :: Dagger.Service.t() + def as_service(%__MODULE__{} = container) do + selection = + container.selection |> select("asService") + + %Dagger.Service{ + selection: selection, + client: container.client + } + end + + @doc "Returns a File representing the container serialized to a tarball." + @spec as_tarball(t(), [ + {:platform_variants, [Dagger.ContainerID.t()]}, + {:forced_compression, Dagger.ImageLayerCompression.t() | nil}, + {:media_types, Dagger.ImageMediaTypes.t() | nil} + ]) :: Dagger.File.t() + def as_tarball(%__MODULE__{} = container, optional_args \\ []) do + selection = + container.selection + |> select("asTarball") + |> maybe_put_arg( + "platformVariants", + if(optional_args[:platform_variants], + do: Enum.map(optional_args[:platform_variants], &Dagger.ID.id!/1), + else: nil + ) ) - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - selection = - if is_nil(optional_args[:mode]) do - selection - else - arg(selection, "mode", optional_args[:mode]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a temporary directory mounted at the given path.\n\n## Required Arguments\n\n* `path` - Location of the temporary directory (e.g., \"/tmp/temp_dir\")." - @spec with_mounted_temp(t(), Dagger.String.t()) :: Dagger.Container.t() - def with_mounted_temp(%__MODULE__{} = container, path) do - selection = select(container.selection, "withMountedTemp") - selection = arg(selection, "path", path) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a new file written at the given path.\n\n## Required Arguments\n\n* `path` - Location of the written file (e.g., \"/tmp/file.txt\").\n\n## Optional Arguments\n\n* `contents` - Content of the file to write (e.g., \"Hello world!\").\n* `permissions` - Permission given to the written file (e.g., 0600).\n* `owner` - A user:group to set for the file.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_new_file(t(), Dagger.String.t(), keyword()) :: Dagger.Container.t() - def with_new_file(%__MODULE__{} = container, path, optional_args \\ []) do - selection = select(container.selection, "withNewFile") - selection = arg(selection, "path", path) - - selection = - if is_nil(optional_args[:contents]) do - selection - else - arg(selection, "contents", optional_args[:contents]) - end - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with a registry authentication for a given address.\n\n## Required Arguments\n\n* `address` - Registry's address to bind the authentication to.\n\nFormatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main).\n* `username` - The username of the registry's account (e.g., \"Dagger\").\n* `secret` - The API key, password or token to authenticate to this registry." - @spec with_registry_auth(t(), Dagger.String.t(), Dagger.String.t(), Dagger.Secret.t()) :: - Dagger.Container.t() - def with_registry_auth(%__MODULE__{} = container, address, username, secret) do - selection = select(container.selection, "withRegistryAuth") - selection = arg(selection, "address", address) - selection = arg(selection, "username", username) - - ( - {:ok, id} = Dagger.Secret.id(secret) - selection = arg(selection, "secret", id) + |> maybe_put_arg("forcedCompression", optional_args[:forced_compression]) + |> maybe_put_arg("mediaTypes", optional_args[:media_types]) + + %Dagger.File{ + selection: selection, + client: container.client + } + end + + @doc "Initializes this container from a Dockerfile build." + @spec build(t(), Dagger.Directory.t(), [ + {:dockerfile, String.t() | nil}, + {:target, String.t() | nil}, + {:build_args, [Dagger.BuildArg.t()]}, + {:secrets, [Dagger.SecretID.t()]} + ]) :: Dagger.Container.t() + def build(%__MODULE__{} = container, context, optional_args \\ []) do + selection = + container.selection + |> select("build") + |> put_arg("context", Dagger.ID.id!(context)) + |> maybe_put_arg("dockerfile", optional_args[:dockerfile]) + |> maybe_put_arg("target", optional_args[:target]) + |> maybe_put_arg("buildArgs", optional_args[:build_args]) + |> maybe_put_arg( + "secrets", + if(optional_args[:secrets], + do: Enum.map(optional_args[:secrets], &Dagger.ID.id!/1), + else: nil + ) ) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves the container with the given directory mounted to /.\n\n## Required Arguments\n\n* `directory` - Directory to mount." - @spec with_rootfs(t(), Dagger.Directory.t()) :: Dagger.Container.t() - def with_rootfs(%__MODULE__{} = container, directory) do - selection = select(container.selection, "withRootfs") - - ( - {:ok, id} = Dagger.Directory.id(directory) - selection = arg(selection, "directory", id) + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves default arguments for future commands." + @spec default_args(t()) :: {:ok, [String.t()]} | {:error, term()} + def default_args(%__MODULE__{} = container) do + selection = + container.selection |> select("defaultArgs") + + execute(selection, container.client) + end + + @doc """ + Retrieves a directory at the given path. + + Mounts are included. + """ + @spec directory(t(), String.t()) :: Dagger.Directory.t() + def directory(%__MODULE__{} = container, path) do + selection = + container.selection |> select("directory") |> put_arg("path", path) + + %Dagger.Directory{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves entrypoint to be prepended to the arguments of all commands." + @spec entrypoint(t()) :: {:ok, [String.t()]} | {:error, term()} + def entrypoint(%__MODULE__{} = container) do + selection = + container.selection |> select("entrypoint") + + execute(selection, container.client) + end + + @doc "Retrieves the value of the specified environment variable." + @spec env_variable(t(), String.t()) :: {:ok, String.t() | nil} | {:error, term()} + def env_variable(%__MODULE__{} = container, name) do + selection = + container.selection |> select("envVariable") |> put_arg("name", name) + + execute(selection, container.client) + end + + @doc "Retrieves the list of environment variables passed to commands." + @spec env_variables(t()) :: {:ok, [Dagger.EnvVariable.t()]} | {:error, term()} + def env_variables(%__MODULE__{} = container) do + selection = + container.selection |> select("envVariables") |> select("id") + + with {:ok, items} <- execute(selection, container.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.EnvVariable{ + selection: + query() + |> select("loadEnvVariableFromID") + |> arg("id", id), + client: container.client + } + end} + end + end + + @doc """ + EXPERIMENTAL API! Subject to change/removal at any time. + + Configures all available GPUs on the host to be accessible to this container. + + This currently works for Nvidia devices only. + """ + @spec experimental_with_all_gpus(t()) :: Dagger.Container.t() + def experimental_with_all_gpus(%__MODULE__{} = container) do + selection = + container.selection |> select("experimentalWithAllGPUs") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + EXPERIMENTAL API! Subject to change/removal at any time. + + Configures the provided list of devices to be accesible to this container. + + This currently works for Nvidia devices only. + """ + @spec experimental_with_gpu(t(), [String.t()]) :: Dagger.Container.t() + def experimental_with_gpu(%__MODULE__{} = container, devices) do + selection = + container.selection |> select("experimentalWithGPU") |> put_arg("devices", devices) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Writes the container as an OCI tarball to the destination file path on the host. + + Return true on success. + + It can also export platform variants. + """ + @spec export(t(), String.t(), [ + {:platform_variants, [Dagger.ContainerID.t()]}, + {:forced_compression, Dagger.ImageLayerCompression.t() | nil}, + {:media_types, Dagger.ImageMediaTypes.t() | nil} + ]) :: {:ok, boolean()} | {:error, term()} + def export(%__MODULE__{} = container, path, optional_args \\ []) do + selection = + container.selection + |> select("export") + |> put_arg("path", path) + |> maybe_put_arg( + "platformVariants", + if(optional_args[:platform_variants], + do: Enum.map(optional_args[:platform_variants], &Dagger.ID.id!/1), + else: nil + ) ) - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus an env variable containing the given secret.\n\n## Required Arguments\n\n* `name` - The name of the secret variable (e.g., \"API_SECRET\").\n* `secret` - The identifier of the secret value." - @spec with_secret_variable(t(), Dagger.String.t(), Dagger.Secret.t()) :: Dagger.Container.t() - def with_secret_variable(%__MODULE__{} = container, name, secret) do - selection = select(container.selection, "withSecretVariable") - selection = arg(selection, "name", name) - - ( - {:ok, id} = Dagger.Secret.id(secret) - selection = arg(selection, "secret", id) + |> maybe_put_arg("forcedCompression", optional_args[:forced_compression]) + |> maybe_put_arg("mediaTypes", optional_args[:media_types]) + + execute(selection, container.client) + end + + @doc """ + Retrieves the list of exposed ports. + + This includes ports already exposed by the image, even if not explicitly added with dagger. + """ + @spec exposed_ports(t()) :: {:ok, [Dagger.Port.t()]} | {:error, term()} + def exposed_ports(%__MODULE__{} = container) do + selection = + container.selection |> select("exposedPorts") |> select("id") + + with {:ok, items} <- execute(selection, container.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Port{ + selection: + query() + |> select("loadPortFromID") + |> arg("id", id), + client: container.client + } + end} + end + end + + @doc """ + Retrieves a file at the given path. + + Mounts are included. + """ + @spec file(t(), String.t()) :: Dagger.File.t() + def file(%__MODULE__{} = container, path) do + selection = + container.selection |> select("file") |> put_arg("path", path) + + %Dagger.File{ + selection: selection, + client: container.client + } + end + + @doc "Initializes this container from a pulled base image." + @spec from(t(), String.t()) :: Dagger.Container.t() + def from(%__MODULE__{} = container, address) do + selection = + container.selection |> select("from") |> put_arg("address", address) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "A unique identifier for this Container." + @spec id(t()) :: {:ok, Dagger.ContainerID.t()} | {:error, term()} + def id(%__MODULE__{} = container) do + selection = + container.selection |> select("id") + + execute(selection, container.client) + end + + @doc "The unique image reference which can only be retrieved immediately after the 'Container.From' call." + @spec image_ref(t()) :: {:ok, String.t()} | {:error, term()} + def image_ref(%__MODULE__{} = container) do + selection = + container.selection |> select("imageRef") + + execute(selection, container.client) + end + + @doc "Reads the container from an OCI tarball." + @spec import(t(), Dagger.File.t(), [{:tag, String.t() | nil}]) :: Dagger.Container.t() + def import(%__MODULE__{} = container, source, optional_args \\ []) do + selection = + container.selection + |> select("import") + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("tag", optional_args[:tag]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves the value of the specified label." + @spec label(t(), String.t()) :: {:ok, String.t() | nil} | {:error, term()} + def label(%__MODULE__{} = container, name) do + selection = + container.selection |> select("label") |> put_arg("name", name) + + execute(selection, container.client) + end + + @doc "Retrieves the list of labels passed to container." + @spec labels(t()) :: {:ok, [Dagger.Label.t()]} | {:error, term()} + def labels(%__MODULE__{} = container) do + selection = + container.selection |> select("labels") |> select("id") + + with {:ok, items} <- execute(selection, container.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Label{ + selection: + query() + |> select("loadLabelFromID") + |> arg("id", id), + client: container.client + } + end} + end + end + + @doc "Retrieves the list of paths where a directory is mounted." + @spec mounts(t()) :: {:ok, [String.t()]} | {:error, term()} + def mounts(%__MODULE__{} = container) do + selection = + container.selection |> select("mounts") + + execute(selection, container.client) + end + + @doc "Creates a named sub-pipeline." + @spec pipeline(t(), String.t(), [ + {:description, String.t() | nil}, + {:labels, [Dagger.PipelineLabel.t()]} + ]) :: Dagger.Container.t() + def pipeline(%__MODULE__{} = container, name, optional_args \\ []) do + selection = + container.selection + |> select("pipeline") + |> put_arg("name", name) + |> maybe_put_arg("description", optional_args[:description]) + |> maybe_put_arg("labels", optional_args[:labels]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "The platform this container executes and publishes as." + @spec platform(t()) :: {:ok, Dagger.Platform.t()} | {:error, term()} + def platform(%__MODULE__{} = container) do + selection = + container.selection |> select("platform") + + execute(selection, container.client) + end + + @doc """ + Publishes this container as a new image to the specified address. + + Publish returns a fully qualified ref. + + It can also publish platform variants. + """ + @spec publish(t(), String.t(), [ + {:platform_variants, [Dagger.ContainerID.t()]}, + {:forced_compression, Dagger.ImageLayerCompression.t() | nil}, + {:media_types, Dagger.ImageMediaTypes.t() | nil} + ]) :: {:ok, String.t()} | {:error, term()} + def publish(%__MODULE__{} = container, address, optional_args \\ []) do + selection = + container.selection + |> select("publish") + |> put_arg("address", address) + |> maybe_put_arg( + "platformVariants", + if(optional_args[:platform_variants], + do: Enum.map(optional_args[:platform_variants], &Dagger.ID.id!/1), + else: nil + ) ) - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Establish a runtime dependency on a service.\n\nThe service will be started automatically when needed and detached when it is no longer needed, executing the default command if none is set.\n\nThe service will be reachable from the container via the provided hostname alias.\n\nThe service dependency will also convey to any files or directories produced by the container.\n\n## Required Arguments\n\n* `alias` - A name that can be used to reach the service from the container\n* `service` - Identifier of the service container" - @spec with_service_binding(t(), Dagger.String.t(), Dagger.Service.t()) :: Dagger.Container.t() - def with_service_binding(%__MODULE__{} = container, alias, service) do - selection = select(container.selection, "withServiceBinding") - selection = arg(selection, "alias", alias) - - ( - {:ok, id} = Dagger.Service.id(service) - selection = arg(selection, "service", id) + |> maybe_put_arg("forcedCompression", optional_args[:forced_compression]) + |> maybe_put_arg("mediaTypes", optional_args[:media_types]) + + execute(selection, container.client) + end + + @doc "Retrieves this container's root filesystem. Mounts are not included." + @spec rootfs(t()) :: Dagger.Directory.t() + def rootfs(%__MODULE__{} = container) do + selection = + container.selection |> select("rootfs") + + %Dagger.Directory{ + selection: selection, + client: container.client + } + end + + @doc """ + The error stream of the last executed command. + + Will execute default command if none is set, or error if there's no default. + """ + @spec stderr(t()) :: {:ok, String.t()} | {:error, term()} + def stderr(%__MODULE__{} = container) do + selection = + container.selection |> select("stderr") + + execute(selection, container.client) + end + + @doc """ + The output stream of the last executed command. + + Will execute default command if none is set, or error if there's no default. + """ + @spec stdout(t()) :: {:ok, String.t()} | {:error, term()} + def stdout(%__MODULE__{} = container) do + selection = + container.selection |> select("stdout") + + execute(selection, container.client) + end + + @doc """ + Forces evaluation of the pipeline in the engine. + + It doesn't run the default command if no exec has been set. + """ + @spec sync(t()) :: {:ok, Dagger.ContainerID.t()} | {:error, term()} + def sync(%__MODULE__{} = container) do + selection = + container.selection |> select("sync") + + execute(selection, container.client) + end + + @doc "Return an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default)." + @spec terminal(t(), [{:cmd, [String.t()]}]) :: Dagger.Terminal.t() + def terminal(%__MODULE__{} = container, optional_args \\ []) do + selection = + container.selection |> select("terminal") |> maybe_put_arg("cmd", optional_args[:cmd]) + + %Dagger.Terminal{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves the user to be set for all commands." + @spec user(t()) :: {:ok, String.t()} | {:error, term()} + def user(%__MODULE__{} = container) do + selection = + container.selection |> select("user") + + execute(selection, container.client) + end + + @doc "Configures default arguments for future commands." + @spec with_default_args(t(), [String.t()]) :: Dagger.Container.t() + def with_default_args(%__MODULE__{} = container, args) do + selection = + container.selection |> select("withDefaultArgs") |> put_arg("args", args) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Set the default command to invoke for the container's terminal API." + @spec with_default_terminal_cmd(t(), [String.t()]) :: Dagger.Container.t() + def with_default_terminal_cmd(%__MODULE__{} = container, args) do + selection = + container.selection |> select("withDefaultTerminalCmd") |> put_arg("args", args) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a directory written at the given path." + @spec with_directory(t(), String.t(), Dagger.Directory.t(), [ + {:exclude, [String.t()]}, + {:include, [String.t()]}, + {:owner, String.t() | nil} + ]) :: Dagger.Container.t() + def with_directory(%__MODULE__{} = container, path, directory, optional_args \\ []) do + selection = + container.selection + |> select("withDirectory") + |> put_arg("path", path) + |> put_arg("directory", Dagger.ID.id!(directory)) + |> maybe_put_arg("exclude", optional_args[:exclude]) + |> maybe_put_arg("include", optional_args[:include]) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container but with a different command entrypoint." + @spec with_entrypoint(t(), [String.t()], [{:keep_default_args, boolean() | nil}]) :: + Dagger.Container.t() + def with_entrypoint(%__MODULE__{} = container, args, optional_args \\ []) do + selection = + container.selection + |> select("withEntrypoint") + |> put_arg("args", args) + |> maybe_put_arg("keepDefaultArgs", optional_args[:keep_default_args]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus the given environment variable." + @spec with_env_variable(t(), String.t(), String.t(), [{:expand, boolean() | nil}]) :: + Dagger.Container.t() + def with_env_variable(%__MODULE__{} = container, name, value, optional_args \\ []) do + selection = + container.selection + |> select("withEnvVariable") + |> put_arg("name", name) + |> put_arg("value", value) + |> maybe_put_arg("expand", optional_args[:expand]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container after executing the specified command inside it." + @spec with_exec(t(), [String.t()], [ + {:skip_entrypoint, boolean() | nil}, + {:stdin, String.t() | nil}, + {:redirect_stdout, String.t() | nil}, + {:redirect_stderr, String.t() | nil}, + {:experimental_privileged_nesting, boolean() | nil}, + {:insecure_root_capabilities, boolean() | nil} + ]) :: Dagger.Container.t() + def with_exec(%__MODULE__{} = container, args, optional_args \\ []) do + selection = + container.selection + |> select("withExec") + |> put_arg("args", args) + |> maybe_put_arg("skipEntrypoint", optional_args[:skip_entrypoint]) + |> maybe_put_arg("stdin", optional_args[:stdin]) + |> maybe_put_arg("redirectStdout", optional_args[:redirect_stdout]) + |> maybe_put_arg("redirectStderr", optional_args[:redirect_stderr]) + |> maybe_put_arg( + "experimentalPrivilegedNesting", + optional_args[:experimental_privileged_nesting] ) - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container plus a socket forwarded to the given Unix socket path.\n\n## Required Arguments\n\n* `path` - Location of the forwarded Unix socket (e.g., \"/tmp/socket\").\n* `source` - Identifier of the socket to forward.\n\n## Optional Arguments\n\n* `owner` - A user:group to set for the mounted socket.\n\nThe user and group can either be an ID (1000:1000) or a name (foo:bar).\n\nIf the group is omitted, it defaults to the same as the user." - @spec with_unix_socket(t(), Dagger.String.t(), Dagger.Socket.t(), keyword()) :: - Dagger.Container.t() - def with_unix_socket(%__MODULE__{} = container, path, source, optional_args \\ []) do - selection = select(container.selection, "withUnixSocket") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.Socket.id(source) - selection = arg(selection, "source", id) + |> maybe_put_arg("insecureRootCapabilities", optional_args[:insecure_root_capabilities]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Expose a network port. + + Exposed ports serve two purposes: + + - For health checks and introspection, when running services + + - For setting the EXPOSE OCI field when publishing the container + """ + @spec with_exposed_port(t(), integer(), [ + {:protocol, Dagger.NetworkProtocol.t() | nil}, + {:description, String.t() | nil}, + {:experimental_skip_healthcheck, boolean() | nil} + ]) :: Dagger.Container.t() + def with_exposed_port(%__MODULE__{} = container, port, optional_args \\ []) do + selection = + container.selection + |> select("withExposedPort") + |> put_arg("port", port) + |> maybe_put_arg("protocol", optional_args[:protocol]) + |> maybe_put_arg("description", optional_args[:description]) + |> maybe_put_arg( + "experimentalSkipHealthcheck", + optional_args[:experimental_skip_healthcheck] ) - selection = - if is_nil(optional_args[:owner]) do - selection - else - arg(selection, "owner", optional_args[:owner]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with a different command user.\n\n## Required Arguments\n\n* `name` - The user to set (e.g., \"root\")." - @spec with_user(t(), Dagger.String.t()) :: Dagger.Container.t() - def with_user(%__MODULE__{} = container, name) do - selection = select(container.selection, "withUser") - selection = arg(selection, "name", name) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with a different working directory.\n\n## Required Arguments\n\n* `path` - The path to set as the working directory (e.g., \"/app\")." - @spec with_workdir(t(), Dagger.String.t()) :: Dagger.Container.t() - def with_workdir(%__MODULE__{} = container, path) do - selection = select(container.selection, "withWorkdir") - selection = arg(selection, "path", path) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with unset default arguments for future commands." - @spec without_default_args(t()) :: Dagger.Container.t() - def without_default_args(%__MODULE__{} = container) do - selection = select(container.selection, "withoutDefaultArgs") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with an unset command entrypoint.\n\n\n\n## Optional Arguments\n\n* `keep_default_args` - Don't remove the default arguments when unsetting the entrypoint." - @spec without_entrypoint(t(), keyword()) :: Dagger.Container.t() - def without_entrypoint(%__MODULE__{} = container, optional_args \\ []) do - selection = select(container.selection, "withoutEntrypoint") - - selection = - if is_nil(optional_args[:keep_default_args]) do - selection - else - arg(selection, "keepDefaultArgs", optional_args[:keep_default_args]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container minus the given environment variable.\n\n## Required Arguments\n\n* `name` - The name of the environment variable (e.g., \"HOST\")." - @spec without_env_variable(t(), Dagger.String.t()) :: Dagger.Container.t() - def without_env_variable(%__MODULE__{} = container, name) do - selection = select(container.selection, "withoutEnvVariable") - selection = arg(selection, "name", name) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Unexpose a previously exposed port.\n\n## Required Arguments\n\n* `port` - Port number to unexpose\n\n## Optional Arguments\n\n* `protocol` - Port protocol to unexpose" - @spec without_exposed_port(t(), Dagger.Int.t(), keyword()) :: Dagger.Container.t() - def without_exposed_port(%__MODULE__{} = container, port, optional_args \\ []) do - selection = select(container.selection, "withoutExposedPort") - selection = arg(selection, "port", port) - - selection = - if is_nil(optional_args[:protocol]) do - selection - else - arg(selection, "protocol", optional_args[:protocol]) - end - - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Indicate that subsequent operations should not be featured more prominently in the UI.\n\nThis is the initial state of all containers." - @spec without_focus(t()) :: Dagger.Container.t() - def without_focus(%__MODULE__{} = container) do - selection = select(container.selection, "withoutFocus") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container minus the given environment label.\n\n## Required Arguments\n\n* `name` - The name of the label to remove (e.g., \"org.opencontainers.artifact.created\")." - @spec without_label(t(), Dagger.String.t()) :: Dagger.Container.t() - def without_label(%__MODULE__{} = container, name) do - selection = select(container.selection, "withoutLabel") - selection = arg(selection, "name", name) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container after unmounting everything at the given path.\n\n## Required Arguments\n\n* `path` - Location of the cache directory (e.g., \"/cache/node_modules\")." - @spec without_mount(t(), Dagger.String.t()) :: Dagger.Container.t() - def without_mount(%__MODULE__{} = container, path) do - selection = select(container.selection, "withoutMount") - selection = arg(selection, "path", path) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container without the registry authentication of a given address.\n\n## Required Arguments\n\n* `address` - Registry's address to remove the authentication from.\n\nFormatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main)." - @spec without_registry_auth(t(), Dagger.String.t()) :: Dagger.Container.t() - def without_registry_auth(%__MODULE__{} = container, address) do - selection = select(container.selection, "withoutRegistryAuth") - selection = arg(selection, "address", address) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with a previously added Unix socket removed.\n\n## Required Arguments\n\n* `path` - Location of the socket to remove (e.g., \"/tmp/socket\")." - @spec without_unix_socket(t(), Dagger.String.t()) :: Dagger.Container.t() - def without_unix_socket(%__MODULE__{} = container, path) do - selection = select(container.selection, "withoutUnixSocket") - selection = arg(selection, "path", path) - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with an unset command user.\n\nShould default to root." - @spec without_user(t()) :: Dagger.Container.t() - def without_user(%__MODULE__{} = container) do - selection = select(container.selection, "withoutUser") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves this container with an unset working directory.\n\nShould default to \"/\"." - @spec without_workdir(t()) :: Dagger.Container.t() - def without_workdir(%__MODULE__{} = container) do - selection = select(container.selection, "withoutWorkdir") - %Dagger.Container{selection: selection, client: container.client} - end - ) - - ( - @doc "Retrieves the working directory for all commands." - @spec workdir(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def workdir(%__MODULE__{} = container) do - selection = select(container.selection, "workdir") - execute(selection, container.client) - end - ) + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus the contents of the given file copied to the given path." + @spec with_file(t(), String.t(), Dagger.File.t(), [ + {:permissions, integer() | nil}, + {:owner, String.t() | nil} + ]) :: Dagger.Container.t() + def with_file(%__MODULE__{} = container, path, source, optional_args \\ []) do + selection = + container.selection + |> select("withFile") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("permissions", optional_args[:permissions]) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus the contents of the given files copied to the given path." + @spec with_files(t(), String.t(), [Dagger.FileID.t()], [ + {:permissions, integer() | nil}, + {:owner, String.t() | nil} + ]) :: Dagger.Container.t() + def with_files(%__MODULE__{} = container, path, sources, optional_args \\ []) do + selection = + container.selection + |> select("withFiles") + |> put_arg("path", path) + |> put_arg("sources", sources) + |> maybe_put_arg("permissions", optional_args[:permissions]) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Indicate that subsequent operations should be featured more prominently in the UI." + @spec with_focus(t()) :: Dagger.Container.t() + def with_focus(%__MODULE__{} = container) do + selection = + container.selection |> select("withFocus") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus the given label." + @spec with_label(t(), String.t(), String.t()) :: Dagger.Container.t() + def with_label(%__MODULE__{} = container, name, value) do + selection = + container.selection + |> select("withLabel") + |> put_arg("name", name) + |> put_arg("value", value) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a cache volume mounted at the given path." + @spec with_mounted_cache(t(), String.t(), Dagger.CacheVolume.t(), [ + {:source, Dagger.DirectoryID.t() | nil}, + {:sharing, Dagger.CacheSharingMode.t() | nil}, + {:owner, String.t() | nil} + ]) :: Dagger.Container.t() + def with_mounted_cache(%__MODULE__{} = container, path, cache, optional_args \\ []) do + selection = + container.selection + |> select("withMountedCache") + |> put_arg("path", path) + |> put_arg("cache", Dagger.ID.id!(cache)) + |> maybe_put_arg("source", optional_args[:source]) + |> maybe_put_arg("sharing", optional_args[:sharing]) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a directory mounted at the given path." + @spec with_mounted_directory(t(), String.t(), Dagger.Directory.t(), [{:owner, String.t() | nil}]) :: + Dagger.Container.t() + def with_mounted_directory(%__MODULE__{} = container, path, source, optional_args \\ []) do + selection = + container.selection + |> select("withMountedDirectory") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a file mounted at the given path." + @spec with_mounted_file(t(), String.t(), Dagger.File.t(), [{:owner, String.t() | nil}]) :: + Dagger.Container.t() + def with_mounted_file(%__MODULE__{} = container, path, source, optional_args \\ []) do + selection = + container.selection + |> select("withMountedFile") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a secret mounted into a file at the given path." + @spec with_mounted_secret(t(), String.t(), Dagger.Secret.t(), [ + {:owner, String.t() | nil}, + {:mode, integer() | nil} + ]) :: Dagger.Container.t() + def with_mounted_secret(%__MODULE__{} = container, path, source, optional_args \\ []) do + selection = + container.selection + |> select("withMountedSecret") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("owner", optional_args[:owner]) + |> maybe_put_arg("mode", optional_args[:mode]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a temporary directory mounted at the given path." + @spec with_mounted_temp(t(), String.t()) :: Dagger.Container.t() + def with_mounted_temp(%__MODULE__{} = container, path) do + selection = + container.selection |> select("withMountedTemp") |> put_arg("path", path) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a new file written at the given path." + @spec with_new_file(t(), String.t(), [ + {:contents, String.t() | nil}, + {:permissions, integer() | nil}, + {:owner, String.t() | nil} + ]) :: Dagger.Container.t() + def with_new_file(%__MODULE__{} = container, path, optional_args \\ []) do + selection = + container.selection + |> select("withNewFile") + |> put_arg("path", path) + |> maybe_put_arg("contents", optional_args[:contents]) + |> maybe_put_arg("permissions", optional_args[:permissions]) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with a registry authentication for a given address." + @spec with_registry_auth(t(), String.t(), String.t(), Dagger.Secret.t()) :: Dagger.Container.t() + def with_registry_auth(%__MODULE__{} = container, address, username, secret) do + selection = + container.selection + |> select("withRegistryAuth") + |> put_arg("address", address) + |> put_arg("username", username) + |> put_arg("secret", Dagger.ID.id!(secret)) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves the container with the given directory mounted to /." + @spec with_rootfs(t(), Dagger.Directory.t()) :: Dagger.Container.t() + def with_rootfs(%__MODULE__{} = container, directory) do + selection = + container.selection + |> select("withRootfs") + |> put_arg("directory", Dagger.ID.id!(directory)) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus an env variable containing the given secret." + @spec with_secret_variable(t(), String.t(), Dagger.Secret.t()) :: Dagger.Container.t() + def with_secret_variable(%__MODULE__{} = container, name, secret) do + selection = + container.selection + |> select("withSecretVariable") + |> put_arg("name", name) + |> put_arg("secret", Dagger.ID.id!(secret)) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Establish a runtime dependency on a service. + + The service will be started automatically when needed and detached when it is no longer needed, executing the default command if none is set. + + The service will be reachable from the container via the provided hostname alias. + + The service dependency will also convey to any files or directories produced by the container. + """ + @spec with_service_binding(t(), String.t(), Dagger.Service.t()) :: Dagger.Container.t() + def with_service_binding(%__MODULE__{} = container, alias, service) do + selection = + container.selection + |> select("withServiceBinding") + |> put_arg("alias", alias) + |> put_arg("service", Dagger.ID.id!(service)) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container plus a socket forwarded to the given Unix socket path." + @spec with_unix_socket(t(), String.t(), Dagger.Socket.t(), [{:owner, String.t() | nil}]) :: + Dagger.Container.t() + def with_unix_socket(%__MODULE__{} = container, path, source, optional_args \\ []) do + selection = + container.selection + |> select("withUnixSocket") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("owner", optional_args[:owner]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with a different command user." + @spec with_user(t(), String.t()) :: Dagger.Container.t() + def with_user(%__MODULE__{} = container, name) do + selection = + container.selection |> select("withUser") |> put_arg("name", name) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with a different working directory." + @spec with_workdir(t(), String.t()) :: Dagger.Container.t() + def with_workdir(%__MODULE__{} = container, path) do + selection = + container.selection |> select("withWorkdir") |> put_arg("path", path) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with unset default arguments for future commands." + @spec without_default_args(t()) :: Dagger.Container.t() + def without_default_args(%__MODULE__{} = container) do + selection = + container.selection |> select("withoutDefaultArgs") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with an unset command entrypoint." + @spec without_entrypoint(t(), [{:keep_default_args, boolean() | nil}]) :: Dagger.Container.t() + def without_entrypoint(%__MODULE__{} = container, optional_args \\ []) do + selection = + container.selection + |> select("withoutEntrypoint") + |> maybe_put_arg("keepDefaultArgs", optional_args[:keep_default_args]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container minus the given environment variable." + @spec without_env_variable(t(), String.t()) :: Dagger.Container.t() + def without_env_variable(%__MODULE__{} = container, name) do + selection = + container.selection |> select("withoutEnvVariable") |> put_arg("name", name) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Unexpose a previously exposed port." + @spec without_exposed_port(t(), integer(), [{:protocol, Dagger.NetworkProtocol.t() | nil}]) :: + Dagger.Container.t() + def without_exposed_port(%__MODULE__{} = container, port, optional_args \\ []) do + selection = + container.selection + |> select("withoutExposedPort") + |> put_arg("port", port) + |> maybe_put_arg("protocol", optional_args[:protocol]) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Indicate that subsequent operations should not be featured more prominently in the UI. + + This is the initial state of all containers. + """ + @spec without_focus(t()) :: Dagger.Container.t() + def without_focus(%__MODULE__{} = container) do + selection = + container.selection |> select("withoutFocus") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container minus the given environment label." + @spec without_label(t(), String.t()) :: Dagger.Container.t() + def without_label(%__MODULE__{} = container, name) do + selection = + container.selection |> select("withoutLabel") |> put_arg("name", name) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container after unmounting everything at the given path." + @spec without_mount(t(), String.t()) :: Dagger.Container.t() + def without_mount(%__MODULE__{} = container, path) do + selection = + container.selection |> select("withoutMount") |> put_arg("path", path) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container without the registry authentication of a given address." + @spec without_registry_auth(t(), String.t()) :: Dagger.Container.t() + def without_registry_auth(%__MODULE__{} = container, address) do + selection = + container.selection |> select("withoutRegistryAuth") |> put_arg("address", address) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves this container with a previously added Unix socket removed." + @spec without_unix_socket(t(), String.t()) :: Dagger.Container.t() + def without_unix_socket(%__MODULE__{} = container, path) do + selection = + container.selection |> select("withoutUnixSocket") |> put_arg("path", path) + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Retrieves this container with an unset command user. + + Should default to root. + """ + @spec without_user(t()) :: Dagger.Container.t() + def without_user(%__MODULE__{} = container) do + selection = + container.selection |> select("withoutUser") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc """ + Retrieves this container with an unset working directory. + + Should default to \"/\". + """ + @spec without_workdir(t()) :: Dagger.Container.t() + def without_workdir(%__MODULE__{} = container) do + selection = + container.selection |> select("withoutWorkdir") + + %Dagger.Container{ + selection: selection, + client: container.client + } + end + + @doc "Retrieves the working directory for all commands." + @spec workdir(t()) :: {:ok, String.t()} | {:error, term()} + def workdir(%__MODULE__{} = container) do + selection = + container.selection |> select("workdir") + + execute(selection, container.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/container_id.ex b/sdk/elixir/lib/dagger/gen/container_id.ex index 40a4d52f7be..6081f056612 100644 --- a/sdk/elixir/lib/dagger/gen/container_id.ex +++ b/sdk/elixir/lib/dagger/gen/container_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ContainerID do @moduledoc "The `ContainerID` scalar type represents an identifier for an object of type Container." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/current_module.ex b/sdk/elixir/lib/dagger/gen/current_module.ex index 0d1b86b199e..f0d1929decf 100644 --- a/sdk/elixir/lib/dagger/gen/current_module.ex +++ b/sdk/elixir/lib/dagger/gen/current_module.ex @@ -1,69 +1,71 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.CurrentModule do @moduledoc "Reflective module API provided to functions at runtime." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this CurrentModule." - @spec id(t()) :: {:ok, Dagger.CurrentModuleID.t()} | {:error, term()} - def id(%__MODULE__{} = current_module) do - selection = select(current_module.selection, "id") - execute(selection, current_module.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this CurrentModule." + @spec id(t()) :: {:ok, Dagger.CurrentModuleID.t()} | {:error, term()} + def id(%__MODULE__{} = current_module) do + selection = + current_module.selection |> select("id") + + execute(selection, current_module.client) + end + + @doc "The name of the module being executed in" + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = current_module) do + selection = + current_module.selection |> select("name") - ( - @doc "The name of the module being executed in" - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = current_module) do - selection = select(current_module.selection, "name") - execute(selection, current_module.client) - end - ) + execute(selection, current_module.client) + end - ( - @doc "The directory containing the module's source code loaded into the engine (plus any generated code that may have been created)." - @spec source(t()) :: Dagger.Directory.t() - def source(%__MODULE__{} = current_module) do - selection = select(current_module.selection, "source") - %Dagger.Directory{selection: selection, client: current_module.client} - end - ) + @doc "The directory containing the module's source code loaded into the engine (plus any generated code that may have been created)." + @spec source(t()) :: Dagger.Directory.t() + def source(%__MODULE__{} = current_module) do + selection = + current_module.selection |> select("source") - ( - @doc "Load a directory from the module's scratch working directory, including any changes that may have been made to it during module function execution.\n\n## Required Arguments\n\n* `path` - Location of the directory to access (e.g., \".\").\n\n## Optional Arguments\n\n* `exclude` - Exclude artifacts that match the given pattern (e.g., [\"node_modules/\", \".git*\"]).\n* `include` - Include only artifacts that match the given pattern (e.g., [\"app/\", \"package.*\"])." - @spec workdir(t(), Dagger.String.t(), keyword()) :: Dagger.Directory.t() - def workdir(%__MODULE__{} = current_module, path, optional_args \\ []) do - selection = select(current_module.selection, "workdir") - selection = arg(selection, "path", path) + %Dagger.Directory{ + selection: selection, + client: current_module.client + } + end - selection = - if is_nil(optional_args[:exclude]) do - selection - else - arg(selection, "exclude", optional_args[:exclude]) - end + @doc "Load a directory from the module's scratch working directory, including any changes that may have been made to it during module function execution." + @spec workdir(t(), String.t(), [{:exclude, [String.t()]}, {:include, [String.t()]}]) :: + Dagger.Directory.t() + def workdir(%__MODULE__{} = current_module, path, optional_args \\ []) do + selection = + current_module.selection + |> select("workdir") + |> put_arg("path", path) + |> maybe_put_arg("exclude", optional_args[:exclude]) + |> maybe_put_arg("include", optional_args[:include]) - selection = - if is_nil(optional_args[:include]) do - selection - else - arg(selection, "include", optional_args[:include]) - end + %Dagger.Directory{ + selection: selection, + client: current_module.client + } + end - %Dagger.Directory{selection: selection, client: current_module.client} - end - ) + @doc "Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution." + @spec workdir_file(t(), String.t()) :: Dagger.File.t() + def workdir_file(%__MODULE__{} = current_module, path) do + selection = + current_module.selection |> select("workdirFile") |> put_arg("path", path) - ( - @doc "Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.\n\n## Required Arguments\n\n* `path` - Location of the file to retrieve (e.g., \"README.md\")." - @spec workdir_file(t(), Dagger.String.t()) :: Dagger.File.t() - def workdir_file(%__MODULE__{} = current_module, path) do - selection = select(current_module.selection, "workdirFile") - selection = arg(selection, "path", path) - %Dagger.File{selection: selection, client: current_module.client} - end - ) + %Dagger.File{ + selection: selection, + client: current_module.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/current_module_id.ex b/sdk/elixir/lib/dagger/gen/current_module_id.ex index 7832e85d58b..22def3d4ba7 100644 --- a/sdk/elixir/lib/dagger/gen/current_module_id.ex +++ b/sdk/elixir/lib/dagger/gen/current_module_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.CurrentModuleID do @moduledoc "The `CurrentModuleID` scalar type represents an identifier for an object of type CurrentModule." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/date_time.ex b/sdk/elixir/lib/dagger/gen/date_time.ex deleted file mode 100644 index a20caccd1c0..00000000000 --- a/sdk/elixir/lib/dagger/gen/date_time.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.DateTime do - @moduledoc "The `DateTime` scalar type represents a DateTime. The DateTime is serialized as an RFC 3339 quoted string" - @type t() :: DateTime.t() -end diff --git a/sdk/elixir/lib/dagger/gen/directory.ex b/sdk/elixir/lib/dagger/gen/directory.ex index f66ca95dce1..2e75fd3b4a8 100644 --- a/sdk/elixir/lib/dagger/gen/directory.ex +++ b/sdk/elixir/lib/dagger/gen/directory.ex @@ -1,334 +1,279 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Directory do @moduledoc "A directory." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID @derive Dagger.Sync defstruct [:selection, :client] - ( - @doc "Load the directory as a Dagger module\n\n\n\n## Optional Arguments\n\n* `source_root_path` - An optional subpath of the directory which contains the module's configuration file.\n\nThis is needed when the module code is in a subdirectory but requires parent directories to be loaded in order to execute. For example, the module source code may need a go.mod, project.toml, package.json, etc. file from a parent directory.\n\nIf not set, the module source code is loaded from the root of the directory." - @spec as_module(t(), keyword()) :: Dagger.Module.t() - def as_module(%__MODULE__{} = directory, optional_args \\ []) do - selection = select(directory.selection, "asModule") - - selection = - if is_nil(optional_args[:source_root_path]) do - selection - else - arg(selection, "sourceRootPath", optional_args[:source_root_path]) - end - - %Dagger.Module{selection: selection, client: directory.client} - end - ) - - ( - @doc "Gets the difference between this directory and an another directory.\n\n## Required Arguments\n\n* `other` - Identifier of the directory to compare." - @spec diff(t(), Dagger.Directory.t()) :: Dagger.Directory.t() - def diff(%__MODULE__{} = directory, other) do - selection = select(directory.selection, "diff") - - ( - {:ok, id} = Dagger.Directory.id(other) - selection = arg(selection, "other", id) - ) - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves a directory at the given path.\n\n## Required Arguments\n\n* `path` - Location of the directory to retrieve (e.g., \"/src\")." - @spec directory(t(), Dagger.String.t()) :: Dagger.Directory.t() - def directory(%__MODULE__{} = directory, path) do - selection = select(directory.selection, "directory") - selection = arg(selection, "path", path) - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Builds a new Docker container from this directory.\n\n\n\n## Optional Arguments\n\n* `platform` - The platform to build.\n* `dockerfile` - Path to the Dockerfile to use (e.g., \"frontend.Dockerfile\").\n* `target` - Target build stage to build.\n* `build_args` - Build arguments to use in the build.\n* `secrets` - Secrets to pass to the build.\n\nThey will be mounted at /run/secrets/[secret-name]." - @spec docker_build(t(), keyword()) :: Dagger.Container.t() - def docker_build(%__MODULE__{} = directory, optional_args \\ []) do - selection = select(directory.selection, "dockerBuild") - - selection = - if is_nil(optional_args[:platform]) do - selection - else - arg(selection, "platform", optional_args[:platform]) - end - - selection = - if is_nil(optional_args[:dockerfile]) do - selection - else - arg(selection, "dockerfile", optional_args[:dockerfile]) - end - - selection = - if is_nil(optional_args[:target]) do - selection - else - arg(selection, "target", optional_args[:target]) - end - - selection = - if is_nil(optional_args[:build_args]) do - selection - else - arg(selection, "buildArgs", optional_args[:build_args]) - end - - selection = - if is_nil(optional_args[:secrets]) do - selection - else - ids = - optional_args[:secrets] - |> Enum.map(fn value -> - {:ok, id} = Dagger.Secret.id(value) - id - end) - - arg(selection, "secrets", ids) - end - - %Dagger.Container{selection: selection, client: directory.client} - end - ) - - ( - @doc "Returns a list of files and directories at the given path.\n\n\n\n## Optional Arguments\n\n* `path` - Location of the directory to look at (e.g., \"/src\")." - @spec entries(t(), keyword()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def entries(%__MODULE__{} = directory, optional_args \\ []) do - selection = select(directory.selection, "entries") - - selection = - if is_nil(optional_args[:path]) do - selection - else - arg(selection, "path", optional_args[:path]) - end - - execute(selection, directory.client) - end - ) - - ( - @doc "Writes the contents of the directory to a path on the host.\n\n## Required Arguments\n\n* `path` - Location of the copied directory (e.g., \"logs/\")." - @spec export(t(), Dagger.String.t()) :: {:ok, Dagger.Boolean.t()} | {:error, term()} - def export(%__MODULE__{} = directory, path) do - selection = select(directory.selection, "export") - selection = arg(selection, "path", path) - execute(selection, directory.client) - end - ) - - ( - @doc "Retrieves a file at the given path.\n\n## Required Arguments\n\n* `path` - Location of the file to retrieve (e.g., \"README.md\")." - @spec file(t(), Dagger.String.t()) :: Dagger.File.t() - def file(%__MODULE__{} = directory, path) do - selection = select(directory.selection, "file") - selection = arg(selection, "path", path) - %Dagger.File{selection: selection, client: directory.client} - end - ) - - ( - @doc "Returns a list of files and directories that matche the given pattern.\n\n## Required Arguments\n\n* `pattern` - Pattern to match (e.g., \"*.md\")." - @spec glob(t(), Dagger.String.t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def glob(%__MODULE__{} = directory, pattern) do - selection = select(directory.selection, "glob") - selection = arg(selection, "pattern", pattern) - execute(selection, directory.client) - end - ) - - ( - @doc "A unique identifier for this Directory." - @spec id(t()) :: {:ok, Dagger.DirectoryID.t()} | {:error, term()} - def id(%__MODULE__{} = directory) do - selection = select(directory.selection, "id") - execute(selection, directory.client) - end - ) - - ( - @doc "Creates a named sub-pipeline.\n\n## Required Arguments\n\n* `name` - Name of the sub-pipeline.\n\n## Optional Arguments\n\n* `description` - Description of the sub-pipeline.\n* `labels` - Labels to apply to the sub-pipeline." - @spec pipeline(t(), Dagger.String.t(), keyword()) :: Dagger.Directory.t() - def pipeline(%__MODULE__{} = directory, name, optional_args \\ []) do - selection = select(directory.selection, "pipeline") - selection = arg(selection, "name", name) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - selection = - if is_nil(optional_args[:labels]) do - selection - else - arg(selection, "labels", optional_args[:labels]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Force evaluation in the engine." - @spec sync(t()) :: {:ok, Dagger.DirectoryID.t()} | {:error, term()} - def sync(%__MODULE__{} = directory) do - selection = select(directory.selection, "sync") - execute(selection, directory.client) - end - ) - - ( - @doc "Retrieves this directory plus a directory written at the given path.\n\n## Required Arguments\n\n* `path` - Location of the written directory (e.g., \"/src/\").\n* `directory` - Identifier of the directory to copy.\n\n## Optional Arguments\n\n* `exclude` - Exclude artifacts that match the given pattern (e.g., [\"node_modules/\", \".git*\"]).\n* `include` - Include only artifacts that match the given pattern (e.g., [\"app/\", \"package.*\"])." - @spec with_directory(t(), Dagger.String.t(), Dagger.Directory.t(), keyword()) :: - Dagger.Directory.t() - def with_directory(%__MODULE__{} = directory, path, directory, optional_args \\ []) do - selection = select(directory.selection, "withDirectory") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.Directory.id(directory) - selection = arg(selection, "directory", id) - ) + @type t() :: %__MODULE__{} - selection = - if is_nil(optional_args[:exclude]) do - selection - else - arg(selection, "exclude", optional_args[:exclude]) - end - - selection = - if is_nil(optional_args[:include]) do - selection - else - arg(selection, "include", optional_args[:include]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory plus the contents of the given file copied to the given path.\n\n## Required Arguments\n\n* `path` - Location of the copied file (e.g., \"/file.txt\").\n* `source` - Identifier of the file to copy.\n\n## Optional Arguments\n\n* `permissions` - Permission given to the copied file (e.g., 0600)." - @spec with_file(t(), Dagger.String.t(), Dagger.File.t(), keyword()) :: Dagger.Directory.t() - def with_file(%__MODULE__{} = directory, path, source, optional_args \\ []) do - selection = select(directory.selection, "withFile") - selection = arg(selection, "path", path) - - ( - {:ok, id} = Dagger.File.id(source) - selection = arg(selection, "source", id) + @doc "Load the directory as a Dagger module" + @spec as_module(t(), [{:source_root_path, String.t() | nil}]) :: Dagger.Module.t() + def as_module(%__MODULE__{} = directory, optional_args \\ []) do + selection = + directory.selection + |> select("asModule") + |> maybe_put_arg("sourceRootPath", optional_args[:source_root_path]) + + %Dagger.Module{ + selection: selection, + client: directory.client + } + end + + @doc "Gets the difference between this directory and an another directory." + @spec diff(t(), Dagger.Directory.t()) :: Dagger.Directory.t() + def diff(%__MODULE__{} = directory, other) do + selection = + directory.selection |> select("diff") |> put_arg("other", Dagger.ID.id!(other)) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves a directory at the given path." + @spec directory(t(), String.t()) :: Dagger.Directory.t() + def directory(%__MODULE__{} = directory, path) do + selection = + directory.selection |> select("directory") |> put_arg("path", path) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Builds a new Docker container from this directory." + @spec docker_build(t(), [ + {:platform, Dagger.Platform.t() | nil}, + {:dockerfile, String.t() | nil}, + {:target, String.t() | nil}, + {:build_args, [Dagger.BuildArg.t()]}, + {:secrets, [Dagger.SecretID.t()]} + ]) :: Dagger.Container.t() + def docker_build(%__MODULE__{} = directory, optional_args \\ []) do + selection = + directory.selection + |> select("dockerBuild") + |> maybe_put_arg("platform", optional_args[:platform]) + |> maybe_put_arg("dockerfile", optional_args[:dockerfile]) + |> maybe_put_arg("target", optional_args[:target]) + |> maybe_put_arg("buildArgs", optional_args[:build_args]) + |> maybe_put_arg( + "secrets", + if(optional_args[:secrets], + do: Enum.map(optional_args[:secrets], &Dagger.ID.id!/1), + else: nil + ) ) - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory plus the contents of the given files copied to the given path.\n\n## Required Arguments\n\n* `path` - Location where copied files should be placed (e.g., \"/src\").\n* `sources` - Identifiers of the files to copy.\n\n## Optional Arguments\n\n* `permissions` - Permission given to the copied files (e.g., 0600)." - @spec with_files(t(), Dagger.String.t(), [Dagger.FileID.t()], keyword()) :: - Dagger.Directory.t() - def with_files(%__MODULE__{} = directory, path, sources, optional_args \\ []) do - selection = select(directory.selection, "withFiles") - selection = arg(selection, "path", path) - selection = arg(selection, "sources", sources) - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory plus a new directory created at the given path.\n\n## Required Arguments\n\n* `path` - Location of the directory created (e.g., \"/logs\").\n\n## Optional Arguments\n\n* `permissions` - Permission granted to the created directory (e.g., 0777)." - @spec with_new_directory(t(), Dagger.String.t(), keyword()) :: Dagger.Directory.t() - def with_new_directory(%__MODULE__{} = directory, path, optional_args \\ []) do - selection = select(directory.selection, "withNewDirectory") - selection = arg(selection, "path", path) - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory plus a new file written at the given path.\n\n## Required Arguments\n\n* `path` - Location of the written file (e.g., \"/file.txt\").\n* `contents` - Content of the written file (e.g., \"Hello world!\").\n\n## Optional Arguments\n\n* `permissions` - Permission given to the copied file (e.g., 0600)." - @spec with_new_file(t(), Dagger.String.t(), Dagger.String.t(), keyword()) :: - Dagger.Directory.t() - def with_new_file(%__MODULE__{} = directory, path, contents, optional_args \\ []) do - selection = select(directory.selection, "withNewFile") - selection = arg(selection, "path", path) - selection = arg(selection, "contents", contents) - - selection = - if is_nil(optional_args[:permissions]) do - selection - else - arg(selection, "permissions", optional_args[:permissions]) - end - - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory with all file/dir timestamps set to the given time.\n\n## Required Arguments\n\n* `timestamp` - Timestamp to set dir/files in.\n\nFormatted in seconds following Unix epoch (e.g., 1672531199)." - @spec with_timestamps(t(), Dagger.Int.t()) :: Dagger.Directory.t() - def with_timestamps(%__MODULE__{} = directory, timestamp) do - selection = select(directory.selection, "withTimestamps") - selection = arg(selection, "timestamp", timestamp) - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory with the directory at the given path removed.\n\n## Required Arguments\n\n* `path` - Location of the directory to remove (e.g., \".github/\")." - @spec without_directory(t(), Dagger.String.t()) :: Dagger.Directory.t() - def without_directory(%__MODULE__{} = directory, path) do - selection = select(directory.selection, "withoutDirectory") - selection = arg(selection, "path", path) - %Dagger.Directory{selection: selection, client: directory.client} - end - ) - - ( - @doc "Retrieves this directory with the file at the given path removed.\n\n## Required Arguments\n\n* `path` - Location of the file to remove (e.g., \"/file.txt\")." - @spec without_file(t(), Dagger.String.t()) :: Dagger.Directory.t() - def without_file(%__MODULE__{} = directory, path) do - selection = select(directory.selection, "withoutFile") - selection = arg(selection, "path", path) - %Dagger.Directory{selection: selection, client: directory.client} - end - ) + %Dagger.Container{ + selection: selection, + client: directory.client + } + end + + @doc "Returns a list of files and directories at the given path." + @spec entries(t(), [{:path, String.t() | nil}]) :: {:ok, [String.t()]} | {:error, term()} + def entries(%__MODULE__{} = directory, optional_args \\ []) do + selection = + directory.selection |> select("entries") |> maybe_put_arg("path", optional_args[:path]) + + execute(selection, directory.client) + end + + @doc "Writes the contents of the directory to a path on the host." + @spec export(t(), String.t()) :: {:ok, boolean()} | {:error, term()} + def export(%__MODULE__{} = directory, path) do + selection = + directory.selection |> select("export") |> put_arg("path", path) + + execute(selection, directory.client) + end + + @doc "Retrieves a file at the given path." + @spec file(t(), String.t()) :: Dagger.File.t() + def file(%__MODULE__{} = directory, path) do + selection = + directory.selection |> select("file") |> put_arg("path", path) + + %Dagger.File{ + selection: selection, + client: directory.client + } + end + + @doc "Returns a list of files and directories that matche the given pattern." + @spec glob(t(), String.t()) :: {:ok, [String.t()]} | {:error, term()} + def glob(%__MODULE__{} = directory, pattern) do + selection = + directory.selection |> select("glob") |> put_arg("pattern", pattern) + + execute(selection, directory.client) + end + + @doc "A unique identifier for this Directory." + @spec id(t()) :: {:ok, Dagger.DirectoryID.t()} | {:error, term()} + def id(%__MODULE__{} = directory) do + selection = + directory.selection |> select("id") + + execute(selection, directory.client) + end + + @doc "Creates a named sub-pipeline." + @spec pipeline(t(), String.t(), [ + {:description, String.t() | nil}, + {:labels, [Dagger.PipelineLabel.t()]} + ]) :: Dagger.Directory.t() + def pipeline(%__MODULE__{} = directory, name, optional_args \\ []) do + selection = + directory.selection + |> select("pipeline") + |> put_arg("name", name) + |> maybe_put_arg("description", optional_args[:description]) + |> maybe_put_arg("labels", optional_args[:labels]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Force evaluation in the engine." + @spec sync(t()) :: {:ok, Dagger.DirectoryID.t()} | {:error, term()} + def sync(%__MODULE__{} = directory) do + selection = + directory.selection |> select("sync") + + execute(selection, directory.client) + end + + @doc "Retrieves this directory plus a directory written at the given path." + @spec with_directory(t(), String.t(), Dagger.Directory.t(), [ + {:exclude, [String.t()]}, + {:include, [String.t()]} + ]) :: Dagger.Directory.t() + def with_directory(%__MODULE__{} = directory, path, directory, optional_args \\ []) do + selection = + directory.selection + |> select("withDirectory") + |> put_arg("path", path) + |> put_arg("directory", Dagger.ID.id!(directory)) + |> maybe_put_arg("exclude", optional_args[:exclude]) + |> maybe_put_arg("include", optional_args[:include]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory plus the contents of the given file copied to the given path." + @spec with_file(t(), String.t(), Dagger.File.t(), [{:permissions, integer() | nil}]) :: + Dagger.Directory.t() + def with_file(%__MODULE__{} = directory, path, source, optional_args \\ []) do + selection = + directory.selection + |> select("withFile") + |> put_arg("path", path) + |> put_arg("source", Dagger.ID.id!(source)) + |> maybe_put_arg("permissions", optional_args[:permissions]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory plus the contents of the given files copied to the given path." + @spec with_files(t(), String.t(), [Dagger.FileID.t()], [{:permissions, integer() | nil}]) :: + Dagger.Directory.t() + def with_files(%__MODULE__{} = directory, path, sources, optional_args \\ []) do + selection = + directory.selection + |> select("withFiles") + |> put_arg("path", path) + |> put_arg("sources", sources) + |> maybe_put_arg("permissions", optional_args[:permissions]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory plus a new directory created at the given path." + @spec with_new_directory(t(), String.t(), [{:permissions, integer() | nil}]) :: + Dagger.Directory.t() + def with_new_directory(%__MODULE__{} = directory, path, optional_args \\ []) do + selection = + directory.selection + |> select("withNewDirectory") + |> put_arg("path", path) + |> maybe_put_arg("permissions", optional_args[:permissions]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory plus a new file written at the given path." + @spec with_new_file(t(), String.t(), String.t(), [{:permissions, integer() | nil}]) :: + Dagger.Directory.t() + def with_new_file(%__MODULE__{} = directory, path, contents, optional_args \\ []) do + selection = + directory.selection + |> select("withNewFile") + |> put_arg("path", path) + |> put_arg("contents", contents) + |> maybe_put_arg("permissions", optional_args[:permissions]) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory with all file/dir timestamps set to the given time." + @spec with_timestamps(t(), integer()) :: Dagger.Directory.t() + def with_timestamps(%__MODULE__{} = directory, timestamp) do + selection = + directory.selection |> select("withTimestamps") |> put_arg("timestamp", timestamp) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory with the directory at the given path removed." + @spec without_directory(t(), String.t()) :: Dagger.Directory.t() + def without_directory(%__MODULE__{} = directory, path) do + selection = + directory.selection |> select("withoutDirectory") |> put_arg("path", path) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end + + @doc "Retrieves this directory with the file at the given path removed." + @spec without_file(t(), String.t()) :: Dagger.Directory.t() + def without_file(%__MODULE__{} = directory, path) do + selection = + directory.selection |> select("withoutFile") |> put_arg("path", path) + + %Dagger.Directory{ + selection: selection, + client: directory.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/directory_id.ex b/sdk/elixir/lib/dagger/gen/directory_id.ex index b2a713f9ddd..8feb8e8efe2 100644 --- a/sdk/elixir/lib/dagger/gen/directory_id.ex +++ b/sdk/elixir/lib/dagger/gen/directory_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.DirectoryID do @moduledoc "The `DirectoryID` scalar type represents an identifier for an object of type Directory." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/env_variable.ex b/sdk/elixir/lib/dagger/gen/env_variable.ex index 7bf473bb6b3..0472bfd2064 100644 --- a/sdk/elixir/lib/dagger/gen/env_variable.ex +++ b/sdk/elixir/lib/dagger/gen/env_variable.ex @@ -1,34 +1,39 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.EnvVariable do @moduledoc "An environment variable name and value." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this EnvVariable." - @spec id(t()) :: {:ok, Dagger.EnvVariableID.t()} | {:error, term()} - def id(%__MODULE__{} = env_variable) do - selection = select(env_variable.selection, "id") - execute(selection, env_variable.client) - end - ) - - ( - @doc "The environment variable name." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = env_variable) do - selection = select(env_variable.selection, "name") - execute(selection, env_variable.client) - end - ) - - ( - @doc "The environment variable value." - @spec value(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def value(%__MODULE__{} = env_variable) do - selection = select(env_variable.selection, "value") - execute(selection, env_variable.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this EnvVariable." + @spec id(t()) :: {:ok, Dagger.EnvVariableID.t()} | {:error, term()} + def id(%__MODULE__{} = env_variable) do + selection = + env_variable.selection |> select("id") + + execute(selection, env_variable.client) + end + + @doc "The environment variable name." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = env_variable) do + selection = + env_variable.selection |> select("name") + + execute(selection, env_variable.client) + end + + @doc "The environment variable value." + @spec value(t()) :: {:ok, String.t()} | {:error, term()} + def value(%__MODULE__{} = env_variable) do + selection = + env_variable.selection |> select("value") + + execute(selection, env_variable.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/env_variable_id.ex b/sdk/elixir/lib/dagger/gen/env_variable_id.ex index e7ee21c7a66..3540a4b3fbe 100644 --- a/sdk/elixir/lib/dagger/gen/env_variable_id.ex +++ b/sdk/elixir/lib/dagger/gen/env_variable_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.EnvVariableID do @moduledoc "The `EnvVariableID` scalar type represents an identifier for an object of type EnvVariable." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/field_type_def.ex b/sdk/elixir/lib/dagger/gen/field_type_def.ex index c4b35de479e..d4431c08e26 100644 --- a/sdk/elixir/lib/dagger/gen/field_type_def.ex +++ b/sdk/elixir/lib/dagger/gen/field_type_def.ex @@ -1,43 +1,55 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FieldTypeDef do - @moduledoc "A definition of a field on a custom object defined in a Module.\n\nA field on an object has a static value, as opposed to a function on an object whose value is computed by invoking code (and can accept arguments)." + @moduledoc """ + A definition of a field on a custom object defined in a Module. + + A field on an object has a static value, as opposed to a function on an object whose value is computed by invoking code (and can accept arguments). + """ + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A doc string for the field, if any." - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = field_type_def) do - selection = select(field_type_def.selection, "description") - execute(selection, field_type_def.client) - end - ) - - ( - @doc "A unique identifier for this FieldTypeDef." - @spec id(t()) :: {:ok, Dagger.FieldTypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = field_type_def) do - selection = select(field_type_def.selection, "id") - execute(selection, field_type_def.client) - end - ) - - ( - @doc "The name of the field in lowerCamelCase format." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = field_type_def) do - selection = select(field_type_def.selection, "name") - execute(selection, field_type_def.client) - end - ) - - ( - @doc "The type of the field." - @spec type_def(t()) :: Dagger.TypeDef.t() - def type_def(%__MODULE__{} = field_type_def) do - selection = select(field_type_def.selection, "typeDef") - %Dagger.TypeDef{selection: selection, client: field_type_def.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "A doc string for the field, if any." + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = field_type_def) do + selection = + field_type_def.selection |> select("description") + + execute(selection, field_type_def.client) + end + + @doc "A unique identifier for this FieldTypeDef." + @spec id(t()) :: {:ok, Dagger.FieldTypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = field_type_def) do + selection = + field_type_def.selection |> select("id") + + execute(selection, field_type_def.client) + end + + @doc "The name of the field in lowerCamelCase format." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = field_type_def) do + selection = + field_type_def.selection |> select("name") + + execute(selection, field_type_def.client) + end + + @doc "The type of the field." + @spec type_def(t()) :: Dagger.TypeDef.t() + def type_def(%__MODULE__{} = field_type_def) do + selection = + field_type_def.selection |> select("typeDef") + + %Dagger.TypeDef{ + selection: selection, + client: field_type_def.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/field_type_def_id.ex b/sdk/elixir/lib/dagger/gen/field_type_def_id.ex index f7d37938902..b902ba1de8d 100644 --- a/sdk/elixir/lib/dagger/gen/field_type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/field_type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FieldTypeDefID do @moduledoc "The `FieldTypeDefID` scalar type represents an identifier for an object of type FieldTypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/file.ex b/sdk/elixir/lib/dagger/gen/file.ex index 5402c76ba1c..4225ee63538 100644 --- a/sdk/elixir/lib/dagger/gen/file.ex +++ b/sdk/elixir/lib/dagger/gen/file.ex @@ -1,82 +1,82 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.File do @moduledoc "A file." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID @derive Dagger.Sync defstruct [:selection, :client] - ( - @doc "Retrieves the contents of the file." - @spec contents(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def contents(%__MODULE__{} = file) do - selection = select(file.selection, "contents") - execute(selection, file.client) - end - ) - - ( - @doc "Writes the file to a file path on the host.\n\n## Required Arguments\n\n* `path` - Location of the written directory (e.g., \"output.txt\").\n\n## Optional Arguments\n\n* `allow_parent_dir_path` - If allowParentDirPath is true, the path argument can be a directory path, in which case the file will be created in that directory." - @spec export(t(), Dagger.String.t(), keyword()) :: - {:ok, Dagger.Boolean.t()} | {:error, term()} - def export(%__MODULE__{} = file, path, optional_args \\ []) do - selection = select(file.selection, "export") - selection = arg(selection, "path", path) - - selection = - if is_nil(optional_args[:allow_parent_dir_path]) do - selection - else - arg(selection, "allowParentDirPath", optional_args[:allow_parent_dir_path]) - end - - execute(selection, file.client) - end - ) - - ( - @doc "A unique identifier for this File." - @spec id(t()) :: {:ok, Dagger.FileID.t()} | {:error, term()} - def id(%__MODULE__{} = file) do - selection = select(file.selection, "id") - execute(selection, file.client) - end - ) - - ( - @doc "Retrieves the name of the file." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = file) do - selection = select(file.selection, "name") - execute(selection, file.client) - end - ) - - ( - @doc "Retrieves the size of the file, in bytes." - @spec size(t()) :: {:ok, Dagger.Int.t()} | {:error, term()} - def size(%__MODULE__{} = file) do - selection = select(file.selection, "size") - execute(selection, file.client) - end - ) - - ( - @doc "Force evaluation in the engine." - @spec sync(t()) :: {:ok, Dagger.FileID.t()} | {:error, term()} - def sync(%__MODULE__{} = file) do - selection = select(file.selection, "sync") - execute(selection, file.client) - end - ) - - ( - @doc "Retrieves this file with its created/modified timestamps set to the given time.\n\n## Required Arguments\n\n* `timestamp` - Timestamp to set dir/files in.\n\nFormatted in seconds following Unix epoch (e.g., 1672531199)." - @spec with_timestamps(t(), Dagger.Int.t()) :: Dagger.File.t() - def with_timestamps(%__MODULE__{} = file, timestamp) do - selection = select(file.selection, "withTimestamps") - selection = arg(selection, "timestamp", timestamp) - %Dagger.File{selection: selection, client: file.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "Retrieves the contents of the file." + @spec contents(t()) :: {:ok, String.t()} | {:error, term()} + def contents(%__MODULE__{} = file) do + selection = + file.selection |> select("contents") + + execute(selection, file.client) + end + + @doc "Writes the file to a file path on the host." + @spec export(t(), String.t(), [{:allow_parent_dir_path, boolean() | nil}]) :: + {:ok, boolean()} | {:error, term()} + def export(%__MODULE__{} = file, path, optional_args \\ []) do + selection = + file.selection + |> select("export") + |> put_arg("path", path) + |> maybe_put_arg("allowParentDirPath", optional_args[:allow_parent_dir_path]) + + execute(selection, file.client) + end + + @doc "A unique identifier for this File." + @spec id(t()) :: {:ok, Dagger.FileID.t()} | {:error, term()} + def id(%__MODULE__{} = file) do + selection = + file.selection |> select("id") + + execute(selection, file.client) + end + + @doc "Retrieves the name of the file." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = file) do + selection = + file.selection |> select("name") + + execute(selection, file.client) + end + + @doc "Retrieves the size of the file, in bytes." + @spec size(t()) :: {:ok, integer()} | {:error, term()} + def size(%__MODULE__{} = file) do + selection = + file.selection |> select("size") + + execute(selection, file.client) + end + + @doc "Force evaluation in the engine." + @spec sync(t()) :: {:ok, Dagger.FileID.t()} | {:error, term()} + def sync(%__MODULE__{} = file) do + selection = + file.selection |> select("sync") + + execute(selection, file.client) + end + + @doc "Retrieves this file with its created/modified timestamps set to the given time." + @spec with_timestamps(t(), integer()) :: Dagger.File.t() + def with_timestamps(%__MODULE__{} = file, timestamp) do + selection = + file.selection |> select("withTimestamps") |> put_arg("timestamp", timestamp) + + %Dagger.File{ + selection: selection, + client: file.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/file_id.ex b/sdk/elixir/lib/dagger/gen/file_id.ex index afb7c3de137..d77a5be307e 100644 --- a/sdk/elixir/lib/dagger/gen/file_id.ex +++ b/sdk/elixir/lib/dagger/gen/file_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FileID do @moduledoc "The `FileID` scalar type represents an identifier for an object of type File." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/float.ex b/sdk/elixir/lib/dagger/gen/float.ex deleted file mode 100644 index 0e316c13575..00000000000 --- a/sdk/elixir/lib/dagger/gen/float.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.Float do - @moduledoc "The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)." - @type t() :: float() -end diff --git a/sdk/elixir/lib/dagger/gen/function.ex b/sdk/elixir/lib/dagger/gen/function.ex index 1b97e1f3bab..0cb93cc362d 100644 --- a/sdk/elixir/lib/dagger/gen/function.ex +++ b/sdk/elixir/lib/dagger/gen/function.ex @@ -1,103 +1,107 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Function do - @moduledoc "Function represents a resolver provided by a Module.\n\nA function always evaluates against a parent object and is given a set of named arguments." + @moduledoc """ + Function represents a resolver provided by a Module. + + A function always evaluates against a parent object and is given a set of named arguments. + """ + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "Arguments accepted by the function, if any." - @spec args(t()) :: {:ok, [Dagger.FunctionArg.t()]} | {:error, term()} - def args(%__MODULE__{} = function) do - selection = select(function.selection, "args") - selection = select(selection, "defaultValue description id name typeDef") - - with {:ok, data} <- execute(selection, function.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFunctionArgFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.FunctionArg{selection: elem_selection, client: function.client} - end)} - end - end - ) - - ( - @doc "A doc string for the function, if any." - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = function) do - selection = select(function.selection, "description") - execute(selection, function.client) - end - ) - - ( - @doc "A unique identifier for this Function." - @spec id(t()) :: {:ok, Dagger.FunctionID.t()} | {:error, term()} - def id(%__MODULE__{} = function) do - selection = select(function.selection, "id") - execute(selection, function.client) - end - ) - - ( - @doc "The name of the function." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = function) do - selection = select(function.selection, "name") - execute(selection, function.client) - end - ) - - ( - @doc "The type returned by the function." - @spec return_type(t()) :: Dagger.TypeDef.t() - def return_type(%__MODULE__{} = function) do - selection = select(function.selection, "returnType") - %Dagger.TypeDef{selection: selection, client: function.client} - end - ) - - ( - @doc "Returns the function with the provided argument\n\n## Required Arguments\n\n* `name` - The name of the argument\n* `type_def` - The type of the argument\n\n## Optional Arguments\n\n* `description` - A doc string for the argument, if any\n* `default_value` - A default value to use for this argument if not explicitly set by the caller, if any" - @spec with_arg(t(), Dagger.String.t(), Dagger.TypeDef.t(), keyword()) :: Dagger.Function.t() - def with_arg(%__MODULE__{} = function, name, type_def, optional_args \\ []) do - selection = select(function.selection, "withArg") - selection = arg(selection, "name", name) - - ( - {:ok, id} = Dagger.TypeDef.id(type_def) - selection = arg(selection, "typeDef", id) - ) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - selection = - if is_nil(optional_args[:default_value]) do - selection - else - arg(selection, "defaultValue", optional_args[:default_value]) - end - - %Dagger.Function{selection: selection, client: function.client} - end - ) - - ( - @doc "Returns the function with the given doc string.\n\n## Required Arguments\n\n* `description` - The doc string to set." - @spec with_description(t(), Dagger.String.t()) :: Dagger.Function.t() - def with_description(%__MODULE__{} = function, description) do - selection = select(function.selection, "withDescription") - selection = arg(selection, "description", description) - %Dagger.Function{selection: selection, client: function.client} + @type t() :: %__MODULE__{} + + @doc "Arguments accepted by the function, if any." + @spec args(t()) :: {:ok, [Dagger.FunctionArg.t()]} | {:error, term()} + def args(%__MODULE__{} = function) do + selection = + function.selection |> select("args") |> select("id") + + with {:ok, items} <- execute(selection, function.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.FunctionArg{ + selection: + query() + |> select("loadFunctionArgFromID") + |> arg("id", id), + client: function.client + } + end} end - ) + end + + @doc "A doc string for the function, if any." + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = function) do + selection = + function.selection |> select("description") + + execute(selection, function.client) + end + + @doc "A unique identifier for this Function." + @spec id(t()) :: {:ok, Dagger.FunctionID.t()} | {:error, term()} + def id(%__MODULE__{} = function) do + selection = + function.selection |> select("id") + + execute(selection, function.client) + end + + @doc "The name of the function." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = function) do + selection = + function.selection |> select("name") + + execute(selection, function.client) + end + + @doc "The type returned by the function." + @spec return_type(t()) :: Dagger.TypeDef.t() + def return_type(%__MODULE__{} = function) do + selection = + function.selection |> select("returnType") + + %Dagger.TypeDef{ + selection: selection, + client: function.client + } + end + + @doc "Returns the function with the provided argument" + @spec with_arg(t(), String.t(), Dagger.TypeDef.t(), [ + {:description, String.t() | nil}, + {:default_value, Dagger.JSON.t() | nil} + ]) :: Dagger.Function.t() + def with_arg(%__MODULE__{} = function, name, type_def, optional_args \\ []) do + selection = + function.selection + |> select("withArg") + |> put_arg("name", name) + |> put_arg("typeDef", Dagger.ID.id!(type_def)) + |> maybe_put_arg("description", optional_args[:description]) + |> maybe_put_arg("defaultValue", optional_args[:default_value]) + + %Dagger.Function{ + selection: selection, + client: function.client + } + end + + @doc "Returns the function with the given doc string." + @spec with_description(t(), String.t()) :: Dagger.Function.t() + def with_description(%__MODULE__{} = function, description) do + selection = + function.selection |> select("withDescription") |> put_arg("description", description) + + %Dagger.Function{ + selection: selection, + client: function.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/function_arg.ex b/sdk/elixir/lib/dagger/gen/function_arg.ex index 724e67d4b1b..3c88fe6bdf9 100644 --- a/sdk/elixir/lib/dagger/gen/function_arg.ex +++ b/sdk/elixir/lib/dagger/gen/function_arg.ex @@ -1,52 +1,64 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionArg do - @moduledoc "An argument accepted by a function.\n\nThis is a specification for an argument at function definition time, not an argument passed at function call time." + @moduledoc """ + An argument accepted by a function. + + This is a specification for an argument at function definition time, not an argument passed at function call time. + """ + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A default value to use for this argument when not explicitly set by the caller, if any." - @spec default_value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} - def default_value(%__MODULE__{} = function_arg) do - selection = select(function_arg.selection, "defaultValue") - execute(selection, function_arg.client) - end - ) - - ( - @doc "A doc string for the argument, if any." - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = function_arg) do - selection = select(function_arg.selection, "description") - execute(selection, function_arg.client) - end - ) - - ( - @doc "A unique identifier for this FunctionArg." - @spec id(t()) :: {:ok, Dagger.FunctionArgID.t()} | {:error, term()} - def id(%__MODULE__{} = function_arg) do - selection = select(function_arg.selection, "id") - execute(selection, function_arg.client) - end - ) - - ( - @doc "The name of the argument in lowerCamelCase format." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = function_arg) do - selection = select(function_arg.selection, "name") - execute(selection, function_arg.client) - end - ) - - ( - @doc "The type of the argument." - @spec type_def(t()) :: Dagger.TypeDef.t() - def type_def(%__MODULE__{} = function_arg) do - selection = select(function_arg.selection, "typeDef") - %Dagger.TypeDef{selection: selection, client: function_arg.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "A default value to use for this argument when not explicitly set by the caller, if any." + @spec default_value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} + def default_value(%__MODULE__{} = function_arg) do + selection = + function_arg.selection |> select("defaultValue") + + execute(selection, function_arg.client) + end + + @doc "A doc string for the argument, if any." + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = function_arg) do + selection = + function_arg.selection |> select("description") + + execute(selection, function_arg.client) + end + + @doc "A unique identifier for this FunctionArg." + @spec id(t()) :: {:ok, Dagger.FunctionArgID.t()} | {:error, term()} + def id(%__MODULE__{} = function_arg) do + selection = + function_arg.selection |> select("id") + + execute(selection, function_arg.client) + end + + @doc "The name of the argument in lowerCamelCase format." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = function_arg) do + selection = + function_arg.selection |> select("name") + + execute(selection, function_arg.client) + end + + @doc "The type of the argument." + @spec type_def(t()) :: Dagger.TypeDef.t() + def type_def(%__MODULE__{} = function_arg) do + selection = + function_arg.selection |> select("typeDef") + + %Dagger.TypeDef{ + selection: selection, + client: function_arg.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/function_arg_id.ex b/sdk/elixir/lib/dagger/gen/function_arg_id.ex index 7910fe94d59..7152675fa70 100644 --- a/sdk/elixir/lib/dagger/gen/function_arg_id.ex +++ b/sdk/elixir/lib/dagger/gen/function_arg_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionArgID do @moduledoc "The `FunctionArgID` scalar type represents an identifier for an object of type FunctionArg." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/function_call.ex b/sdk/elixir/lib/dagger/gen/function_call.ex index 55e8a11ade5..87b5c252844 100644 --- a/sdk/elixir/lib/dagger/gen/function_call.ex +++ b/sdk/elixir/lib/dagger/gen/function_call.ex @@ -1,73 +1,77 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionCall do @moduledoc "An active function call." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this FunctionCall." - @spec id(t()) :: {:ok, Dagger.FunctionCallID.t()} | {:error, term()} - def id(%__MODULE__{} = function_call) do - selection = select(function_call.selection, "id") - execute(selection, function_call.client) - end - ) - - ( - @doc "The argument values the function is being invoked with." - @spec input_args(t()) :: {:ok, [Dagger.FunctionCallArgValue.t()]} | {:error, term()} - def input_args(%__MODULE__{} = function_call) do - selection = select(function_call.selection, "inputArgs") - selection = select(selection, "id name value") - - with {:ok, data} <- execute(selection, function_call.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFunctionCallArgValueFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.FunctionCallArgValue{selection: elem_selection, client: function_call.client} - end)} - end - end - ) - - ( - @doc "The name of the function being called." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = function_call) do - selection = select(function_call.selection, "name") - execute(selection, function_call.client) - end - ) - - ( - @doc "The value of the parent object of the function being called. If the function is top-level to the module, this is always an empty object." - @spec parent(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} - def parent(%__MODULE__{} = function_call) do - selection = select(function_call.selection, "parent") - execute(selection, function_call.client) - end - ) - - ( - @doc "The name of the parent object of the function being called. If the function is top-level to the module, this is the name of the module." - @spec parent_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def parent_name(%__MODULE__{} = function_call) do - selection = select(function_call.selection, "parentName") - execute(selection, function_call.client) - end - ) - - ( - @doc "Set the return value of the function call to the provided value.\n\n## Required Arguments\n\n* `value` - JSON serialization of the return value." - @spec return_value(t(), Dagger.JSON.t()) :: {:ok, Dagger.Void.t() | nil} | {:error, term()} - def return_value(%__MODULE__{} = function_call, value) do - selection = select(function_call.selection, "returnValue") - selection = arg(selection, "value", value) - execute(selection, function_call.client) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this FunctionCall." + @spec id(t()) :: {:ok, Dagger.FunctionCallID.t()} | {:error, term()} + def id(%__MODULE__{} = function_call) do + selection = + function_call.selection |> select("id") + + execute(selection, function_call.client) + end + + @doc "The argument values the function is being invoked with." + @spec input_args(t()) :: {:ok, [Dagger.FunctionCallArgValue.t()]} | {:error, term()} + def input_args(%__MODULE__{} = function_call) do + selection = + function_call.selection |> select("inputArgs") |> select("id") + + with {:ok, items} <- execute(selection, function_call.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.FunctionCallArgValue{ + selection: + query() + |> select("loadFunctionCallArgValueFromID") + |> arg("id", id), + client: function_call.client + } + end} end - ) + end + + @doc "The name of the function being called." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = function_call) do + selection = + function_call.selection |> select("name") + + execute(selection, function_call.client) + end + + @doc "The value of the parent object of the function being called. If the function is top-level to the module, this is always an empty object." + @spec parent(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} + def parent(%__MODULE__{} = function_call) do + selection = + function_call.selection |> select("parent") + + execute(selection, function_call.client) + end + + @doc "The name of the parent object of the function being called. If the function is top-level to the module, this is the name of the module." + @spec parent_name(t()) :: {:ok, String.t()} | {:error, term()} + def parent_name(%__MODULE__{} = function_call) do + selection = + function_call.selection |> select("parentName") + + execute(selection, function_call.client) + end + + @doc "Set the return value of the function call to the provided value." + @spec return_value(t(), Dagger.JSON.t()) :: {:ok, Dagger.Void.t() | nil} | {:error, term()} + def return_value(%__MODULE__{} = function_call, value) do + selection = + function_call.selection |> select("returnValue") |> put_arg("value", value) + + execute(selection, function_call.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/function_call_arg_value.ex b/sdk/elixir/lib/dagger/gen/function_call_arg_value.ex index 4250f8eaa42..6dfe6a3af36 100644 --- a/sdk/elixir/lib/dagger/gen/function_call_arg_value.ex +++ b/sdk/elixir/lib/dagger/gen/function_call_arg_value.ex @@ -1,34 +1,39 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionCallArgValue do @moduledoc "A value passed as a named argument to a function call." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this FunctionCallArgValue." - @spec id(t()) :: {:ok, Dagger.FunctionCallArgValueID.t()} | {:error, term()} - def id(%__MODULE__{} = function_call_arg_value) do - selection = select(function_call_arg_value.selection, "id") - execute(selection, function_call_arg_value.client) - end - ) - - ( - @doc "The name of the argument." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = function_call_arg_value) do - selection = select(function_call_arg_value.selection, "name") - execute(selection, function_call_arg_value.client) - end - ) - - ( - @doc "The value of the argument represented as a JSON serialized string." - @spec value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} - def value(%__MODULE__{} = function_call_arg_value) do - selection = select(function_call_arg_value.selection, "value") - execute(selection, function_call_arg_value.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this FunctionCallArgValue." + @spec id(t()) :: {:ok, Dagger.FunctionCallArgValueID.t()} | {:error, term()} + def id(%__MODULE__{} = function_call_arg_value) do + selection = + function_call_arg_value.selection |> select("id") + + execute(selection, function_call_arg_value.client) + end + + @doc "The name of the argument." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = function_call_arg_value) do + selection = + function_call_arg_value.selection |> select("name") + + execute(selection, function_call_arg_value.client) + end + + @doc "The value of the argument represented as a JSON serialized string." + @spec value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()} + def value(%__MODULE__{} = function_call_arg_value) do + selection = + function_call_arg_value.selection |> select("value") + + execute(selection, function_call_arg_value.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/function_call_arg_value_id.ex b/sdk/elixir/lib/dagger/gen/function_call_arg_value_id.ex index a65068cdc78..f374a5fb3fb 100644 --- a/sdk/elixir/lib/dagger/gen/function_call_arg_value_id.ex +++ b/sdk/elixir/lib/dagger/gen/function_call_arg_value_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionCallArgValueID do @moduledoc "The `FunctionCallArgValueID` scalar type represents an identifier for an object of type FunctionCallArgValue." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/function_call_id.ex b/sdk/elixir/lib/dagger/gen/function_call_id.ex index 6dfbb068f2a..6fd5a2fb431 100644 --- a/sdk/elixir/lib/dagger/gen/function_call_id.ex +++ b/sdk/elixir/lib/dagger/gen/function_call_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionCallID do @moduledoc "The `FunctionCallID` scalar type represents an identifier for an object of type FunctionCall." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/function_call_input.ex b/sdk/elixir/lib/dagger/gen/function_call_input.ex deleted file mode 100644 index 22663eb7c19..00000000000 --- a/sdk/elixir/lib/dagger/gen/function_call_input.ex +++ /dev/null @@ -1,7 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.FunctionCallInput do - @moduledoc "FunctionCallInput" - @type t() :: %__MODULE__{name: Dagger.String.t(), value: Dagger.JSON.t()} - @derive Nestru.Decoder - defstruct [:name, :value] -end diff --git a/sdk/elixir/lib/dagger/gen/function_id.ex b/sdk/elixir/lib/dagger/gen/function_id.ex index 70428521a79..b0860dc9d10 100644 --- a/sdk/elixir/lib/dagger/gen/function_id.ex +++ b/sdk/elixir/lib/dagger/gen/function_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.FunctionID do @moduledoc "The `FunctionID` scalar type represents an identifier for an object of type Function." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/generated_code.ex b/sdk/elixir/lib/dagger/gen/generated_code.ex index 1fd724a0ce2..fa23d64e1dc 100644 --- a/sdk/elixir/lib/dagger/gen/generated_code.ex +++ b/sdk/elixir/lib/dagger/gen/generated_code.ex @@ -1,63 +1,75 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GeneratedCode do @moduledoc "The result of running an SDK's codegen." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The directory containing the generated code." - @spec code(t()) :: Dagger.Directory.t() - def code(%__MODULE__{} = generated_code) do - selection = select(generated_code.selection, "code") - %Dagger.Directory{selection: selection, client: generated_code.client} - end - ) - - ( - @doc "A unique identifier for this GeneratedCode." - @spec id(t()) :: {:ok, Dagger.GeneratedCodeID.t()} | {:error, term()} - def id(%__MODULE__{} = generated_code) do - selection = select(generated_code.selection, "id") - execute(selection, generated_code.client) - end - ) - - ( - @doc "List of paths to mark generated in version control (i.e. .gitattributes)." - @spec vcs_generated_paths(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def vcs_generated_paths(%__MODULE__{} = generated_code) do - selection = select(generated_code.selection, "vcsGeneratedPaths") - execute(selection, generated_code.client) - end - ) - - ( - @doc "List of paths to ignore in version control (i.e. .gitignore)." - @spec vcs_ignored_paths(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def vcs_ignored_paths(%__MODULE__{} = generated_code) do - selection = select(generated_code.selection, "vcsIgnoredPaths") - execute(selection, generated_code.client) - end - ) - - ( - @doc "Set the list of paths to mark generated in version control.\n\n## Required Arguments\n\n* `paths` -" - @spec with_vcs_generated_paths(t(), [Dagger.String.t()]) :: Dagger.GeneratedCode.t() - def with_vcs_generated_paths(%__MODULE__{} = generated_code, paths) do - selection = select(generated_code.selection, "withVCSGeneratedPaths") - selection = arg(selection, "paths", paths) - %Dagger.GeneratedCode{selection: selection, client: generated_code.client} - end - ) - - ( - @doc "Set the list of paths to ignore in version control.\n\n## Required Arguments\n\n* `paths` -" - @spec with_vcs_ignored_paths(t(), [Dagger.String.t()]) :: Dagger.GeneratedCode.t() - def with_vcs_ignored_paths(%__MODULE__{} = generated_code, paths) do - selection = select(generated_code.selection, "withVCSIgnoredPaths") - selection = arg(selection, "paths", paths) - %Dagger.GeneratedCode{selection: selection, client: generated_code.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "The directory containing the generated code." + @spec code(t()) :: Dagger.Directory.t() + def code(%__MODULE__{} = generated_code) do + selection = + generated_code.selection |> select("code") + + %Dagger.Directory{ + selection: selection, + client: generated_code.client + } + end + + @doc "A unique identifier for this GeneratedCode." + @spec id(t()) :: {:ok, Dagger.GeneratedCodeID.t()} | {:error, term()} + def id(%__MODULE__{} = generated_code) do + selection = + generated_code.selection |> select("id") + + execute(selection, generated_code.client) + end + + @doc "List of paths to mark generated in version control (i.e. .gitattributes)." + @spec vcs_generated_paths(t()) :: {:ok, [String.t()]} | {:error, term()} + def vcs_generated_paths(%__MODULE__{} = generated_code) do + selection = + generated_code.selection |> select("vcsGeneratedPaths") + + execute(selection, generated_code.client) + end + + @doc "List of paths to ignore in version control (i.e. .gitignore)." + @spec vcs_ignored_paths(t()) :: {:ok, [String.t()]} | {:error, term()} + def vcs_ignored_paths(%__MODULE__{} = generated_code) do + selection = + generated_code.selection |> select("vcsIgnoredPaths") + + execute(selection, generated_code.client) + end + + @doc "Set the list of paths to mark generated in version control." + @spec with_vcs_generated_paths(t(), [String.t()]) :: Dagger.GeneratedCode.t() + def with_vcs_generated_paths(%__MODULE__{} = generated_code, paths) do + selection = + generated_code.selection |> select("withVCSGeneratedPaths") |> put_arg("paths", paths) + + %Dagger.GeneratedCode{ + selection: selection, + client: generated_code.client + } + end + + @doc "Set the list of paths to ignore in version control." + @spec with_vcs_ignored_paths(t(), [String.t()]) :: Dagger.GeneratedCode.t() + def with_vcs_ignored_paths(%__MODULE__{} = generated_code, paths) do + selection = + generated_code.selection |> select("withVCSIgnoredPaths") |> put_arg("paths", paths) + + %Dagger.GeneratedCode{ + selection: selection, + client: generated_code.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/generated_code_id.ex b/sdk/elixir/lib/dagger/gen/generated_code_id.ex index 63bf44005f8..36169b9424c 100644 --- a/sdk/elixir/lib/dagger/gen/generated_code_id.ex +++ b/sdk/elixir/lib/dagger/gen/generated_code_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GeneratedCodeID do @moduledoc "The `GeneratedCodeID` scalar type represents an identifier for an object of type GeneratedCode." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/git_module_ref.ex b/sdk/elixir/lib/dagger/gen/git_module_ref.ex deleted file mode 100644 index b9ec0731363..00000000000 --- a/sdk/elixir/lib/dagger/gen/git_module_ref.ex +++ /dev/null @@ -1,61 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.GitModuleRef do - @moduledoc "A reference to a module loaded from a git repo." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "The URL from which the ref's git repo can be cloned from" - @spec clone_url(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def clone_url(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "cloneURL") - execute(selection, git_module_ref.client) - end - ) - - ( - @doc "" - @spec commit(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def commit(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "commit") - execute(selection, git_module_ref.client) - end - ) - - ( - @doc "The URL to the ref's git repo in a web browser" - @spec html_url(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def html_url(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "htmlURL") - execute(selection, git_module_ref.client) - end - ) - - ( - @doc "A unique identifier for this GitModuleRef." - @spec id(t()) :: {:ok, Dagger.GitModuleRefID.t()} | {:error, term()} - def id(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "id") - execute(selection, git_module_ref.client) - end - ) - - ( - @doc "" - @spec module_source_path(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def module_source_path(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "moduleSourcePath") - execute(selection, git_module_ref.client) - end - ) - - ( - @doc "" - @spec version(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def version(%__MODULE__{} = git_module_ref) do - selection = select(git_module_ref.selection, "version") - execute(selection, git_module_ref.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/git_module_ref_id.ex b/sdk/elixir/lib/dagger/gen/git_module_ref_id.ex deleted file mode 100644 index 897d3fc659a..00000000000 --- a/sdk/elixir/lib/dagger/gen/git_module_ref_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.GitModuleRefID do - @moduledoc "The `GitModuleRefID` scalar type represents an identifier for an object of type GitModuleRef." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/git_module_source.ex b/sdk/elixir/lib/dagger/gen/git_module_source.ex index 95dc26dc21f..cb655cbcca9 100644 --- a/sdk/elixir/lib/dagger/gen/git_module_source.ex +++ b/sdk/elixir/lib/dagger/gen/git_module_source.ex @@ -1,70 +1,78 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitModuleSource do @moduledoc "Module source originating from a git repo." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The URL from which the source's git repo can be cloned." - @spec clone_url(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def clone_url(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "cloneURL") - execute(selection, git_module_source.client) - end - ) - - ( - @doc "The resolved commit of the git repo this source points to." - @spec commit(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def commit(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "commit") - execute(selection, git_module_source.client) - end - ) - - ( - @doc "The directory containing everything needed to load load and use the module." - @spec context_directory(t()) :: Dagger.Directory.t() - def context_directory(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "contextDirectory") - %Dagger.Directory{selection: selection, client: git_module_source.client} - end - ) - - ( - @doc "The URL to the source's git repo in a web browser" - @spec html_url(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def html_url(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "htmlURL") - execute(selection, git_module_source.client) - end - ) - - ( - @doc "A unique identifier for this GitModuleSource." - @spec id(t()) :: {:ok, Dagger.GitModuleSourceID.t()} | {:error, term()} - def id(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "id") - execute(selection, git_module_source.client) - end - ) - - ( - @doc "The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory)." - @spec root_subpath(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def root_subpath(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "rootSubpath") - execute(selection, git_module_source.client) - end - ) - - ( - @doc "The specified version of the git repo this source points to." - @spec version(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def version(%__MODULE__{} = git_module_source) do - selection = select(git_module_source.selection, "version") - execute(selection, git_module_source.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "The URL from which the source's git repo can be cloned." + @spec clone_url(t()) :: {:ok, String.t()} | {:error, term()} + def clone_url(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("cloneURL") + + execute(selection, git_module_source.client) + end + + @doc "The resolved commit of the git repo this source points to." + @spec commit(t()) :: {:ok, String.t()} | {:error, term()} + def commit(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("commit") + + execute(selection, git_module_source.client) + end + + @doc "The directory containing everything needed to load load and use the module." + @spec context_directory(t()) :: Dagger.Directory.t() + def context_directory(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("contextDirectory") + + %Dagger.Directory{ + selection: selection, + client: git_module_source.client + } + end + + @doc "The URL to the source's git repo in a web browser" + @spec html_url(t()) :: {:ok, String.t()} | {:error, term()} + def html_url(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("htmlURL") + + execute(selection, git_module_source.client) + end + + @doc "A unique identifier for this GitModuleSource." + @spec id(t()) :: {:ok, Dagger.GitModuleSourceID.t()} | {:error, term()} + def id(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("id") + + execute(selection, git_module_source.client) + end + + @doc "The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory)." + @spec root_subpath(t()) :: {:ok, String.t()} | {:error, term()} + def root_subpath(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("rootSubpath") + + execute(selection, git_module_source.client) + end + + @doc "The specified version of the git repo this source points to." + @spec version(t()) :: {:ok, String.t()} | {:error, term()} + def version(%__MODULE__{} = git_module_source) do + selection = + git_module_source.selection |> select("version") + + execute(selection, git_module_source.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/git_module_source_id.ex b/sdk/elixir/lib/dagger/gen/git_module_source_id.ex index e8e85ce3828..10238745d33 100644 --- a/sdk/elixir/lib/dagger/gen/git_module_source_id.ex +++ b/sdk/elixir/lib/dagger/gen/git_module_source_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitModuleSourceID do @moduledoc "The `GitModuleSourceID` scalar type represents an identifier for an object of type GitModuleSource." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/git_ref.ex b/sdk/elixir/lib/dagger/gen/git_ref.ex index 48a9d9cc78d..18b85bd125c 100644 --- a/sdk/elixir/lib/dagger/gen/git_ref.ex +++ b/sdk/elixir/lib/dagger/gen/git_ref.ex @@ -1,50 +1,48 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitRef do @moduledoc "A git ref (tag, branch, or commit)." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The resolved commit id at this ref." - @spec commit(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def commit(%__MODULE__{} = git_ref) do - selection = select(git_ref.selection, "commit") - execute(selection, git_ref.client) - end - ) - - ( - @doc "A unique identifier for this GitRef." - @spec id(t()) :: {:ok, Dagger.GitRefID.t()} | {:error, term()} - def id(%__MODULE__{} = git_ref) do - selection = select(git_ref.selection, "id") - execute(selection, git_ref.client) - end - ) - - ( - @doc "The filesystem tree at this ref.\n\n\n\n## Optional Arguments\n\n* `ssh_known_hosts` - DEPRECATED: This option should be passed to `git` instead.\n* `ssh_auth_socket` - DEPRECATED: This option should be passed to `git` instead." - @spec tree(t(), keyword()) :: Dagger.Directory.t() - def tree(%__MODULE__{} = git_ref, optional_args \\ []) do - selection = select(git_ref.selection, "tree") - - selection = - if is_nil(optional_args[:ssh_known_hosts]) do - selection - else - arg(selection, "sshKnownHosts", optional_args[:ssh_known_hosts]) - end - - selection = - if is_nil(optional_args[:ssh_auth_socket]) do - selection - else - {:ok, id} = Dagger.Socket.id(optional_args[:ssh_auth_socket]) - arg(selection, "sshAuthSocket", id) - end - - %Dagger.Directory{selection: selection, client: git_ref.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "The resolved commit id at this ref." + @spec commit(t()) :: {:ok, String.t()} | {:error, term()} + def commit(%__MODULE__{} = git_ref) do + selection = + git_ref.selection |> select("commit") + + execute(selection, git_ref.client) + end + + @doc "A unique identifier for this GitRef." + @spec id(t()) :: {:ok, Dagger.GitRefID.t()} | {:error, term()} + def id(%__MODULE__{} = git_ref) do + selection = + git_ref.selection |> select("id") + + execute(selection, git_ref.client) + end + + @doc "The filesystem tree at this ref." + @spec tree(t(), [ + {:ssh_known_hosts, String.t() | nil}, + {:ssh_auth_socket, Dagger.SocketID.t() | nil} + ]) :: Dagger.Directory.t() + def tree(%__MODULE__{} = git_ref, optional_args \\ []) do + selection = + git_ref.selection + |> select("tree") + |> maybe_put_arg("sshKnownHosts", optional_args[:ssh_known_hosts]) + |> maybe_put_arg("sshAuthSocket", optional_args[:ssh_auth_socket]) + + %Dagger.Directory{ + selection: selection, + client: git_ref.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/git_ref_id.ex b/sdk/elixir/lib/dagger/gen/git_ref_id.ex index 3a25b8e5cd4..dd242cf46a3 100644 --- a/sdk/elixir/lib/dagger/gen/git_ref_id.ex +++ b/sdk/elixir/lib/dagger/gen/git_ref_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitRefID do @moduledoc "The `GitRefID` scalar type represents an identifier for an object of type GitRef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/git_repository.ex b/sdk/elixir/lib/dagger/gen/git_repository.ex index bfcf1058dd4..35d928e1e25 100644 --- a/sdk/elixir/lib/dagger/gen/git_repository.ex +++ b/sdk/elixir/lib/dagger/gen/git_repository.ex @@ -1,56 +1,69 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitRepository do @moduledoc "A git repository." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "Returns details of a branch.\n\n## Required Arguments\n\n* `name` - Branch's name (e.g., \"main\")." - @spec branch(t(), Dagger.String.t()) :: Dagger.GitRef.t() - def branch(%__MODULE__{} = git_repository, name) do - selection = select(git_repository.selection, "branch") - selection = arg(selection, "name", name) - %Dagger.GitRef{selection: selection, client: git_repository.client} - end - ) - - ( - @doc "Returns details of a commit.\n\n## Required Arguments\n\n* `id` - Identifier of the commit (e.g., \"b6315d8f2810962c601af73f86831f6866ea798b\")." - @spec commit(t(), Dagger.String.t()) :: Dagger.GitRef.t() - def commit(%__MODULE__{} = git_repository, id) do - selection = select(git_repository.selection, "commit") - selection = arg(selection, "id", id) - %Dagger.GitRef{selection: selection, client: git_repository.client} - end - ) - - ( - @doc "A unique identifier for this GitRepository." - @spec id(t()) :: {:ok, Dagger.GitRepositoryID.t()} | {:error, term()} - def id(%__MODULE__{} = git_repository) do - selection = select(git_repository.selection, "id") - execute(selection, git_repository.client) - end - ) - - ( - @doc "Returns details of a ref.\n\n## Required Arguments\n\n* `name` - Ref's name (can be a commit identifier, a tag name, a branch name, or a fully-qualified ref)." - @spec ref(t(), Dagger.String.t()) :: Dagger.GitRef.t() - def ref(%__MODULE__{} = git_repository, name) do - selection = select(git_repository.selection, "ref") - selection = arg(selection, "name", name) - %Dagger.GitRef{selection: selection, client: git_repository.client} - end - ) - - ( - @doc "Returns details of a tag.\n\n## Required Arguments\n\n* `name` - Tag's name (e.g., \"v0.3.9\")." - @spec tag(t(), Dagger.String.t()) :: Dagger.GitRef.t() - def tag(%__MODULE__{} = git_repository, name) do - selection = select(git_repository.selection, "tag") - selection = arg(selection, "name", name) - %Dagger.GitRef{selection: selection, client: git_repository.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "Returns details of a branch." + @spec branch(t(), String.t()) :: Dagger.GitRef.t() + def branch(%__MODULE__{} = git_repository, name) do + selection = + git_repository.selection |> select("branch") |> put_arg("name", name) + + %Dagger.GitRef{ + selection: selection, + client: git_repository.client + } + end + + @doc "Returns details of a commit." + @spec commit(t(), String.t()) :: Dagger.GitRef.t() + def commit(%__MODULE__{} = git_repository, id) do + selection = + git_repository.selection |> select("commit") |> put_arg("id", id) + + %Dagger.GitRef{ + selection: selection, + client: git_repository.client + } + end + + @doc "A unique identifier for this GitRepository." + @spec id(t()) :: {:ok, Dagger.GitRepositoryID.t()} | {:error, term()} + def id(%__MODULE__{} = git_repository) do + selection = + git_repository.selection |> select("id") + + execute(selection, git_repository.client) + end + + @doc "Returns details of a ref." + @spec ref(t(), String.t()) :: Dagger.GitRef.t() + def ref(%__MODULE__{} = git_repository, name) do + selection = + git_repository.selection |> select("ref") |> put_arg("name", name) + + %Dagger.GitRef{ + selection: selection, + client: git_repository.client + } + end + + @doc "Returns details of a tag." + @spec tag(t(), String.t()) :: Dagger.GitRef.t() + def tag(%__MODULE__{} = git_repository, name) do + selection = + git_repository.selection |> select("tag") |> put_arg("name", name) + + %Dagger.GitRef{ + selection: selection, + client: git_repository.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/git_repository_id.ex b/sdk/elixir/lib/dagger/gen/git_repository_id.ex index 9f66647c74f..d23a17740ae 100644 --- a/sdk/elixir/lib/dagger/gen/git_repository_id.ex +++ b/sdk/elixir/lib/dagger/gen/git_repository_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.GitRepositoryID do @moduledoc "The `GitRepositoryID` scalar type represents an identifier for an object of type GitRepository." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/host.ex b/sdk/elixir/lib/dagger/gen/host.ex index 27c3d0edb30..b372399e965 100644 --- a/sdk/elixir/lib/dagger/gen/host.ex +++ b/sdk/elixir/lib/dagger/gen/host.ex @@ -1,119 +1,112 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Host do @moduledoc "Information about the host environment." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "Accesses a directory on the host.\n\n## Required Arguments\n\n* `path` - Location of the directory to access (e.g., \".\").\n\n## Optional Arguments\n\n* `exclude` - Exclude artifacts that match the given pattern (e.g., [\"node_modules/\", \".git*\"]).\n* `include` - Include only artifacts that match the given pattern (e.g., [\"app/\", \"package.*\"])." - @spec directory(t(), Dagger.String.t(), keyword()) :: Dagger.Directory.t() - def directory(%__MODULE__{} = host, path, optional_args \\ []) do - selection = select(host.selection, "directory") - selection = arg(selection, "path", path) - - selection = - if is_nil(optional_args[:exclude]) do - selection - else - arg(selection, "exclude", optional_args[:exclude]) - end - - selection = - if is_nil(optional_args[:include]) do - selection - else - arg(selection, "include", optional_args[:include]) - end - - %Dagger.Directory{selection: selection, client: host.client} - end - ) - - ( - @doc "Accesses a file on the host.\n\n## Required Arguments\n\n* `path` - Location of the file to retrieve (e.g., \"README.md\")." - @spec file(t(), Dagger.String.t()) :: Dagger.File.t() - def file(%__MODULE__{} = host, path) do - selection = select(host.selection, "file") - selection = arg(selection, "path", path) - %Dagger.File{selection: selection, client: host.client} - end - ) - - ( - @doc "A unique identifier for this Host." - @spec id(t()) :: {:ok, Dagger.HostID.t()} | {:error, term()} - def id(%__MODULE__{} = host) do - selection = select(host.selection, "id") - execute(selection, host.client) - end - ) - - ( - @doc "Creates a service that forwards traffic to a specified address via the host.\n\n## Required Arguments\n\n* `ports` - Ports to expose via the service, forwarding through the host network.\n\nIf a port's frontend is unspecified or 0, it defaults to the same as the backend port.\n\nAn empty set of ports is not valid; an error will be returned.\n\n## Optional Arguments\n\n* `host` - Upstream host to forward traffic to." - @spec service(t(), [Dagger.PortForward.t()], keyword()) :: Dagger.Service.t() - def service(%__MODULE__{} = host, ports, optional_args \\ []) do - selection = select(host.selection, "service") - selection = arg(selection, "ports", ports) - - selection = - if is_nil(optional_args[:host]) do - selection - else - arg(selection, "host", optional_args[:host]) - end - - %Dagger.Service{selection: selection, client: host.client} - end - ) - - ( - @doc "Sets a secret given a user-defined name and the file path on the host, and returns the secret.\n\nThe file is limited to a size of 512000 bytes.\n\n## Required Arguments\n\n* `name` - The user defined name for this secret.\n* `path` - Location of the file to set as a secret." - @spec set_secret_file(t(), Dagger.String.t(), Dagger.String.t()) :: Dagger.Secret.t() - def set_secret_file(%__MODULE__{} = host, name, path) do - selection = select(host.selection, "setSecretFile") - selection = arg(selection, "name", name) - selection = arg(selection, "path", path) - %Dagger.Secret{selection: selection, client: host.client} - end - ) - - ( - @doc "Creates a tunnel that forwards traffic from the host to a service.\n\n## Required Arguments\n\n* `service` - Service to send traffic from the tunnel.\n\n## Optional Arguments\n\n* `ports` - Configure explicit port forwarding rules for the tunnel.\n\nIf a port's frontend is unspecified or 0, a random port will be chosen by the host.\n\nIf no ports are given, all of the service's ports are forwarded. If native is true, each port maps to the same port on the host. If native is false, each port maps to a random port chosen by the host.\n\nIf ports are given and native is true, the ports are additive.\n* `native` - Map each service port to the same port on the host, as if the service were running natively.\n\nNote: enabling may result in port conflicts." - @spec tunnel(t(), Dagger.Service.t(), keyword()) :: Dagger.Service.t() - def tunnel(%__MODULE__{} = host, service, optional_args \\ []) do - selection = select(host.selection, "tunnel") - - ( - {:ok, id} = Dagger.Service.id(service) - selection = arg(selection, "service", id) - ) - - selection = - if is_nil(optional_args[:ports]) do - selection - else - arg(selection, "ports", optional_args[:ports]) - end - - selection = - if is_nil(optional_args[:native]) do - selection - else - arg(selection, "native", optional_args[:native]) - end - - %Dagger.Service{selection: selection, client: host.client} - end - ) - - ( - @doc "Accesses a Unix socket on the host.\n\n## Required Arguments\n\n* `path` - Location of the Unix socket (e.g., \"/var/run/docker.sock\")." - @spec unix_socket(t(), Dagger.String.t()) :: Dagger.Socket.t() - def unix_socket(%__MODULE__{} = host, path) do - selection = select(host.selection, "unixSocket") - selection = arg(selection, "path", path) - %Dagger.Socket{selection: selection, client: host.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "Accesses a directory on the host." + @spec directory(t(), String.t(), [{:exclude, [String.t()]}, {:include, [String.t()]}]) :: + Dagger.Directory.t() + def directory(%__MODULE__{} = host, path, optional_args \\ []) do + selection = + host.selection + |> select("directory") + |> put_arg("path", path) + |> maybe_put_arg("exclude", optional_args[:exclude]) + |> maybe_put_arg("include", optional_args[:include]) + + %Dagger.Directory{ + selection: selection, + client: host.client + } + end + + @doc "Accesses a file on the host." + @spec file(t(), String.t()) :: Dagger.File.t() + def file(%__MODULE__{} = host, path) do + selection = + host.selection |> select("file") |> put_arg("path", path) + + %Dagger.File{ + selection: selection, + client: host.client + } + end + + @doc "A unique identifier for this Host." + @spec id(t()) :: {:ok, Dagger.HostID.t()} | {:error, term()} + def id(%__MODULE__{} = host) do + selection = + host.selection |> select("id") + + execute(selection, host.client) + end + + @doc "Creates a service that forwards traffic to a specified address via the host." + @spec service(t(), [Dagger.PortForward.t()], [{:host, String.t() | nil}]) :: Dagger.Service.t() + def service(%__MODULE__{} = host, ports, optional_args \\ []) do + selection = + host.selection + |> select("service") + |> put_arg("ports", ports) + |> maybe_put_arg("host", optional_args[:host]) + + %Dagger.Service{ + selection: selection, + client: host.client + } + end + + @doc """ + Sets a secret given a user-defined name and the file path on the host, and returns the secret. + + The file is limited to a size of 512000 bytes. + """ + @spec set_secret_file(t(), String.t(), String.t()) :: Dagger.Secret.t() + def set_secret_file(%__MODULE__{} = host, name, path) do + selection = + host.selection |> select("setSecretFile") |> put_arg("name", name) |> put_arg("path", path) + + %Dagger.Secret{ + selection: selection, + client: host.client + } + end + + @doc "Creates a tunnel that forwards traffic from the host to a service." + @spec tunnel(t(), Dagger.Service.t(), [ + {:ports, [Dagger.PortForward.t()]}, + {:native, boolean() | nil} + ]) :: Dagger.Service.t() + def tunnel(%__MODULE__{} = host, service, optional_args \\ []) do + selection = + host.selection + |> select("tunnel") + |> put_arg("service", Dagger.ID.id!(service)) + |> maybe_put_arg("ports", optional_args[:ports]) + |> maybe_put_arg("native", optional_args[:native]) + + %Dagger.Service{ + selection: selection, + client: host.client + } + end + + @doc "Accesses a Unix socket on the host." + @spec unix_socket(t(), String.t()) :: Dagger.Socket.t() + def unix_socket(%__MODULE__{} = host, path) do + selection = + host.selection |> select("unixSocket") |> put_arg("path", path) + + %Dagger.Socket{ + selection: selection, + client: host.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/host_id.ex b/sdk/elixir/lib/dagger/gen/host_id.ex index f6f23267a80..ca4bf3fe31e 100644 --- a/sdk/elixir/lib/dagger/gen/host_id.ex +++ b/sdk/elixir/lib/dagger/gen/host_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.HostID do @moduledoc "The `HostID` scalar type represents an identifier for an object of type Host." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/host_variable.ex b/sdk/elixir/lib/dagger/gen/host_variable.ex deleted file mode 100644 index be233f90253..00000000000 --- a/sdk/elixir/lib/dagger/gen/host_variable.ex +++ /dev/null @@ -1,7 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.HostVariable do - @moduledoc "An environment variable on the host environment." - @type t() :: %__MODULE__{secret: Dagger.Secret.t(), value: Dagger.String.t()} - @derive Nestru.Decoder - defstruct [:secret, :value] -end diff --git a/sdk/elixir/lib/dagger/gen/id.ex b/sdk/elixir/lib/dagger/gen/id.ex deleted file mode 100644 index c7bc75e4e1a..00000000000 --- a/sdk/elixir/lib/dagger/gen/id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ID do - @moduledoc "The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/image_layer_compression.ex b/sdk/elixir/lib/dagger/gen/image_layer_compression.ex index 7040d4a577c..480c885b5cd 100644 --- a/sdk/elixir/lib/dagger/gen/image_layer_compression.ex +++ b/sdk/elixir/lib/dagger/gen/image_layer_compression.ex @@ -1,36 +1,18 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ImageLayerCompression do @moduledoc "Compression algorithm to use for image layers." - @type t() :: :EStarGZ | :Gzip | :Uncompressed | :Zstd - ( - @doc "" - @spec e_star_gz() :: :EStarGZ - def e_star_gz() do - :EStarGZ - end - ) - ( - @doc "" - @spec gzip() :: :Gzip - def gzip() do - :Gzip - end - ) + @type t() :: :Gzip | :Zstd | :EStarGZ | :Uncompressed - ( - @doc "" - @spec uncompressed() :: :Uncompressed - def uncompressed() do - :Uncompressed - end - ) + @spec gzip() :: :Gzip + def gzip(), do: :Gzip - ( - @doc "" - @spec zstd() :: :Zstd - def zstd() do - :Zstd - end - ) + @spec zstd() :: :Zstd + def zstd(), do: :Zstd + + @spec e_star_gz() :: :EStarGZ + def e_star_gz(), do: :EStarGZ + + @spec uncompressed() :: :Uncompressed + def uncompressed(), do: :Uncompressed end diff --git a/sdk/elixir/lib/dagger/gen/image_media_types.ex b/sdk/elixir/lib/dagger/gen/image_media_types.ex index 00021b900b9..776f476fbee 100644 --- a/sdk/elixir/lib/dagger/gen/image_media_types.ex +++ b/sdk/elixir/lib/dagger/gen/image_media_types.ex @@ -1,20 +1,12 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ImageMediaTypes do @moduledoc "Mediatypes to use in published or exported image metadata." - @type t() :: :DockerMediaTypes | :OCIMediaTypes - ( - @doc "" - @spec docker_media_types() :: :DockerMediaTypes - def docker_media_types() do - :DockerMediaTypes - end - ) - ( - @doc "" - @spec oci_media_types() :: :OCIMediaTypes - def oci_media_types() do - :OCIMediaTypes - end - ) + @type t() :: :OCIMediaTypes | :DockerMediaTypes + + @spec oci_media_types() :: :OCIMediaTypes + def oci_media_types(), do: :OCIMediaTypes + + @spec docker_media_types() :: :DockerMediaTypes + def docker_media_types(), do: :DockerMediaTypes end diff --git a/sdk/elixir/lib/dagger/gen/input_type_def.ex b/sdk/elixir/lib/dagger/gen/input_type_def.ex index 742531f9839..1dee71328fa 100644 --- a/sdk/elixir/lib/dagger/gen/input_type_def.ex +++ b/sdk/elixir/lib/dagger/gen/input_type_def.ex @@ -1,45 +1,55 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.InputTypeDef do - @moduledoc "A graphql input type, which is essentially just a group of named args.\nThis is currently only used to represent pre-existing usage of graphql input types\nin the core API. It is not used by user modules and shouldn't ever be as user\nmodule accept input objects via their id rather than graphql input types." + @moduledoc """ + A graphql input type, which is essentially just a group of named args. + This is currently only used to represent pre-existing usage of graphql input types + in the core API. It is not used by user modules and shouldn't ever be as user + module accept input objects via their id rather than graphql input types. + """ + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "Static fields defined on this input object, if any." - @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()} - def fields(%__MODULE__{} = input_type_def) do - selection = select(input_type_def.selection, "fields") - selection = select(selection, "description id name typeDef") - - with {:ok, data} <- execute(selection, input_type_def.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFieldTypeDefFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.FieldTypeDef{selection: elem_selection, client: input_type_def.client} - end)} - end - end - ) - - ( - @doc "A unique identifier for this InputTypeDef." - @spec id(t()) :: {:ok, Dagger.InputTypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = input_type_def) do - selection = select(input_type_def.selection, "id") - execute(selection, input_type_def.client) - end - ) - - ( - @doc "The name of the input object." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = input_type_def) do - selection = select(input_type_def.selection, "name") - execute(selection, input_type_def.client) + @type t() :: %__MODULE__{} + + @doc "Static fields defined on this input object, if any." + @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()} + def fields(%__MODULE__{} = input_type_def) do + selection = + input_type_def.selection |> select("fields") |> select("id") + + with {:ok, items} <- execute(selection, input_type_def.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.FieldTypeDef{ + selection: + query() + |> select("loadFieldTypeDefFromID") + |> arg("id", id), + client: input_type_def.client + } + end} end - ) + end + + @doc "A unique identifier for this InputTypeDef." + @spec id(t()) :: {:ok, Dagger.InputTypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = input_type_def) do + selection = + input_type_def.selection |> select("id") + + execute(selection, input_type_def.client) + end + + @doc "The name of the input object." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = input_type_def) do + selection = + input_type_def.selection |> select("name") + + execute(selection, input_type_def.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/input_type_def_id.ex b/sdk/elixir/lib/dagger/gen/input_type_def_id.ex index d5bab6678dd..b934e2a3258 100644 --- a/sdk/elixir/lib/dagger/gen/input_type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/input_type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.InputTypeDefID do @moduledoc "The `InputTypeDefID` scalar type represents an identifier for an object of type InputTypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/int.ex b/sdk/elixir/lib/dagger/gen/int.ex deleted file mode 100644 index cc2181a671a..00000000000 --- a/sdk/elixir/lib/dagger/gen/int.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.Int do - @moduledoc "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1." - @type t() :: integer() -end diff --git a/sdk/elixir/lib/dagger/gen/interactive_shell.ex b/sdk/elixir/lib/dagger/gen/interactive_shell.ex deleted file mode 100644 index 60e1f1b1c87..00000000000 --- a/sdk/elixir/lib/dagger/gen/interactive_shell.ex +++ /dev/null @@ -1,25 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.InteractiveShell do - @moduledoc "An interactive shell that clients can connect to." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "A unique identifier for this InteractiveShell." - @spec id(t()) :: {:ok, Dagger.InteractiveShellID.t()} | {:error, term()} - def id(%__MODULE__{} = interactive_shell) do - selection = select(interactive_shell.selection, "id") - execute(selection, interactive_shell.client) - end - ) - - ( - @doc "An http endpoint at which an interactive shell can be connected to over a websocket." - @spec websocket_endpoint(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def websocket_endpoint(%__MODULE__{} = interactive_shell) do - selection = select(interactive_shell.selection, "websocketEndpoint") - execute(selection, interactive_shell.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/interactive_shell_id.ex b/sdk/elixir/lib/dagger/gen/interactive_shell_id.ex deleted file mode 100644 index ba9588fc71e..00000000000 --- a/sdk/elixir/lib/dagger/gen/interactive_shell_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.InteractiveShellID do - @moduledoc "The `InteractiveShellID` scalar type represents an identifier for an object of type InteractiveShell." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/interface_type_def.ex b/sdk/elixir/lib/dagger/gen/interface_type_def.ex index 24f35f6d13a..8a5d481f7bc 100644 --- a/sdk/elixir/lib/dagger/gen/interface_type_def.ex +++ b/sdk/elixir/lib/dagger/gen/interface_type_def.ex @@ -1,63 +1,68 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.InterfaceTypeDef do @moduledoc "A definition of a custom interface defined in a Module." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The doc string for the interface, if any." - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = interface_type_def) do - selection = select(interface_type_def.selection, "description") - execute(selection, interface_type_def.client) - end - ) - - ( - @doc "Functions defined on this interface, if any." - @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()} - def functions(%__MODULE__{} = interface_type_def) do - selection = select(interface_type_def.selection, "functions") - selection = select(selection, "args description id name returnType withArg withDescription") - - with {:ok, data} <- execute(selection, interface_type_def.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFunctionFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Function{selection: elem_selection, client: interface_type_def.client} - end)} - end - end - ) - - ( - @doc "A unique identifier for this InterfaceTypeDef." - @spec id(t()) :: {:ok, Dagger.InterfaceTypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = interface_type_def) do - selection = select(interface_type_def.selection, "id") - execute(selection, interface_type_def.client) - end - ) - - ( - @doc "The name of the interface." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = interface_type_def) do - selection = select(interface_type_def.selection, "name") - execute(selection, interface_type_def.client) - end - ) - - ( - @doc "If this InterfaceTypeDef is associated with a Module, the name of the module. Unset otherwise." - @spec source_module_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def source_module_name(%__MODULE__{} = interface_type_def) do - selection = select(interface_type_def.selection, "sourceModuleName") - execute(selection, interface_type_def.client) + @type t() :: %__MODULE__{} + + @doc "The doc string for the interface, if any." + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = interface_type_def) do + selection = + interface_type_def.selection |> select("description") + + execute(selection, interface_type_def.client) + end + + @doc "Functions defined on this interface, if any." + @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()} + def functions(%__MODULE__{} = interface_type_def) do + selection = + interface_type_def.selection |> select("functions") |> select("id") + + with {:ok, items} <- execute(selection, interface_type_def.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Function{ + selection: + query() + |> select("loadFunctionFromID") + |> arg("id", id), + client: interface_type_def.client + } + end} end - ) + end + + @doc "A unique identifier for this InterfaceTypeDef." + @spec id(t()) :: {:ok, Dagger.InterfaceTypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = interface_type_def) do + selection = + interface_type_def.selection |> select("id") + + execute(selection, interface_type_def.client) + end + + @doc "The name of the interface." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = interface_type_def) do + selection = + interface_type_def.selection |> select("name") + + execute(selection, interface_type_def.client) + end + + @doc "If this InterfaceTypeDef is associated with a Module, the name of the module. Unset otherwise." + @spec source_module_name(t()) :: {:ok, String.t()} | {:error, term()} + def source_module_name(%__MODULE__{} = interface_type_def) do + selection = + interface_type_def.selection |> select("sourceModuleName") + + execute(selection, interface_type_def.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/interface_type_def_id.ex b/sdk/elixir/lib/dagger/gen/interface_type_def_id.ex index 87eee71950a..7959e862097 100644 --- a/sdk/elixir/lib/dagger/gen/interface_type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/interface_type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.InterfaceTypeDefID do @moduledoc "The `InterfaceTypeDefID` scalar type represents an identifier for an object of type InterfaceTypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/json.ex b/sdk/elixir/lib/dagger/gen/json.ex index f01891992b2..30c28342a85 100644 --- a/sdk/elixir/lib/dagger/gen/json.ex +++ b/sdk/elixir/lib/dagger/gen/json.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.JSON do @moduledoc "An arbitrary JSON-encoded value." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/label.ex b/sdk/elixir/lib/dagger/gen/label.ex index c964d2e2e07..654648f088b 100644 --- a/sdk/elixir/lib/dagger/gen/label.ex +++ b/sdk/elixir/lib/dagger/gen/label.ex @@ -1,34 +1,39 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Label do @moduledoc "A simple key value object that represents a label." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this Label." - @spec id(t()) :: {:ok, Dagger.LabelID.t()} | {:error, term()} - def id(%__MODULE__{} = label) do - selection = select(label.selection, "id") - execute(selection, label.client) - end - ) - - ( - @doc "The label name." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = label) do - selection = select(label.selection, "name") - execute(selection, label.client) - end - ) - - ( - @doc "The label value." - @spec value(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def value(%__MODULE__{} = label) do - selection = select(label.selection, "value") - execute(selection, label.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this Label." + @spec id(t()) :: {:ok, Dagger.LabelID.t()} | {:error, term()} + def id(%__MODULE__{} = label) do + selection = + label.selection |> select("id") + + execute(selection, label.client) + end + + @doc "The label name." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = label) do + selection = + label.selection |> select("name") + + execute(selection, label.client) + end + + @doc "The label value." + @spec value(t()) :: {:ok, String.t()} | {:error, term()} + def value(%__MODULE__{} = label) do + selection = + label.selection |> select("value") + + execute(selection, label.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/label_id.ex b/sdk/elixir/lib/dagger/gen/label_id.ex index 462cbafeccf..c115d303a56 100644 --- a/sdk/elixir/lib/dagger/gen/label_id.ex +++ b/sdk/elixir/lib/dagger/gen/label_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.LabelID do @moduledoc "The `LabelID` scalar type represents an identifier for an object of type Label." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/list_type_def.ex b/sdk/elixir/lib/dagger/gen/list_type_def.ex index f928a051d06..6e93b0ff4f4 100644 --- a/sdk/elixir/lib/dagger/gen/list_type_def.ex +++ b/sdk/elixir/lib/dagger/gen/list_type_def.ex @@ -1,25 +1,33 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ListTypeDef do @moduledoc "A definition of a list type in a Module." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The type of the elements in the list." - @spec element_type_def(t()) :: Dagger.TypeDef.t() - def element_type_def(%__MODULE__{} = list_type_def) do - selection = select(list_type_def.selection, "elementTypeDef") - %Dagger.TypeDef{selection: selection, client: list_type_def.client} - end - ) - - ( - @doc "A unique identifier for this ListTypeDef." - @spec id(t()) :: {:ok, Dagger.ListTypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = list_type_def) do - selection = select(list_type_def.selection, "id") - execute(selection, list_type_def.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "The type of the elements in the list." + @spec element_type_def(t()) :: Dagger.TypeDef.t() + def element_type_def(%__MODULE__{} = list_type_def) do + selection = + list_type_def.selection |> select("elementTypeDef") + + %Dagger.TypeDef{ + selection: selection, + client: list_type_def.client + } + end + + @doc "A unique identifier for this ListTypeDef." + @spec id(t()) :: {:ok, Dagger.ListTypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = list_type_def) do + selection = + list_type_def.selection |> select("id") + + execute(selection, list_type_def.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/list_type_def_id.ex b/sdk/elixir/lib/dagger/gen/list_type_def_id.ex index 4e7873bf0c4..cd5b3bb721c 100644 --- a/sdk/elixir/lib/dagger/gen/list_type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/list_type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ListTypeDefID do @moduledoc "The `ListTypeDefID` scalar type represents an identifier for an object of type ListTypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/local_module_ref.ex b/sdk/elixir/lib/dagger/gen/local_module_ref.ex deleted file mode 100644 index e84d0229825..00000000000 --- a/sdk/elixir/lib/dagger/gen/local_module_ref.ex +++ /dev/null @@ -1,25 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.LocalModuleRef do - @moduledoc "A reference to a module loaded from a path locally relative to a directory." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "A unique identifier for this LocalModuleRef." - @spec id(t()) :: {:ok, Dagger.LocalModuleRefID.t()} | {:error, term()} - def id(%__MODULE__{} = local_module_ref) do - selection = select(local_module_ref.selection, "id") - execute(selection, local_module_ref.client) - end - ) - - ( - @doc "" - @spec module_source_path(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def module_source_path(%__MODULE__{} = local_module_ref) do - selection = select(local_module_ref.selection, "moduleSourcePath") - execute(selection, local_module_ref.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/local_module_ref_id.ex b/sdk/elixir/lib/dagger/gen/local_module_ref_id.ex deleted file mode 100644 index 37378f713e5..00000000000 --- a/sdk/elixir/lib/dagger/gen/local_module_ref_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.LocalModuleRefID do - @moduledoc "The `LocalModuleRefID` scalar type represents an identifier for an object of type LocalModuleRef." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/local_module_source.ex b/sdk/elixir/lib/dagger/gen/local_module_source.ex index 5fab6bc0019..78264e0e92c 100644 --- a/sdk/elixir/lib/dagger/gen/local_module_source.ex +++ b/sdk/elixir/lib/dagger/gen/local_module_source.ex @@ -1,34 +1,42 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.LocalModuleSource do @moduledoc "Module source that that originates from a path locally relative to an arbitrary directory." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The directory containing everything needed to load load and use the module." - @spec context_directory(t()) :: Dagger.Directory.t() - def context_directory(%__MODULE__{} = local_module_source) do - selection = select(local_module_source.selection, "contextDirectory") - %Dagger.Directory{selection: selection, client: local_module_source.client} - end - ) - - ( - @doc "A unique identifier for this LocalModuleSource." - @spec id(t()) :: {:ok, Dagger.LocalModuleSourceID.t()} | {:error, term()} - def id(%__MODULE__{} = local_module_source) do - selection = select(local_module_source.selection, "id") - execute(selection, local_module_source.client) - end - ) - - ( - @doc "The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory)." - @spec root_subpath(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def root_subpath(%__MODULE__{} = local_module_source) do - selection = select(local_module_source.selection, "rootSubpath") - execute(selection, local_module_source.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "The directory containing everything needed to load load and use the module." + @spec context_directory(t()) :: Dagger.Directory.t() + def context_directory(%__MODULE__{} = local_module_source) do + selection = + local_module_source.selection |> select("contextDirectory") + + %Dagger.Directory{ + selection: selection, + client: local_module_source.client + } + end + + @doc "A unique identifier for this LocalModuleSource." + @spec id(t()) :: {:ok, Dagger.LocalModuleSourceID.t()} | {:error, term()} + def id(%__MODULE__{} = local_module_source) do + selection = + local_module_source.selection |> select("id") + + execute(selection, local_module_source.client) + end + + @doc "The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory)." + @spec root_subpath(t()) :: {:ok, String.t()} | {:error, term()} + def root_subpath(%__MODULE__{} = local_module_source) do + selection = + local_module_source.selection |> select("rootSubpath") + + execute(selection, local_module_source.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/local_module_source_id.ex b/sdk/elixir/lib/dagger/gen/local_module_source_id.ex index 6c0d4a088f3..910ca26ece8 100644 --- a/sdk/elixir/lib/dagger/gen/local_module_source_id.ex +++ b/sdk/elixir/lib/dagger/gen/local_module_source_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.LocalModuleSourceID do @moduledoc "The `LocalModuleSourceID` scalar type represents an identifier for an object of type LocalModuleSource." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/module.ex b/sdk/elixir/lib/dagger/gen/module.ex index e3b9b1b8366..b8201354411 100644 --- a/sdk/elixir/lib/dagger/gen/module.ex +++ b/sdk/elixir/lib/dagger/gen/module.ex @@ -1,242 +1,249 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Module do @moduledoc "A Dagger module." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "Modules used by this module." - @spec dependencies(t()) :: {:ok, [Dagger.Module.t()]} | {:error, term()} - def dependencies(%__MODULE__{} = module) do - selection = select(module.selection, "dependencies") - - selection = - select( - selection, - "dependencies dependencyConfig description generatedContextDiff generatedContextDirectory id initialize interfaces name objects runtime sdk serve source withDescription withInterface withObject withSource" - ) - - with {:ok, data} <- execute(selection, module.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadModuleFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Module{selection: elem_selection, client: module.client} - end)} - end - end - ) - - ( - @doc "The dependencies as configured by the module." - @spec dependency_config(t()) :: {:ok, [Dagger.ModuleDependency.t()]} | {:error, term()} - def dependency_config(%__MODULE__{} = module) do - selection = select(module.selection, "dependencyConfig") - selection = select(selection, "id name source") - - with {:ok, data} <- execute(selection, module.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadModuleDependencyFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.ModuleDependency{selection: elem_selection, client: module.client} - end)} - end - end - ) - - ( - @doc "The doc string of the module, if any" - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = module) do - selection = select(module.selection, "description") - execute(selection, module.client) - end - ) - - ( - @doc "The generated files and directories made on top of the module source's context directory." - @spec generated_context_diff(t()) :: Dagger.Directory.t() - def generated_context_diff(%__MODULE__{} = module) do - selection = select(module.selection, "generatedContextDiff") - %Dagger.Directory{selection: selection, client: module.client} - end - ) - - ( - @doc "The module source's context plus any configuration and source files created by codegen." - @spec generated_context_directory(t()) :: Dagger.Directory.t() - def generated_context_directory(%__MODULE__{} = module) do - selection = select(module.selection, "generatedContextDirectory") - %Dagger.Directory{selection: selection, client: module.client} - end - ) - - ( - @doc "A unique identifier for this Module." - @spec id(t()) :: {:ok, Dagger.ModuleID.t()} | {:error, term()} - def id(%__MODULE__{} = module) do - selection = select(module.selection, "id") - execute(selection, module.client) - end - ) - - ( - @doc "Retrieves the module with the objects loaded via its SDK." - @spec initialize(t()) :: Dagger.Module.t() - def initialize(%__MODULE__{} = module) do - selection = select(module.selection, "initialize") - %Dagger.Module{selection: selection, client: module.client} - end - ) - - ( - @doc "Interfaces served by this module." - @spec interfaces(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} - def interfaces(%__MODULE__{} = module) do - selection = select(module.selection, "interfaces") - - selection = - select( - selection, - "asInput asInterface asList asObject id kind optional withConstructor withField withFunction withInterface withKind withListOf withObject withOptional" - ) - - with {:ok, data} <- execute(selection, module.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadTypeDefFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.TypeDef{selection: elem_selection, client: module.client} - end)} - end - end - ) - - ( - @doc "The name of the module" - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = module) do - selection = select(module.selection, "name") - execute(selection, module.client) - end - ) - - ( - @doc "Objects served by this module." - @spec objects(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} - def objects(%__MODULE__{} = module) do - selection = select(module.selection, "objects") - - selection = - select( - selection, - "asInput asInterface asList asObject id kind optional withConstructor withField withFunction withInterface withKind withListOf withObject withOptional" - ) - - with {:ok, data} <- execute(selection, module.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadTypeDefFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.TypeDef{selection: elem_selection, client: module.client} - end)} - end - end - ) - - ( - @doc "The container that runs the module's entrypoint. It will fail to execute if the module doesn't compile." - @spec runtime(t()) :: Dagger.Container.t() - def runtime(%__MODULE__{} = module) do - selection = select(module.selection, "runtime") - %Dagger.Container{selection: selection, client: module.client} - end - ) - - ( - @doc "The SDK used by this module. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation." - @spec sdk(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def sdk(%__MODULE__{} = module) do - selection = select(module.selection, "sdk") - execute(selection, module.client) - end - ) - - ( - @doc "Serve a module's API in the current session.\n\nNote: this can only be called once per session. In the future, it could return a stream or service to remove the side effect." - @spec serve(t()) :: {:ok, Dagger.Void.t() | nil} | {:error, term()} - def serve(%__MODULE__{} = module) do - selection = select(module.selection, "serve") - execute(selection, module.client) - end - ) - - ( - @doc "The source for the module." - @spec source(t()) :: Dagger.ModuleSource.t() - def source(%__MODULE__{} = module) do - selection = select(module.selection, "source") - %Dagger.ModuleSource{selection: selection, client: module.client} - end - ) - - ( - @doc "Retrieves the module with the given description\n\n## Required Arguments\n\n* `description` - The description to set" - @spec with_description(t(), Dagger.String.t()) :: Dagger.Module.t() - def with_description(%__MODULE__{} = module, description) do - selection = select(module.selection, "withDescription") - selection = arg(selection, "description", description) - %Dagger.Module{selection: selection, client: module.client} - end - ) - - ( - @doc "This module plus the given Interface type and associated functions\n\n## Required Arguments\n\n* `iface` -" - @spec with_interface(t(), Dagger.TypeDef.t()) :: Dagger.Module.t() - def with_interface(%__MODULE__{} = module, iface) do - selection = select(module.selection, "withInterface") - ( - {:ok, id} = Dagger.TypeDef.id(iface) - selection = arg(selection, "iface", id) - ) + use Dagger.Core.QueryBuilder - %Dagger.Module{selection: selection, client: module.client} - end - ) + @derive Dagger.ID - ( - @doc "This module plus the given Object type and associated functions.\n\n## Required Arguments\n\n* `object` -" - @spec with_object(t(), Dagger.TypeDef.t()) :: Dagger.Module.t() - def with_object(%__MODULE__{} = module, object) do - selection = select(module.selection, "withObject") + defstruct [:selection, :client] - ( - {:ok, id} = Dagger.TypeDef.id(object) - selection = arg(selection, "object", id) - ) + @type t() :: %__MODULE__{} - %Dagger.Module{selection: selection, client: module.client} - end - ) - - ( - @doc "Retrieves the module with basic configuration loaded if present.\n\n## Required Arguments\n\n* `source` - The module source to initialize from." - @spec with_source(t(), Dagger.ModuleSource.t()) :: Dagger.Module.t() - def with_source(%__MODULE__{} = module, source) do - selection = select(module.selection, "withSource") - selection = arg(selection, "source", source) - %Dagger.Module{selection: selection, client: module.client} - end - ) + @doc "Modules used by this module." + @spec dependencies(t()) :: {:ok, [Dagger.Module.t()]} | {:error, term()} + def dependencies(%__MODULE__{} = module) do + selection = + module.selection |> select("dependencies") |> select("id") + + with {:ok, items} <- execute(selection, module.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Module{ + selection: + query() + |> select("loadModuleFromID") + |> arg("id", id), + client: module.client + } + end} + end + end + + @doc "The dependencies as configured by the module." + @spec dependency_config(t()) :: {:ok, [Dagger.ModuleDependency.t()]} | {:error, term()} + def dependency_config(%__MODULE__{} = module) do + selection = + module.selection |> select("dependencyConfig") |> select("id") + + with {:ok, items} <- execute(selection, module.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.ModuleDependency{ + selection: + query() + |> select("loadModuleDependencyFromID") + |> arg("id", id), + client: module.client + } + end} + end + end + + @doc "The doc string of the module, if any" + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = module) do + selection = + module.selection |> select("description") + + execute(selection, module.client) + end + + @doc "The generated files and directories made on top of the module source's context directory." + @spec generated_context_diff(t()) :: Dagger.Directory.t() + def generated_context_diff(%__MODULE__{} = module) do + selection = + module.selection |> select("generatedContextDiff") + + %Dagger.Directory{ + selection: selection, + client: module.client + } + end + + @doc "The module source's context plus any configuration and source files created by codegen." + @spec generated_context_directory(t()) :: Dagger.Directory.t() + def generated_context_directory(%__MODULE__{} = module) do + selection = + module.selection |> select("generatedContextDirectory") + + %Dagger.Directory{ + selection: selection, + client: module.client + } + end + + @doc "A unique identifier for this Module." + @spec id(t()) :: {:ok, Dagger.ModuleID.t()} | {:error, term()} + def id(%__MODULE__{} = module) do + selection = + module.selection |> select("id") + + execute(selection, module.client) + end + + @doc "Retrieves the module with the objects loaded via its SDK." + @spec initialize(t()) :: Dagger.Module.t() + def initialize(%__MODULE__{} = module) do + selection = + module.selection |> select("initialize") + + %Dagger.Module{ + selection: selection, + client: module.client + } + end + + @doc "Interfaces served by this module." + @spec interfaces(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} + def interfaces(%__MODULE__{} = module) do + selection = + module.selection |> select("interfaces") |> select("id") + + with {:ok, items} <- execute(selection, module.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.TypeDef{ + selection: + query() + |> select("loadTypeDefFromID") + |> arg("id", id), + client: module.client + } + end} + end + end + + @doc "The name of the module" + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = module) do + selection = + module.selection |> select("name") + + execute(selection, module.client) + end + + @doc "Objects served by this module." + @spec objects(t()) :: {:ok, [Dagger.TypeDef.t()]} | {:error, term()} + def objects(%__MODULE__{} = module) do + selection = + module.selection |> select("objects") |> select("id") + + with {:ok, items} <- execute(selection, module.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.TypeDef{ + selection: + query() + |> select("loadTypeDefFromID") + |> arg("id", id), + client: module.client + } + end} + end + end + + @doc "The container that runs the module's entrypoint. It will fail to execute if the module doesn't compile." + @spec runtime(t()) :: Dagger.Container.t() + def runtime(%__MODULE__{} = module) do + selection = + module.selection |> select("runtime") + + %Dagger.Container{ + selection: selection, + client: module.client + } + end + + @doc "The SDK used by this module. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation." + @spec sdk(t()) :: {:ok, String.t()} | {:error, term()} + def sdk(%__MODULE__{} = module) do + selection = + module.selection |> select("sdk") + + execute(selection, module.client) + end + + @doc """ + Serve a module's API in the current session. + + Note: this can only be called once per session. In the future, it could return a stream or service to remove the side effect. + """ + @spec serve(t()) :: {:ok, Dagger.Void.t() | nil} | {:error, term()} + def serve(%__MODULE__{} = module) do + selection = + module.selection |> select("serve") + + execute(selection, module.client) + end + + @doc "The source for the module." + @spec source(t()) :: Dagger.ModuleSource.t() + def source(%__MODULE__{} = module) do + selection = + module.selection |> select("source") + + %Dagger.ModuleSource{ + selection: selection, + client: module.client + } + end + + @doc "Retrieves the module with the given description" + @spec with_description(t(), String.t()) :: Dagger.Module.t() + def with_description(%__MODULE__{} = module, description) do + selection = + module.selection |> select("withDescription") |> put_arg("description", description) + + %Dagger.Module{ + selection: selection, + client: module.client + } + end + + @doc "This module plus the given Interface type and associated functions" + @spec with_interface(t(), Dagger.TypeDef.t()) :: Dagger.Module.t() + def with_interface(%__MODULE__{} = module, iface) do + selection = + module.selection |> select("withInterface") |> put_arg("iface", Dagger.ID.id!(iface)) + + %Dagger.Module{ + selection: selection, + client: module.client + } + end + + @doc "This module plus the given Object type and associated functions." + @spec with_object(t(), Dagger.TypeDef.t()) :: Dagger.Module.t() + def with_object(%__MODULE__{} = module, object) do + selection = + module.selection |> select("withObject") |> put_arg("object", Dagger.ID.id!(object)) + + %Dagger.Module{ + selection: selection, + client: module.client + } + end + + @doc "Retrieves the module with basic configuration loaded if present." + @spec with_source(t(), Dagger.ModuleSource.t()) :: Dagger.Module.t() + def with_source(%__MODULE__{} = module, source) do + selection = + module.selection |> select("withSource") |> put_arg("source", Dagger.ID.id!(source)) + + %Dagger.Module{ + selection: selection, + client: module.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/module_config.ex b/sdk/elixir/lib/dagger/gen/module_config.ex deleted file mode 100644 index 128d201e496..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_config.ex +++ /dev/null @@ -1,70 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleConfig do - @moduledoc "Static configuration for a module (e.g. parsed contents of dagger.json)" - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "" - @spec dependencies(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def dependencies(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "dependencies") - execute(selection, module_config.client) - end - ) - - ( - @doc "" - @spec exclude(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def exclude(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "exclude") - execute(selection, module_config.client) - end - ) - - ( - @doc "A unique identifier for this ModuleConfig." - @spec id(t()) :: {:ok, Dagger.ModuleConfigID.t()} | {:error, term()} - def id(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "id") - execute(selection, module_config.client) - end - ) - - ( - @doc "" - @spec include(t()) :: {:ok, [Dagger.String.t()]} | {:error, term()} - def include(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "include") - execute(selection, module_config.client) - end - ) - - ( - @doc "" - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "name") - execute(selection, module_config.client) - end - ) - - ( - @doc "" - @spec root(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def root(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "root") - execute(selection, module_config.client) - end - ) - - ( - @doc "" - @spec sdk(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def sdk(%__MODULE__{} = module_config) do - selection = select(module_config.selection, "sdk") - execute(selection, module_config.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/module_config_id.ex b/sdk/elixir/lib/dagger/gen/module_config_id.ex deleted file mode 100644 index e80f03a94ea..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_config_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleConfigID do - @moduledoc "The `ModuleConfigID` scalar type represents an identifier for an object of type ModuleConfig." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/module_dependency.ex b/sdk/elixir/lib/dagger/gen/module_dependency.ex index 0120df06bdf..dc3dd3142d0 100644 --- a/sdk/elixir/lib/dagger/gen/module_dependency.ex +++ b/sdk/elixir/lib/dagger/gen/module_dependency.ex @@ -1,34 +1,42 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleDependency do @moduledoc "The configuration of dependency of a module." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this ModuleDependency." - @spec id(t()) :: {:ok, Dagger.ModuleDependencyID.t()} | {:error, term()} - def id(%__MODULE__{} = module_dependency) do - selection = select(module_dependency.selection, "id") - execute(selection, module_dependency.client) - end - ) - - ( - @doc "The name of the dependency module." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = module_dependency) do - selection = select(module_dependency.selection, "name") - execute(selection, module_dependency.client) - end - ) - - ( - @doc "The source for the dependency module." - @spec source(t()) :: Dagger.ModuleSource.t() - def source(%__MODULE__{} = module_dependency) do - selection = select(module_dependency.selection, "source") - %Dagger.ModuleSource{selection: selection, client: module_dependency.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this ModuleDependency." + @spec id(t()) :: {:ok, Dagger.ModuleDependencyID.t()} | {:error, term()} + def id(%__MODULE__{} = module_dependency) do + selection = + module_dependency.selection |> select("id") + + execute(selection, module_dependency.client) + end + + @doc "The name of the dependency module." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = module_dependency) do + selection = + module_dependency.selection |> select("name") + + execute(selection, module_dependency.client) + end + + @doc "The source for the dependency module." + @spec source(t()) :: Dagger.ModuleSource.t() + def source(%__MODULE__{} = module_dependency) do + selection = + module_dependency.selection |> select("source") + + %Dagger.ModuleSource{ + selection: selection, + client: module_dependency.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/module_dependency_id.ex b/sdk/elixir/lib/dagger/gen/module_dependency_id.ex index 306332209d6..ce34ecbb490 100644 --- a/sdk/elixir/lib/dagger/gen/module_dependency_id.ex +++ b/sdk/elixir/lib/dagger/gen/module_dependency_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleDependencyID do @moduledoc "The `ModuleDependencyID` scalar type represents an identifier for an object of type ModuleDependency." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/module_environment_variable.ex b/sdk/elixir/lib/dagger/gen/module_environment_variable.ex deleted file mode 100644 index 0d30093e3ac..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_environment_variable.ex +++ /dev/null @@ -1,7 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleEnvironmentVariable do - @moduledoc "ModuleEnvironmentVariable" - @type t() :: %__MODULE__{name: Dagger.String.t(), value: Dagger.String.t() | nil} - @derive Nestru.Decoder - defstruct [:name, :value] -end diff --git a/sdk/elixir/lib/dagger/gen/module_id.ex b/sdk/elixir/lib/dagger/gen/module_id.ex index 2d120e4a656..dba9e150a21 100644 --- a/sdk/elixir/lib/dagger/gen/module_id.ex +++ b/sdk/elixir/lib/dagger/gen/module_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleID do @moduledoc "The `ModuleID` scalar type represents an identifier for an object of type Module." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/module_ref.ex b/sdk/elixir/lib/dagger/gen/module_ref.ex deleted file mode 100644 index 0fc16ef6dd8..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_ref.ex +++ /dev/null @@ -1,80 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleRef do - @moduledoc "A reference to a module." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "" - @spec as_git_ref(t()) :: {:ok, Dagger.GitModuleRef.t() | nil} | {:error, term()} - def as_git_ref(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "asGitRef") - - case execute(selection, module_ref.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.GitModuleRef) - error -> error - end - end - ) - - ( - @doc "" - @spec as_local_ref(t()) :: {:ok, Dagger.LocalModuleRef.t() | nil} | {:error, term()} - def as_local_ref(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "asLocalRef") - - case execute(selection, module_ref.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.LocalModuleRef) - error -> error - end - end - ) - - ( - @doc "Load the ref as a module. If this is a local ref, the parent directory must have been provided during module ref creation" - @spec as_module(t()) :: Dagger.Module.t() - def as_module(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "asModule") - %Dagger.Module{selection: selection, client: module_ref.client} - end - ) - - ( - @doc "String representation of the ref." - @spec as_string(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def as_string(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "asString") - execute(selection, module_ref.client) - end - ) - - ( - @doc "A unique identifier for this ModuleRef." - @spec id(t()) :: {:ok, Dagger.ModuleRefID.t()} | {:error, term()} - def id(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "id") - execute(selection, module_ref.client) - end - ) - - ( - @doc "" - @spec kind(t()) :: {:ok, Dagger.ModuleRefKind.t()} | {:error, term()} - def kind(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "kind") - execute(selection, module_ref.client) - end - ) - - ( - @doc "The path to the module source code dir specified by this ref." - @spec module_source_path(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def module_source_path(%__MODULE__{} = module_ref) do - selection = select(module_ref.selection, "moduleSourcePath") - execute(selection, module_ref.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/module_ref_id.ex b/sdk/elixir/lib/dagger/gen/module_ref_id.ex deleted file mode 100644 index e5fabe2a4f2..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_ref_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleRefID do - @moduledoc "The `ModuleRefID` scalar type represents an identifier for an object of type ModuleRef." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/module_ref_kind.ex b/sdk/elixir/lib/dagger/gen/module_ref_kind.ex deleted file mode 100644 index 6b35b36b32b..00000000000 --- a/sdk/elixir/lib/dagger/gen/module_ref_kind.ex +++ /dev/null @@ -1,20 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ModuleRefKind do - @moduledoc "The kind of module ref." - @type t() :: :GitRef | :LocalRef - ( - @doc "" - @spec git_ref() :: :GitRef - def git_ref() do - :GitRef - end - ) - - ( - @doc "" - @spec local_ref() :: :LocalRef - def local_ref() do - :LocalRef - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/module_source.ex b/sdk/elixir/lib/dagger/gen/module_source.ex index 795e875d9ca..a836917b54e 100644 --- a/sdk/elixir/lib/dagger/gen/module_source.ex +++ b/sdk/elixir/lib/dagger/gen/module_source.ex @@ -1,238 +1,261 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleSource do @moduledoc "The source needed to load and run a module, along with any metadata about the source such as versions/urls/etc." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "If the source is a of kind git, the git source representation of it." - @spec as_git_source(t()) :: {:ok, Dagger.GitModuleSource.t() | nil} | {:error, term()} - def as_git_source(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "asGitSource") - - case execute(selection, module_source.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.GitModuleSource) - error -> error - end - end - ) - - ( - @doc "If the source is of kind local, the local source representation of it." - @spec as_local_source(t()) :: {:ok, Dagger.LocalModuleSource.t() | nil} | {:error, term()} - def as_local_source(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "asLocalSource") - - case execute(selection, module_source.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.LocalModuleSource) - error -> error - end - end - ) - - ( - @doc "Load the source as a module. If this is a local source, the parent directory must have been provided during module source creation" - @spec as_module(t()) :: Dagger.Module.t() - def as_module(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "asModule") - %Dagger.Module{selection: selection, client: module_source.client} - end - ) - - ( - @doc "A human readable ref string representation of this module source." - @spec as_string(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def as_string(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "asString") - execute(selection, module_source.client) - end - ) - - ( - @doc "Returns whether the module source has a configuration file." - @spec config_exists(t()) :: {:ok, Dagger.Boolean.t()} | {:error, term()} - def config_exists(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "configExists") - execute(selection, module_source.client) - end - ) - - ( - @doc "The directory containing everything needed to load load and use the module." - @spec context_directory(t()) :: Dagger.Directory.t() - def context_directory(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "contextDirectory") - %Dagger.Directory{selection: selection, client: module_source.client} - end - ) - - ( - @doc "The dependencies of the module source. Includes dependencies from the configuration and any extras from withDependencies calls." - @spec dependencies(t()) :: {:ok, [Dagger.ModuleDependency.t()]} | {:error, term()} - def dependencies(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "dependencies") - selection = select(selection, "id name source") - - with {:ok, data} <- execute(selection, module_source.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadModuleDependencyFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.ModuleDependency{selection: elem_selection, client: module_source.client} - end)} - end - end - ) - - ( - @doc "The directory containing the module configuration and source code (source code may be in a subdir).\n\n## Required Arguments\n\n* `path` - The path from the source directory to select." - @spec directory(t(), Dagger.String.t()) :: Dagger.Directory.t() - def directory(%__MODULE__{} = module_source, path) do - selection = select(module_source.selection, "directory") - selection = arg(selection, "path", path) - %Dagger.Directory{selection: selection, client: module_source.client} - end - ) - - ( - @doc "A unique identifier for this ModuleSource." - @spec id(t()) :: {:ok, Dagger.ModuleSourceID.t()} | {:error, term()} - def id(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "id") - execute(selection, module_source.client) - end - ) - - ( - @doc "The kind of source (e.g. local, git, etc.)" - @spec kind(t()) :: {:ok, Dagger.ModuleSourceKind.t()} | {:error, term()} - def kind(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "kind") - execute(selection, module_source.client) - end - ) - - ( - @doc "If set, the name of the module this source references, including any overrides at runtime by callers." - @spec module_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def module_name(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "moduleName") - execute(selection, module_source.client) - end - ) - - ( - @doc "The original name of the module this source references, as defined in the module configuration." - @spec module_original_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def module_original_name(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "moduleOriginalName") - execute(selection, module_source.client) - end - ) - - ( - @doc "The path to the module source's context directory on the caller's filesystem. Only valid for local sources." - @spec resolve_context_path_from_caller(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def resolve_context_path_from_caller(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "resolveContextPathFromCaller") - execute(selection, module_source.client) - end - ) - - ( - @doc "Resolve the provided module source arg as a dependency relative to this module source.\n\n## Required Arguments\n\n* `dep` - The dependency module source to resolve." - @spec resolve_dependency(t(), Dagger.ModuleSource.t()) :: Dagger.ModuleSource.t() - def resolve_dependency(%__MODULE__{} = module_source, dep) do - selection = select(module_source.selection, "resolveDependency") - selection = arg(selection, "dep", dep) - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "Load the source from its path on the caller's filesystem, including only needed+configured files and directories. Only valid for local sources." - @spec resolve_from_caller(t()) :: Dagger.ModuleSource.t() - def resolve_from_caller(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "resolveFromCaller") - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "The path relative to context of the root of the module source, which contains dagger.json. It also contains the module implementation source code, but that may or may not being a subdir of this root." - @spec source_root_subpath(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def source_root_subpath(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "sourceRootSubpath") - execute(selection, module_source.client) - end - ) - - ( - @doc "The path relative to context of the module implementation source code." - @spec source_subpath(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def source_subpath(%__MODULE__{} = module_source) do - selection = select(module_source.selection, "sourceSubpath") - execute(selection, module_source.client) - end - ) + @type t() :: %__MODULE__{} - ( - @doc "Update the module source with a new context directory. Only valid for local sources.\n\n## Required Arguments\n\n* `dir` - The directory to set as the context directory." - @spec with_context_directory(t(), Dagger.Directory.t()) :: Dagger.ModuleSource.t() - def with_context_directory(%__MODULE__{} = module_source, dir) do - selection = select(module_source.selection, "withContextDirectory") + @doc "If the source is a of kind git, the git source representation of it." + @spec as_git_source(t()) :: Dagger.GitModuleSource.t() | nil + def as_git_source(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("asGitSource") - ( - {:ok, id} = Dagger.Directory.id(dir) - selection = arg(selection, "dir", id) - ) + %Dagger.GitModuleSource{ + selection: selection, + client: module_source.client + } + end - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "Append the provided dependencies to the module source's dependency list.\n\n## Required Arguments\n\n* `dependencies` - The dependencies to append." - @spec with_dependencies(t(), [Dagger.ModuleDependencyID.t()]) :: Dagger.ModuleSource.t() - def with_dependencies(%__MODULE__{} = module_source, dependencies) do - selection = select(module_source.selection, "withDependencies") - selection = arg(selection, "dependencies", dependencies) - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "Update the module source with a new name.\n\n## Required Arguments\n\n* `name` - The name to set." - @spec with_name(t(), Dagger.String.t()) :: Dagger.ModuleSource.t() - def with_name(%__MODULE__{} = module_source, name) do - selection = select(module_source.selection, "withName") - selection = arg(selection, "name", name) - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "Update the module source with a new SDK.\n\n## Required Arguments\n\n* `sdk` - The SDK to set." - @spec with_sdk(t(), Dagger.String.t()) :: Dagger.ModuleSource.t() - def with_sdk(%__MODULE__{} = module_source, sdk) do - selection = select(module_source.selection, "withSDK") - selection = arg(selection, "sdk", sdk) - %Dagger.ModuleSource{selection: selection, client: module_source.client} - end - ) - - ( - @doc "Update the module source with a new source subpath.\n\n## Required Arguments\n\n* `path` - The path to set as the source subpath." - @spec with_source_subpath(t(), Dagger.String.t()) :: Dagger.ModuleSource.t() - def with_source_subpath(%__MODULE__{} = module_source, path) do - selection = select(module_source.selection, "withSourceSubpath") - selection = arg(selection, "path", path) - %Dagger.ModuleSource{selection: selection, client: module_source.client} + @doc "If the source is of kind local, the local source representation of it." + @spec as_local_source(t()) :: Dagger.LocalModuleSource.t() | nil + def as_local_source(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("asLocalSource") + + %Dagger.LocalModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Load the source as a module. If this is a local source, the parent directory must have been provided during module source creation" + @spec as_module(t()) :: Dagger.Module.t() + def as_module(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("asModule") + + %Dagger.Module{ + selection: selection, + client: module_source.client + } + end + + @doc "A human readable ref string representation of this module source." + @spec as_string(t()) :: {:ok, String.t()} | {:error, term()} + def as_string(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("asString") + + execute(selection, module_source.client) + end + + @doc "Returns whether the module source has a configuration file." + @spec config_exists(t()) :: {:ok, boolean()} | {:error, term()} + def config_exists(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("configExists") + + execute(selection, module_source.client) + end + + @doc "The directory containing everything needed to load load and use the module." + @spec context_directory(t()) :: Dagger.Directory.t() + def context_directory(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("contextDirectory") + + %Dagger.Directory{ + selection: selection, + client: module_source.client + } + end + + @doc "The dependencies of the module source. Includes dependencies from the configuration and any extras from withDependencies calls." + @spec dependencies(t()) :: {:ok, [Dagger.ModuleDependency.t()]} | {:error, term()} + def dependencies(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("dependencies") |> select("id") + + with {:ok, items} <- execute(selection, module_source.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.ModuleDependency{ + selection: + query() + |> select("loadModuleDependencyFromID") + |> arg("id", id), + client: module_source.client + } + end} end - ) + end + + @doc "The directory containing the module configuration and source code (source code may be in a subdir)." + @spec directory(t(), String.t()) :: Dagger.Directory.t() + def directory(%__MODULE__{} = module_source, path) do + selection = + module_source.selection |> select("directory") |> put_arg("path", path) + + %Dagger.Directory{ + selection: selection, + client: module_source.client + } + end + + @doc "A unique identifier for this ModuleSource." + @spec id(t()) :: {:ok, Dagger.ModuleSourceID.t()} | {:error, term()} + def id(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("id") + + execute(selection, module_source.client) + end + + @doc "The kind of source (e.g. local, git, etc.)" + @spec kind(t()) :: Dagger.ModuleSourceKind.t() + def kind(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("kind") + + execute(selection, module_source.client) + end + + @doc "If set, the name of the module this source references, including any overrides at runtime by callers." + @spec module_name(t()) :: {:ok, String.t()} | {:error, term()} + def module_name(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("moduleName") + + execute(selection, module_source.client) + end + + @doc "The original name of the module this source references, as defined in the module configuration." + @spec module_original_name(t()) :: {:ok, String.t()} | {:error, term()} + def module_original_name(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("moduleOriginalName") + + execute(selection, module_source.client) + end + + @doc "The path to the module source's context directory on the caller's filesystem. Only valid for local sources." + @spec resolve_context_path_from_caller(t()) :: {:ok, String.t()} | {:error, term()} + def resolve_context_path_from_caller(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("resolveContextPathFromCaller") + + execute(selection, module_source.client) + end + + @doc "Resolve the provided module source arg as a dependency relative to this module source." + @spec resolve_dependency(t(), Dagger.ModuleSource.t()) :: Dagger.ModuleSource.t() + def resolve_dependency(%__MODULE__{} = module_source, dep) do + selection = + module_source.selection |> select("resolveDependency") |> put_arg("dep", Dagger.ID.id!(dep)) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Load the source from its path on the caller's filesystem, including only needed+configured files and directories. Only valid for local sources." + @spec resolve_from_caller(t()) :: Dagger.ModuleSource.t() + def resolve_from_caller(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("resolveFromCaller") + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "The path relative to context of the root of the module source, which contains dagger.json. It also contains the module implementation source code, but that may or may not being a subdir of this root." + @spec source_root_subpath(t()) :: {:ok, String.t()} | {:error, term()} + def source_root_subpath(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("sourceRootSubpath") + + execute(selection, module_source.client) + end + + @doc "The path relative to context of the module implementation source code." + @spec source_subpath(t()) :: {:ok, String.t()} | {:error, term()} + def source_subpath(%__MODULE__{} = module_source) do + selection = + module_source.selection |> select("sourceSubpath") + + execute(selection, module_source.client) + end + + @doc "Update the module source with a new context directory. Only valid for local sources." + @spec with_context_directory(t(), Dagger.Directory.t()) :: Dagger.ModuleSource.t() + def with_context_directory(%__MODULE__{} = module_source, dir) do + selection = + module_source.selection + |> select("withContextDirectory") + |> put_arg("dir", Dagger.ID.id!(dir)) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Append the provided dependencies to the module source's dependency list." + @spec with_dependencies(t(), [Dagger.ModuleDependencyID.t()]) :: Dagger.ModuleSource.t() + def with_dependencies(%__MODULE__{} = module_source, dependencies) do + selection = + module_source.selection + |> select("withDependencies") + |> put_arg("dependencies", dependencies) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Update the module source with a new name." + @spec with_name(t(), String.t()) :: Dagger.ModuleSource.t() + def with_name(%__MODULE__{} = module_source, name) do + selection = + module_source.selection |> select("withName") |> put_arg("name", name) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Update the module source with a new SDK." + @spec with_sdk(t(), String.t()) :: Dagger.ModuleSource.t() + def with_sdk(%__MODULE__{} = module_source, sdk) do + selection = + module_source.selection |> select("withSDK") |> put_arg("sdk", sdk) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end + + @doc "Update the module source with a new source subpath." + @spec with_source_subpath(t(), String.t()) :: Dagger.ModuleSource.t() + def with_source_subpath(%__MODULE__{} = module_source, path) do + selection = + module_source.selection |> select("withSourceSubpath") |> put_arg("path", path) + + %Dagger.ModuleSource{ + selection: selection, + client: module_source.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/module_source_id.ex b/sdk/elixir/lib/dagger/gen/module_source_id.ex index d4ffa38ba6c..84abe33785a 100644 --- a/sdk/elixir/lib/dagger/gen/module_source_id.ex +++ b/sdk/elixir/lib/dagger/gen/module_source_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleSourceID do @moduledoc "The `ModuleSourceID` scalar type represents an identifier for an object of type ModuleSource." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/module_source_kind.ex b/sdk/elixir/lib/dagger/gen/module_source_kind.ex index dae71dc30ce..36fe05c7cf6 100644 --- a/sdk/elixir/lib/dagger/gen/module_source_kind.ex +++ b/sdk/elixir/lib/dagger/gen/module_source_kind.ex @@ -1,20 +1,12 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ModuleSourceKind do @moduledoc "The kind of module source." - @type t() :: :GIT_SOURCE | :LOCAL_SOURCE - ( - @doc "" - @spec git_source() :: :GIT_SOURCE - def git_source() do - :GIT_SOURCE - end - ) - ( - @doc "" - @spec local_source() :: :LOCAL_SOURCE - def local_source() do - :LOCAL_SOURCE - end - ) + @type t() :: :LOCAL_SOURCE | :GIT_SOURCE + + @spec local_source() :: :LOCAL_SOURCE + def local_source(), do: :LOCAL_SOURCE + + @spec git_source() :: :GIT_SOURCE + def git_source(), do: :GIT_SOURCE end diff --git a/sdk/elixir/lib/dagger/gen/network_protocol.ex b/sdk/elixir/lib/dagger/gen/network_protocol.ex index 934ea2033a0..ba211e2f30f 100644 --- a/sdk/elixir/lib/dagger/gen/network_protocol.ex +++ b/sdk/elixir/lib/dagger/gen/network_protocol.ex @@ -1,20 +1,12 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.NetworkProtocol do @moduledoc "Transport layer network protocol associated to a port." + @type t() :: :TCP | :UDP - ( - @doc "" - @spec tcp() :: :TCP - def tcp() do - :TCP - end - ) - ( - @doc "" - @spec udp() :: :UDP - def udp() do - :UDP - end - ) + @spec tcp() :: :TCP + def tcp(), do: :TCP + + @spec udp() :: :UDP + def udp(), do: :UDP end diff --git a/sdk/elixir/lib/dagger/gen/object_type_def.ex b/sdk/elixir/lib/dagger/gen/object_type_def.ex index da753cfe87d..68cd1f258a5 100644 --- a/sdk/elixir/lib/dagger/gen/object_type_def.ex +++ b/sdk/elixir/lib/dagger/gen/object_type_def.ex @@ -1,97 +1,100 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ObjectTypeDef do @moduledoc "A definition of a custom object defined in a Module." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The function used to construct new instances of this object, if any" - @spec constructor(t()) :: {:ok, Dagger.Function.t() | nil} | {:error, term()} - def constructor(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "constructor") - - case execute(selection, object_type_def.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.Function) - error -> error - end - end - ) - - ( - @doc "The doc string for the object, if any." - @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def description(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "description") - execute(selection, object_type_def.client) - end - ) - - ( - @doc "Static fields defined on this object, if any." - @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()} - def fields(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "fields") - selection = select(selection, "description id name typeDef") - - with {:ok, data} <- execute(selection, object_type_def.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFieldTypeDefFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.FieldTypeDef{selection: elem_selection, client: object_type_def.client} - end)} - end - end - ) - - ( - @doc "Functions defined on this object, if any." - @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()} - def functions(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "functions") - selection = select(selection, "args description id name returnType withArg withDescription") - - with {:ok, data} <- execute(selection, object_type_def.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadFunctionFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Function{selection: elem_selection, client: object_type_def.client} - end)} - end - end - ) - - ( - @doc "A unique identifier for this ObjectTypeDef." - @spec id(t()) :: {:ok, Dagger.ObjectTypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "id") - execute(selection, object_type_def.client) - end - ) - - ( - @doc "The name of the object." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "name") - execute(selection, object_type_def.client) + @type t() :: %__MODULE__{} + + @doc "The function used to construct new instances of this object, if any" + @spec constructor(t()) :: Dagger.Function.t() | nil + def constructor(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("constructor") + + %Dagger.Function{ + selection: selection, + client: object_type_def.client + } + end + + @doc "The doc string for the object, if any." + @spec description(t()) :: {:ok, String.t()} | {:error, term()} + def description(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("description") + + execute(selection, object_type_def.client) + end + + @doc "Static fields defined on this object, if any." + @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()} + def fields(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("fields") |> select("id") + + with {:ok, items} <- execute(selection, object_type_def.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.FieldTypeDef{ + selection: + query() + |> select("loadFieldTypeDefFromID") + |> arg("id", id), + client: object_type_def.client + } + end} end - ) - - ( - @doc "If this ObjectTypeDef is associated with a Module, the name of the module. Unset otherwise." - @spec source_module_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def source_module_name(%__MODULE__{} = object_type_def) do - selection = select(object_type_def.selection, "sourceModuleName") - execute(selection, object_type_def.client) + end + + @doc "Functions defined on this object, if any." + @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()} + def functions(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("functions") |> select("id") + + with {:ok, items} <- execute(selection, object_type_def.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Function{ + selection: + query() + |> select("loadFunctionFromID") + |> arg("id", id), + client: object_type_def.client + } + end} end - ) + end + + @doc "A unique identifier for this ObjectTypeDef." + @spec id(t()) :: {:ok, Dagger.ObjectTypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("id") + + execute(selection, object_type_def.client) + end + + @doc "The name of the object." + @spec name(t()) :: {:ok, String.t()} | {:error, term()} + def name(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("name") + + execute(selection, object_type_def.client) + end + + @doc "If this ObjectTypeDef is associated with a Module, the name of the module. Unset otherwise." + @spec source_module_name(t()) :: {:ok, String.t()} | {:error, term()} + def source_module_name(%__MODULE__{} = object_type_def) do + selection = + object_type_def.selection |> select("sourceModuleName") + + execute(selection, object_type_def.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/object_type_def_id.ex b/sdk/elixir/lib/dagger/gen/object_type_def_id.ex index 355856f9caf..1ad1a7f3f07 100644 --- a/sdk/elixir/lib/dagger/gen/object_type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/object_type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ObjectTypeDefID do @moduledoc "The `ObjectTypeDefID` scalar type represents an identifier for an object of type ObjectTypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/pipeline_label.ex b/sdk/elixir/lib/dagger/gen/pipeline_label.ex index 8fdf519926b..fe86ed15501 100644 --- a/sdk/elixir/lib/dagger/gen/pipeline_label.ex +++ b/sdk/elixir/lib/dagger/gen/pipeline_label.ex @@ -1,7 +1,11 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.PipelineLabel do @moduledoc "Key value object that represents a pipeline label." - @type t() :: %__MODULE__{name: Dagger.String.t(), value: Dagger.String.t()} - @derive Nestru.Decoder + + @type t() :: %__MODULE__{ + name: String.t(), + value: String.t() + } + defstruct [:name, :value] end diff --git a/sdk/elixir/lib/dagger/gen/platform.ex b/sdk/elixir/lib/dagger/gen/platform.ex index 8d3612c6ff9..9e55a4c2006 100644 --- a/sdk/elixir/lib/dagger/gen/platform.ex +++ b/sdk/elixir/lib/dagger/gen/platform.ex @@ -1,5 +1,10 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Platform do - @moduledoc "The platform config OS and architecture in a Container.\n\nThe format is [os]/[platform]/[version] (e.g., \"darwin/arm64/v7\", \"windows/amd64\", \"linux/arm64\")." + @moduledoc """ + The platform config OS and architecture in a Container. + + The format is [os]/[platform]/[version] (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64"). + """ + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/port.ex b/sdk/elixir/lib/dagger/gen/port.ex index 51e546fffc0..929a4c9286f 100644 --- a/sdk/elixir/lib/dagger/gen/port.ex +++ b/sdk/elixir/lib/dagger/gen/port.ex @@ -1,52 +1,57 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Port do @moduledoc "A port exposed by a container." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "The port description." - @spec description(t()) :: {:ok, Dagger.String.t() | nil} | {:error, term()} - def description(%__MODULE__{} = port) do - selection = select(port.selection, "description") - execute(selection, port.client) - end - ) - - ( - @doc "Skip the health check when run as a service." - @spec experimental_skip_healthcheck(t()) :: {:ok, Dagger.Boolean.t()} | {:error, term()} - def experimental_skip_healthcheck(%__MODULE__{} = port) do - selection = select(port.selection, "experimentalSkipHealthcheck") - execute(selection, port.client) - end - ) - - ( - @doc "A unique identifier for this Port." - @spec id(t()) :: {:ok, Dagger.PortID.t()} | {:error, term()} - def id(%__MODULE__{} = port) do - selection = select(port.selection, "id") - execute(selection, port.client) - end - ) - - ( - @doc "The port number." - @spec port(t()) :: {:ok, Dagger.Int.t()} | {:error, term()} - def port(%__MODULE__{} = port) do - selection = select(port.selection, "port") - execute(selection, port.client) - end - ) - - ( - @doc "The transport layer protocol." - @spec protocol(t()) :: {:ok, Dagger.NetworkProtocol.t()} | {:error, term()} - def protocol(%__MODULE__{} = port) do - selection = select(port.selection, "protocol") - execute(selection, port.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "The port description." + @spec description(t()) :: {:ok, String.t() | nil} | {:error, term()} + def description(%__MODULE__{} = port) do + selection = + port.selection |> select("description") + + execute(selection, port.client) + end + + @doc "Skip the health check when run as a service." + @spec experimental_skip_healthcheck(t()) :: {:ok, boolean()} | {:error, term()} + def experimental_skip_healthcheck(%__MODULE__{} = port) do + selection = + port.selection |> select("experimentalSkipHealthcheck") + + execute(selection, port.client) + end + + @doc "A unique identifier for this Port." + @spec id(t()) :: {:ok, Dagger.PortID.t()} | {:error, term()} + def id(%__MODULE__{} = port) do + selection = + port.selection |> select("id") + + execute(selection, port.client) + end + + @doc "The port number." + @spec port(t()) :: {:ok, integer()} | {:error, term()} + def port(%__MODULE__{} = port) do + selection = + port.selection |> select("port") + + execute(selection, port.client) + end + + @doc "The transport layer protocol." + @spec protocol(t()) :: Dagger.NetworkProtocol.t() + def protocol(%__MODULE__{} = port) do + selection = + port.selection |> select("protocol") + + execute(selection, port.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/port_forward.ex b/sdk/elixir/lib/dagger/gen/port_forward.ex index 16af7548dbb..8e36144728d 100644 --- a/sdk/elixir/lib/dagger/gen/port_forward.ex +++ b/sdk/elixir/lib/dagger/gen/port_forward.ex @@ -1,11 +1,12 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.PortForward do @moduledoc "Port forwarding rules for tunneling network traffic." + @type t() :: %__MODULE__{ - backend: Dagger.Int.t(), - frontend: Dagger.Int.t() | nil, + backend: integer(), + frontend: integer() | nil, protocol: Dagger.NetworkProtocol.t() | nil } - @derive Nestru.Decoder + defstruct [:backend, :frontend, :protocol] end diff --git a/sdk/elixir/lib/dagger/gen/port_id.ex b/sdk/elixir/lib/dagger/gen/port_id.ex index a47c401f441..a853107d3d5 100644 --- a/sdk/elixir/lib/dagger/gen/port_id.ex +++ b/sdk/elixir/lib/dagger/gen/port_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.PortID do @moduledoc "The `PortID` scalar type represents an identifier for an object of type Port." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/project.ex b/sdk/elixir/lib/dagger/gen/project.ex deleted file mode 100644 index a0a924f028f..00000000000 --- a/sdk/elixir/lib/dagger/gen/project.ex +++ /dev/null @@ -1,50 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.Project do - @moduledoc "A collection of Dagger resources that can be queried and invoked." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "Commands provided by this project" - @spec commands(t()) :: {:ok, [Dagger.ProjectCommand.t()] | nil} | {:error, term()} - def commands(%__MODULE__{} = project) do - selection = select(project.selection, "commands") - execute(selection, project.client) - end - ) - - ( - @doc "A unique identifier for this project." - @spec id(t()) :: {:ok, Dagger.ProjectID.t()} | {:error, term()} - def id(%__MODULE__{} = project) do - selection = select(project.selection, "id") - execute(selection, project.client) - end - ) - - ( - @doc "Initialize this project from the given directory and config path\n\n## Required Arguments\n\n* `source` - \n* `config_path` -" - @spec load(t(), Dagger.Directory.t(), Dagger.String.t()) :: Dagger.Project.t() - def load(%__MODULE__{} = project, source, config_path) do - selection = select(project.selection, "load") - - ( - {:ok, id} = Dagger.Directory.id(source) - selection = arg(selection, "source", id) - ) - - selection = arg(selection, "configPath", config_path) - %Dagger.Project{selection: selection, client: project.client} - end - ) - - ( - @doc "Name of the project" - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = project) do - selection = select(project.selection, "name") - execute(selection, project.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/project_command.ex b/sdk/elixir/lib/dagger/gen/project_command.ex deleted file mode 100644 index 586d45ac37c..00000000000 --- a/sdk/elixir/lib/dagger/gen/project_command.ex +++ /dev/null @@ -1,61 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ProjectCommand do - @moduledoc "A command defined in a project that can be invoked from the CLI." - use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} - defstruct [:selection, :client] - - ( - @doc "Documentation for what this command does." - @spec description(t()) :: {:ok, Dagger.String.t() | nil} | {:error, term()} - def description(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "description") - execute(selection, project_command.client) - end - ) - - ( - @doc "Flags accepted by this command." - @spec flags(t()) :: {:ok, [Dagger.ProjectCommandFlag.t()] | nil} | {:error, term()} - def flags(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "flags") - execute(selection, project_command.client) - end - ) - - ( - @doc "A unique identifier for this command." - @spec id(t()) :: {:ok, Dagger.ProjectCommandID.t()} | {:error, term()} - def id(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "id") - execute(selection, project_command.client) - end - ) - - ( - @doc "The name of the command." - @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def name(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "name") - execute(selection, project_command.client) - end - ) - - ( - @doc "The name of the type returned by this command." - @spec result_type(t()) :: {:ok, Dagger.String.t() | nil} | {:error, term()} - def result_type(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "resultType") - execute(selection, project_command.client) - end - ) - - ( - @doc "Subcommands, if any, that this command provides." - @spec subcommands(t()) :: {:ok, [Dagger.ProjectCommand.t()] | nil} | {:error, term()} - def subcommands(%__MODULE__{} = project_command) do - selection = select(project_command.selection, "subcommands") - execute(selection, project_command.client) - end - ) -end diff --git a/sdk/elixir/lib/dagger/gen/project_command_flag.ex b/sdk/elixir/lib/dagger/gen/project_command_flag.ex deleted file mode 100644 index c577615b716..00000000000 --- a/sdk/elixir/lib/dagger/gen/project_command_flag.ex +++ /dev/null @@ -1,7 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ProjectCommandFlag do - @moduledoc "A flag accepted by a project command." - @type t() :: %__MODULE__{description: Dagger.String.t() | nil, name: Dagger.String.t()} - @derive Nestru.Decoder - defstruct [:description, :name] -end diff --git a/sdk/elixir/lib/dagger/gen/project_command_id.ex b/sdk/elixir/lib/dagger/gen/project_command_id.ex deleted file mode 100644 index 02408a55767..00000000000 --- a/sdk/elixir/lib/dagger/gen/project_command_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ProjectCommandID do - @moduledoc "A unique project command identifier." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/project_id.ex b/sdk/elixir/lib/dagger/gen/project_id.ex deleted file mode 100644 index 1363bca49d5..00000000000 --- a/sdk/elixir/lib/dagger/gen/project_id.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.ProjectID do - @moduledoc "A unique project identifier." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/secret.ex b/sdk/elixir/lib/dagger/gen/secret.ex index b25fb71923e..5a1e1c7b857 100644 --- a/sdk/elixir/lib/dagger/gen/secret.ex +++ b/sdk/elixir/lib/dagger/gen/secret.ex @@ -1,25 +1,30 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Secret do @moduledoc "A reference to a secret value, which can be handled more safely than the value itself." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this Secret." - @spec id(t()) :: {:ok, Dagger.SecretID.t()} | {:error, term()} - def id(%__MODULE__{} = secret) do - selection = select(secret.selection, "id") - execute(selection, secret.client) - end - ) - - ( - @doc "The value of this secret." - @spec plaintext(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def plaintext(%__MODULE__{} = secret) do - selection = select(secret.selection, "plaintext") - execute(selection, secret.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this Secret." + @spec id(t()) :: {:ok, Dagger.SecretID.t()} | {:error, term()} + def id(%__MODULE__{} = secret) do + selection = + secret.selection |> select("id") + + execute(selection, secret.client) + end + + @doc "The value of this secret." + @spec plaintext(t()) :: {:ok, String.t()} | {:error, term()} + def plaintext(%__MODULE__{} = secret) do + selection = + secret.selection |> select("plaintext") + + execute(selection, secret.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/secret_id.ex b/sdk/elixir/lib/dagger/gen/secret_id.ex index 59abfccf99b..256018cecce 100644 --- a/sdk/elixir/lib/dagger/gen/secret_id.ex +++ b/sdk/elixir/lib/dagger/gen/secret_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.SecretID do @moduledoc "The `SecretID` scalar type represents an identifier for an object of type Secret." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/service.ex b/sdk/elixir/lib/dagger/gen/service.ex index da03ee81e53..b51a700c973 100644 --- a/sdk/elixir/lib/dagger/gen/service.ex +++ b/sdk/elixir/lib/dagger/gen/service.ex @@ -1,119 +1,104 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Service do @moduledoc "A content-addressed service providing TCP connectivity." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "Retrieves an endpoint that clients can use to reach this container.\n\nIf no port is specified, the first exposed port is used. If none exist an error is returned.\n\nIf a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned.\n\n\n\n## Optional Arguments\n\n* `port` - The exposed port number for the endpoint\n* `scheme` - Return a URL with the given scheme, eg. http for http://" - @spec endpoint(t(), keyword()) :: {:ok, Dagger.String.t()} | {:error, term()} - def endpoint(%__MODULE__{} = service, optional_args \\ []) do - selection = select(service.selection, "endpoint") - - selection = - if is_nil(optional_args[:port]) do - selection - else - arg(selection, "port", optional_args[:port]) - end - - selection = - if is_nil(optional_args[:scheme]) do - selection - else - arg(selection, "scheme", optional_args[:scheme]) - end - - execute(selection, service.client) - end - ) - - ( - @doc "Retrieves a hostname which can be used by clients to reach this container." - @spec hostname(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def hostname(%__MODULE__{} = service) do - selection = select(service.selection, "hostname") - execute(selection, service.client) - end - ) - - ( - @doc "A unique identifier for this Service." - @spec id(t()) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} - def id(%__MODULE__{} = service) do - selection = select(service.selection, "id") - execute(selection, service.client) - end - ) - - ( - @doc "Retrieves the list of ports provided by the service." - @spec ports(t()) :: {:ok, [Dagger.Port.t()]} | {:error, term()} - def ports(%__MODULE__{} = service) do - selection = select(service.selection, "ports") - selection = select(selection, "description experimentalSkipHealthcheck id port protocol") - - with {:ok, data} <- execute(selection, service.client) do - {:ok, - data - |> Enum.map(fn value -> - elem_selection = Dagger.Core.QueryBuilder.Selection.query() - elem_selection = select(elem_selection, "loadPortFromID") - elem_selection = arg(elem_selection, "id", value["id"]) - %Dagger.Port{selection: elem_selection, client: service.client} - end)} - end - end - ) - - ( - @doc "Start the service and wait for its health checks to succeed.\n\nServices bound to a Container do not need to be manually started." - @spec start(t()) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} - def start(%__MODULE__{} = service) do - selection = select(service.selection, "start") - execute(selection, service.client) - end - ) - - ( - @doc "Stop the service.\n\n\n\n## Optional Arguments\n\n* `kill` - Immediately kill the service without waiting for a graceful exit" - @spec stop(t(), keyword()) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} - def stop(%__MODULE__{} = service, optional_args \\ []) do - selection = select(service.selection, "stop") - - selection = - if is_nil(optional_args[:kill]) do - selection - else - arg(selection, "kill", optional_args[:kill]) - end - - execute(selection, service.client) - end - ) - - ( - @doc "Creates a tunnel that forwards traffic from the caller's network to this service.\n\n\n\n## Optional Arguments\n\n* `ports` - List of frontend/backend port mappings to forward.\n\nFrontend is the port accepting traffic on the host, backend is the service port.\n* `random` - Bind each tunnel port to a random port on the host." - @spec up(t(), keyword()) :: {:ok, Dagger.Void.t() | nil} | {:error, term()} - def up(%__MODULE__{} = service, optional_args \\ []) do - selection = select(service.selection, "up") - - selection = - if is_nil(optional_args[:ports]) do - selection - else - arg(selection, "ports", optional_args[:ports]) - end - - selection = - if is_nil(optional_args[:random]) do - selection - else - arg(selection, "random", optional_args[:random]) - end - - execute(selection, service.client) + @type t() :: %__MODULE__{} + + @doc """ + Retrieves an endpoint that clients can use to reach this container. + + If no port is specified, the first exposed port is used. If none exist an error is returned. + + If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned. + """ + @spec endpoint(t(), [{:port, integer() | nil}, {:scheme, String.t() | nil}]) :: + {:ok, String.t()} | {:error, term()} + def endpoint(%__MODULE__{} = service, optional_args \\ []) do + selection = + service.selection + |> select("endpoint") + |> maybe_put_arg("port", optional_args[:port]) + |> maybe_put_arg("scheme", optional_args[:scheme]) + + execute(selection, service.client) + end + + @doc "Retrieves a hostname which can be used by clients to reach this container." + @spec hostname(t()) :: {:ok, String.t()} | {:error, term()} + def hostname(%__MODULE__{} = service) do + selection = + service.selection |> select("hostname") + + execute(selection, service.client) + end + + @doc "A unique identifier for this Service." + @spec id(t()) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} + def id(%__MODULE__{} = service) do + selection = + service.selection |> select("id") + + execute(selection, service.client) + end + + @doc "Retrieves the list of ports provided by the service." + @spec ports(t()) :: {:ok, [Dagger.Port.t()]} | {:error, term()} + def ports(%__MODULE__{} = service) do + selection = + service.selection |> select("ports") |> select("id") + + with {:ok, items} <- execute(selection, service.client) do + {:ok, + for %{"id" => id} <- items do + %Dagger.Port{ + selection: + query() + |> select("loadPortFromID") + |> arg("id", id), + client: service.client + } + end} end - ) + end + + @doc """ + Start the service and wait for its health checks to succeed. + + Services bound to a Container do not need to be manually started. + """ + @spec start(t()) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} + def start(%__MODULE__{} = service) do + selection = + service.selection |> select("start") + + execute(selection, service.client) + end + + @doc "Stop the service." + @spec stop(t(), [{:kill, boolean() | nil}]) :: {:ok, Dagger.ServiceID.t()} | {:error, term()} + def stop(%__MODULE__{} = service, optional_args \\ []) do + selection = + service.selection |> select("stop") |> maybe_put_arg("kill", optional_args[:kill]) + + execute(selection, service.client) + end + + @doc "Creates a tunnel that forwards traffic from the caller's network to this service." + @spec up(t(), [{:ports, [Dagger.PortForward.t()]}, {:random, boolean() | nil}]) :: + {:ok, Dagger.Void.t() | nil} | {:error, term()} + def up(%__MODULE__{} = service, optional_args \\ []) do + selection = + service.selection + |> select("up") + |> maybe_put_arg("ports", optional_args[:ports]) + |> maybe_put_arg("random", optional_args[:random]) + + execute(selection, service.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/service_id.ex b/sdk/elixir/lib/dagger/gen/service_id.ex index 2c4e1bc0963..d3ce414942f 100644 --- a/sdk/elixir/lib/dagger/gen/service_id.ex +++ b/sdk/elixir/lib/dagger/gen/service_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.ServiceID do @moduledoc "The `ServiceID` scalar type represents an identifier for an object of type Service." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/socket.ex b/sdk/elixir/lib/dagger/gen/socket.ex index bac0e369717..d32691bfa02 100644 --- a/sdk/elixir/lib/dagger/gen/socket.ex +++ b/sdk/elixir/lib/dagger/gen/socket.ex @@ -1,16 +1,21 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Socket do @moduledoc "A Unix or TCP/IP socket that can be mounted into a container." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this Socket." - @spec id(t()) :: {:ok, Dagger.SocketID.t()} | {:error, term()} - def id(%__MODULE__{} = socket) do - selection = select(socket.selection, "id") - execute(selection, socket.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this Socket." + @spec id(t()) :: {:ok, Dagger.SocketID.t()} | {:error, term()} + def id(%__MODULE__{} = socket) do + selection = + socket.selection |> select("id") + + execute(selection, socket.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/socket_id.ex b/sdk/elixir/lib/dagger/gen/socket_id.ex index 09bc410dbb3..1034f4999d0 100644 --- a/sdk/elixir/lib/dagger/gen/socket_id.ex +++ b/sdk/elixir/lib/dagger/gen/socket_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.SocketID do @moduledoc "The `SocketID` scalar type represents an identifier for an object of type Socket." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/string.ex b/sdk/elixir/lib/dagger/gen/string.ex deleted file mode 100644 index 41faae9880f..00000000000 --- a/sdk/elixir/lib/dagger/gen/string.ex +++ /dev/null @@ -1,5 +0,0 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. -defmodule Dagger.String do - @moduledoc "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text." - @type t() :: String.t() -end diff --git a/sdk/elixir/lib/dagger/gen/terminal.ex b/sdk/elixir/lib/dagger/gen/terminal.ex index 7276738ec81..40c2f90ed76 100644 --- a/sdk/elixir/lib/dagger/gen/terminal.ex +++ b/sdk/elixir/lib/dagger/gen/terminal.ex @@ -1,25 +1,30 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Terminal do @moduledoc "An interactive terminal that clients can connect to." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "A unique identifier for this Terminal." - @spec id(t()) :: {:ok, Dagger.TerminalID.t()} | {:error, term()} - def id(%__MODULE__{} = terminal) do - selection = select(terminal.selection, "id") - execute(selection, terminal.client) - end - ) - - ( - @doc "An http endpoint at which this terminal can be connected to over a websocket." - @spec websocket_endpoint(t()) :: {:ok, Dagger.String.t()} | {:error, term()} - def websocket_endpoint(%__MODULE__{} = terminal) do - selection = select(terminal.selection, "websocketEndpoint") - execute(selection, terminal.client) - end - ) + @type t() :: %__MODULE__{} + + @doc "A unique identifier for this Terminal." + @spec id(t()) :: {:ok, Dagger.TerminalID.t()} | {:error, term()} + def id(%__MODULE__{} = terminal) do + selection = + terminal.selection |> select("id") + + execute(selection, terminal.client) + end + + @doc "An http endpoint at which this terminal can be connected to over a websocket." + @spec websocket_endpoint(t()) :: {:ok, String.t()} | {:error, term()} + def websocket_endpoint(%__MODULE__{} = terminal) do + selection = + terminal.selection |> select("websocketEndpoint") + + execute(selection, terminal.client) + end end diff --git a/sdk/elixir/lib/dagger/gen/terminal_id.ex b/sdk/elixir/lib/dagger/gen/terminal_id.ex index 05e6d93fbb9..d0485d63ebc 100644 --- a/sdk/elixir/lib/dagger/gen/terminal_id.ex +++ b/sdk/elixir/lib/dagger/gen/terminal_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.TerminalID do @moduledoc "The `TerminalID` scalar type represents an identifier for an object of type Terminal." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/type_def.ex b/sdk/elixir/lib/dagger/gen/type_def.ex index 4736d06ca05..205b47f3e32 100644 --- a/sdk/elixir/lib/dagger/gen/type_def.ex +++ b/sdk/elixir/lib/dagger/gen/type_def.ex @@ -1,214 +1,202 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.TypeDef do @moduledoc "A definition of a parameter or return type in a Module." + use Dagger.Core.QueryBuilder - @type t() :: %__MODULE__{} + + @derive Dagger.ID + defstruct [:selection, :client] - ( - @doc "If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null." - @spec as_input(t()) :: {:ok, Dagger.InputTypeDef.t() | nil} | {:error, term()} - def as_input(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "asInput") - - case execute(selection, type_def.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.InputTypeDef) - error -> error - end - end - ) - - ( - @doc "If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null." - @spec as_interface(t()) :: {:ok, Dagger.InterfaceTypeDef.t() | nil} | {:error, term()} - def as_interface(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "asInterface") - - case execute(selection, type_def.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.InterfaceTypeDef) - error -> error - end - end - ) - - ( - @doc "If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null." - @spec as_list(t()) :: {:ok, Dagger.ListTypeDef.t() | nil} | {:error, term()} - def as_list(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "asList") - - case execute(selection, type_def.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.ListTypeDef) - error -> error - end - end - ) - - ( - @doc "If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null." - @spec as_object(t()) :: {:ok, Dagger.ObjectTypeDef.t() | nil} | {:error, term()} - def as_object(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "asObject") - - case execute(selection, type_def.client) do - {:ok, nil} -> {:ok, nil} - {:ok, data} -> Nestru.decode_from_map(data, Dagger.ObjectTypeDef) - error -> error - end - end - ) - - ( - @doc "A unique identifier for this TypeDef." - @spec id(t()) :: {:ok, Dagger.TypeDefID.t()} | {:error, term()} - def id(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "id") - execute(selection, type_def.client) - end - ) - - ( - @doc "The kind of type this is (e.g. primitive, list, object)." - @spec kind(t()) :: {:ok, Dagger.TypeDefKind.t()} | {:error, term()} - def kind(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "kind") - execute(selection, type_def.client) - end - ) - - ( - @doc "Whether this type can be set to null. Defaults to false." - @spec optional(t()) :: {:ok, Dagger.Boolean.t()} | {:error, term()} - def optional(%__MODULE__{} = type_def) do - selection = select(type_def.selection, "optional") - execute(selection, type_def.client) - end - ) - - ( - @doc "Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.\n\n## Required Arguments\n\n* `function` -" - @spec with_constructor(t(), Dagger.Function.t()) :: Dagger.TypeDef.t() - def with_constructor(%__MODULE__{} = type_def, function) do - selection = select(type_def.selection, "withConstructor") - - ( - {:ok, id} = Dagger.Function.id(function) - selection = arg(selection, "function", id) - ) - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Adds a static field for an Object TypeDef, failing if the type is not an object.\n\n## Required Arguments\n\n* `name` - The name of the field in the object\n* `type_def` - The type of the field\n\n## Optional Arguments\n\n* `description` - A doc string for the field, if any" - @spec with_field(t(), Dagger.String.t(), Dagger.TypeDef.t(), keyword()) :: Dagger.TypeDef.t() - def with_field(%__MODULE__{} = type_def, name, type_def, optional_args \\ []) do - selection = select(type_def.selection, "withField") - selection = arg(selection, "name", name) - - ( - {:ok, id} = Dagger.TypeDef.id(type_def) - selection = arg(selection, "typeDef", id) - ) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.\n\n## Required Arguments\n\n* `function` -" - @spec with_function(t(), Dagger.Function.t()) :: Dagger.TypeDef.t() - def with_function(%__MODULE__{} = type_def, function) do - selection = select(type_def.selection, "withFunction") - - ( - {:ok, id} = Dagger.Function.id(function) - selection = arg(selection, "function", id) - ) - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Returns a TypeDef of kind Interface with the provided name.\n\n## Required Arguments\n\n* `name` - \n\n## Optional Arguments\n\n* `description` -" - @spec with_interface(t(), Dagger.String.t(), keyword()) :: Dagger.TypeDef.t() - def with_interface(%__MODULE__{} = type_def, name, optional_args \\ []) do - selection = select(type_def.selection, "withInterface") - selection = arg(selection, "name", name) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Sets the kind of the type.\n\n## Required Arguments\n\n* `kind` -" - @spec with_kind(t(), Dagger.TypeDefKind.t()) :: Dagger.TypeDef.t() - def with_kind(%__MODULE__{} = type_def, kind) do - selection = select(type_def.selection, "withKind") - selection = arg(selection, "kind", kind) - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Returns a TypeDef of kind List with the provided type for its elements.\n\n## Required Arguments\n\n* `element_type` -" - @spec with_list_of(t(), Dagger.TypeDef.t()) :: Dagger.TypeDef.t() - def with_list_of(%__MODULE__{} = type_def, element_type) do - selection = select(type_def.selection, "withListOf") - - ( - {:ok, id} = Dagger.TypeDef.id(element_type) - selection = arg(selection, "elementType", id) - ) - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Returns a TypeDef of kind Object with the provided name.\n\nNote 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\n## Required Arguments\n\n* `name` - \n\n## Optional Arguments\n\n* `description` -" - @spec with_object(t(), Dagger.String.t(), keyword()) :: Dagger.TypeDef.t() - def with_object(%__MODULE__{} = type_def, name, optional_args \\ []) do - selection = select(type_def.selection, "withObject") - selection = arg(selection, "name", name) - - selection = - if is_nil(optional_args[:description]) do - selection - else - arg(selection, "description", optional_args[:description]) - end - - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) - - ( - @doc "Sets whether this type can be set to null.\n\n## Required Arguments\n\n* `optional` -" - @spec with_optional(t(), Dagger.Boolean.t()) :: Dagger.TypeDef.t() - def with_optional(%__MODULE__{} = type_def, optional) do - selection = select(type_def.selection, "withOptional") - selection = arg(selection, "optional", optional) - %Dagger.TypeDef{selection: selection, client: type_def.client} - end - ) + @type t() :: %__MODULE__{} + + @doc "If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null." + @spec as_input(t()) :: Dagger.InputTypeDef.t() | nil + def as_input(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("asInput") + + %Dagger.InputTypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null." + @spec as_interface(t()) :: Dagger.InterfaceTypeDef.t() | nil + def as_interface(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("asInterface") + + %Dagger.InterfaceTypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null." + @spec as_list(t()) :: Dagger.ListTypeDef.t() | nil + def as_list(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("asList") + + %Dagger.ListTypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null." + @spec as_object(t()) :: Dagger.ObjectTypeDef.t() | nil + def as_object(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("asObject") + + %Dagger.ObjectTypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "A unique identifier for this TypeDef." + @spec id(t()) :: {:ok, Dagger.TypeDefID.t()} | {:error, term()} + def id(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("id") + + execute(selection, type_def.client) + end + + @doc "The kind of type this is (e.g. primitive, list, object)." + @spec kind(t()) :: Dagger.TypeDefKind.t() + def kind(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("kind") + + execute(selection, type_def.client) + end + + @doc "Whether this type can be set to null. Defaults to false." + @spec optional(t()) :: {:ok, boolean()} | {:error, term()} + def optional(%__MODULE__{} = type_def) do + selection = + type_def.selection |> select("optional") + + execute(selection, type_def.client) + end + + @doc "Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object." + @spec with_constructor(t(), Dagger.Function.t()) :: Dagger.TypeDef.t() + def with_constructor(%__MODULE__{} = type_def, function) do + selection = + type_def.selection + |> select("withConstructor") + |> put_arg("function", Dagger.ID.id!(function)) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Adds a static field for an Object TypeDef, failing if the type is not an object." + @spec with_field(t(), String.t(), Dagger.TypeDef.t(), [{:description, String.t() | nil}]) :: + Dagger.TypeDef.t() + def with_field(%__MODULE__{} = type_def, name, type_def, optional_args \\ []) do + selection = + type_def.selection + |> select("withField") + |> put_arg("name", name) + |> put_arg("typeDef", Dagger.ID.id!(type_def)) + |> maybe_put_arg("description", optional_args[:description]) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds." + @spec with_function(t(), Dagger.Function.t()) :: Dagger.TypeDef.t() + def with_function(%__MODULE__{} = type_def, function) do + selection = + type_def.selection |> select("withFunction") |> put_arg("function", Dagger.ID.id!(function)) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Returns a TypeDef of kind Interface with the provided name." + @spec with_interface(t(), String.t(), [{:description, String.t() | nil}]) :: Dagger.TypeDef.t() + def with_interface(%__MODULE__{} = type_def, name, optional_args \\ []) do + selection = + type_def.selection + |> select("withInterface") + |> put_arg("name", name) + |> maybe_put_arg("description", optional_args[:description]) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Sets the kind of the type." + @spec with_kind(t(), Dagger.TypeDefKind.t()) :: Dagger.TypeDef.t() + def with_kind(%__MODULE__{} = type_def, kind) do + selection = + type_def.selection |> select("withKind") |> put_arg("kind", kind) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Returns a TypeDef of kind List with the provided type for its elements." + @spec with_list_of(t(), Dagger.TypeDef.t()) :: Dagger.TypeDef.t() + def with_list_of(%__MODULE__{} = type_def, element_type) do + selection = + type_def.selection + |> select("withListOf") + |> put_arg("elementType", Dagger.ID.id!(element_type)) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc """ + Returns a TypeDef of kind Object with the provided name. + + 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. + """ + @spec with_object(t(), String.t(), [{:description, String.t() | nil}]) :: Dagger.TypeDef.t() + def with_object(%__MODULE__{} = type_def, name, optional_args \\ []) do + selection = + type_def.selection + |> select("withObject") + |> put_arg("name", name) + |> maybe_put_arg("description", optional_args[:description]) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end + + @doc "Sets whether this type can be set to null." + @spec with_optional(t(), boolean()) :: Dagger.TypeDef.t() + def with_optional(%__MODULE__{} = type_def, optional) do + selection = + type_def.selection |> select("withOptional") |> put_arg("optional", optional) + + %Dagger.TypeDef{ + selection: selection, + client: type_def.client + } + end end diff --git a/sdk/elixir/lib/dagger/gen/type_def_id.ex b/sdk/elixir/lib/dagger/gen/type_def_id.ex index 234a7153fee..e80e35b7be9 100644 --- a/sdk/elixir/lib/dagger/gen/type_def_id.ex +++ b/sdk/elixir/lib/dagger/gen/type_def_id.ex @@ -1,5 +1,6 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.TypeDefID do @moduledoc "The `TypeDefID` scalar type represents an identifier for an object of type TypeDef." + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/gen/type_def_kind.ex b/sdk/elixir/lib/dagger/gen/type_def_kind.ex index 4504d97eebc..27b2b17634b 100644 --- a/sdk/elixir/lib/dagger/gen/type_def_kind.ex +++ b/sdk/elixir/lib/dagger/gen/type_def_kind.ex @@ -1,76 +1,62 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.TypeDefKind do @moduledoc "Distinguishes the different kinds of TypeDefs." + @type t() :: - :BOOLEAN_KIND - | :INPUT_KIND + :STRING_KIND | :INTEGER_KIND - | :INTERFACE_KIND + | :BOOLEAN_KIND | :LIST_KIND | :OBJECT_KIND - | :STRING_KIND + | :INTERFACE_KIND + | :INPUT_KIND | :VOID_KIND - ( - @doc "A boolean value." - @spec boolean_kind() :: :BOOLEAN_KIND - def boolean_kind() do - :BOOLEAN_KIND - end - ) - ( - @doc "A graphql input type, used only when representing the core API via TypeDefs." - @spec input_kind() :: :INPUT_KIND - def input_kind() do - :INPUT_KIND - end - ) + @doc "A string value." + @spec string_kind() :: :STRING_KIND + def string_kind(), do: :STRING_KIND + + @doc "An integer value." + @spec integer_kind() :: :INTEGER_KIND + def integer_kind(), do: :INTEGER_KIND + + @doc "A boolean value." + @spec boolean_kind() :: :BOOLEAN_KIND + def boolean_kind(), do: :BOOLEAN_KIND + + @doc """ + A list of values all having the same type. + + Always paired with a ListTypeDef. + """ + @spec list_kind() :: :LIST_KIND + def list_kind(), do: :LIST_KIND + + @doc """ + A named type defined in the GraphQL schema, with fields and functions. - ( - @doc "An integer value." - @spec integer_kind() :: :INTEGER_KIND - def integer_kind() do - :INTEGER_KIND - end - ) + Always paired with an ObjectTypeDef. + """ + @spec object_kind() :: :OBJECT_KIND + def object_kind(), do: :OBJECT_KIND - ( - @doc "A named type of functions that can be matched+implemented by other objects+interfaces.\n\nAlways paired with an InterfaceTypeDef." - @spec interface_kind() :: :INTERFACE_KIND - def interface_kind() do - :INTERFACE_KIND - end - ) + @doc """ + A named type of functions that can be matched+implemented by other objects+interfaces. - ( - @doc "A list of values all having the same type.\n\nAlways paired with a ListTypeDef." - @spec list_kind() :: :LIST_KIND - def list_kind() do - :LIST_KIND - end - ) + Always paired with an InterfaceTypeDef. + """ + @spec interface_kind() :: :INTERFACE_KIND + def interface_kind(), do: :INTERFACE_KIND - ( - @doc "A named type defined in the GraphQL schema, with fields and functions.\n\nAlways paired with an ObjectTypeDef." - @spec object_kind() :: :OBJECT_KIND - def object_kind() do - :OBJECT_KIND - end - ) + @doc "A graphql input type, used only when representing the core API via TypeDefs." + @spec input_kind() :: :INPUT_KIND + def input_kind(), do: :INPUT_KIND - ( - @doc "A string value." - @spec string_kind() :: :STRING_KIND - def string_kind() do - :STRING_KIND - end - ) + @doc """ + A special kind used to signify that no value is returned. - ( - @doc "A special kind used to signify that no value is returned.\n\nThis is used for functions that have no return value. The outer TypeDef specifying this Kind is always Optional, as the Void is never actually represented." - @spec void_kind() :: :VOID_KIND - def void_kind() do - :VOID_KIND - end - ) + This is used for functions that have no return value. The outer TypeDef specifying this Kind is always Optional, as the Void is never actually represented. + """ + @spec void_kind() :: :VOID_KIND + def void_kind(), do: :VOID_KIND end diff --git a/sdk/elixir/lib/dagger/gen/void.ex b/sdk/elixir/lib/dagger/gen/void.ex index 94a46e08232..b4a62162300 100644 --- a/sdk/elixir/lib/dagger/gen/void.ex +++ b/sdk/elixir/lib/dagger/gen/void.ex @@ -1,5 +1,10 @@ -# This file generated by `mix dagger.gen`. Please DO NOT EDIT. +# This file generated by `dagger_codegen`. Please DO NOT EDIT. defmodule Dagger.Void do - @moduledoc "The absence of a value.\n\nA Null Void is used as a placeholder for resolvers that do not return anything." + @moduledoc """ + The absence of a value. + + A Null Void is used as a placeholder for resolvers that do not return anything. + """ + @type t() :: String.t() end diff --git a/sdk/elixir/lib/dagger/id.ex b/sdk/elixir/lib/dagger/id.ex new file mode 100644 index 00000000000..853234e3749 --- /dev/null +++ b/sdk/elixir/lib/dagger/id.ex @@ -0,0 +1,34 @@ +defprotocol Dagger.ID do + @moduledoc false + + @fallback_to_any true + + @doc """ + Fetch an id against the resource. + + Raise exception on error. + """ + @spec id!(struct()) :: String.t() + def id!(resource) +end + +defimpl Dagger.ID, for: Any do + defmacro __deriving__(module, _struct, _opts) do + quote do + defimpl Dagger.ID, for: unquote(module) do + def id!(resource) do + {:ok, id} = unquote(module).id(resource) + id + end + end + end + end + + def id!(value) do + # Borrowing from `:jason` library. + raise Protocol.UndefinedError, + protocol: @protocol, + value: value, + description: "Dagger.ID protocol must be explicitly implemented" + end +end diff --git a/sdk/elixir/scripts/fetch_introspection.exs b/sdk/elixir/scripts/fetch_introspection.exs new file mode 100644 index 00000000000..4d9f7a2a9ad --- /dev/null +++ b/sdk/elixir/scripts/fetch_introspection.exs @@ -0,0 +1,4 @@ +query = File.read!("dagger_codegen/priv/introspection.graphql") +{:ok, client} = Dagger.Core.Client.connect(connect_timeout: :timer.seconds(50)) +{:ok, %{status: 200, body: resp}} = Dagger.Core.Client.query(client, query) +File.write!("introspection.json", Jason.encode!(resp["data"])) diff --git a/sdk/elixir/test/dagger/client_test.exs b/sdk/elixir/test/dagger/client_test.exs index a543189ef68..2496dc7fb03 100644 --- a/sdk/elixir/test/dagger/client_test.exs +++ b/sdk/elixir/test/dagger/client_test.exs @@ -13,7 +13,8 @@ defmodule Dagger.ClientTest do Host, QueryError, Secret, - Sync + Sync, + ID } setup do @@ -180,9 +181,8 @@ defmodule Dagger.ClientTest do |> Container.from("alpine:3.16.2") |> Container.env_variables() - assert [{:ok, "PATH"}] = - envs - |> Enum.map(&EnvVariable.name/1) + assert is_list(envs) + assert [{:ok, "PATH"}] = Enum.map(envs, &EnvVariable.name/1) end test "nullable", %{client: client} do @@ -255,8 +255,8 @@ defmodule Dagger.ClientTest do Elixir.File.rm_rf!("Dockerfile") - container = Client.container(client) - assert %Container{} = Client.container(client, id: container) + container_id = ID.id!(Client.container(client)) + assert %Container{} = Client.container(client, id: container_id) end test "env variable expand", %{client: client} do diff --git a/sdk/elixir/test/dagger/codegen/elixir/function_test.exs b/sdk/elixir/test/dagger/codegen/elixir/function_test.exs deleted file mode 100644 index d73ab8f77fa..00000000000 --- a/sdk/elixir/test/dagger/codegen/elixir/function_test.exs +++ /dev/null @@ -1,179 +0,0 @@ -defmodule Dagger.Codegen.Elixir.FunctionTest do - use ExUnit.Case, async: true - - alias Dagger.Codegen.Elixir.Function - - describe "define/5" do - test "define function" do - args = [Macro.var(:a, __MODULE__)] - - guard = - quote do - is_atom(unquote(Macro.var(:a, __MODULE__))) - end - - body = - quote do - IO.puts(a) - end - - fun = Function.define(:hello, args, guard, body) - - assert format_code(fun) == - """ - @doc false - def hello(a) when is_atom(a) do - IO.puts(a) - end - """ - |> format_code() - end - - test "define function no argument" do - body = - quote do - IO.puts("Hello") - end - - fun = Function.define(:hello, [], nil, body) - - assert format_code(fun) == - """ - @doc false - def hello() do - IO.puts("Hello") - end - """ - |> format_code() - end - - test "define function without guard" do - args = [Macro.var(:a, __MODULE__)] - - body = - quote do - IO.puts(a) - end - - fun = Function.define(:hello, args, body) - - assert format_code(fun) == - """ - @doc false - def hello(a) do - IO.puts(a) - end - """ - |> format_code() - end - - test "define function and have a pattern on argument" do - args = [ - quote do - %__MODULE__{} = mod - end, - Macro.var(:a, __MODULE__) - ] - - body = - quote do - IO.puts(a) - end - - fun = Function.define(:hello, args, body) - - assert format_code(fun) == - """ - @doc false - def hello(%__MODULE__{} = mod, a) do - IO.puts(a) - end - """ - |> format_code() - end - - test "define doc" do - args = [ - Macro.var(:a, __MODULE__) - ] - - body = - quote do - IO.puts(a) - end - - fun = Function.define(:hello, args, nil, body, doc: "Print `a` to stdout") - - assert format_code(fun) == - """ - @doc "Print `a` to stdout" - def hello(a) do - IO.puts(a) - end - """ - |> format_code() - end - - test "define deprecated" do - body = - quote do - end - - fun = - Function.define(:hello, [], nil, body, - doc: "Print `a` to stdout", - deprecated: "Use another function" - ) - - assert format_code(fun) == - """ - @doc "Print `a` to stdout" - @deprecated "Use another function" - def hello() do - end - """ - |> format_code() - end - - test "define typespec" do - body = - quote do - nil - end - - fun = - Function.define(:hello, [Macro.var(:a, __MODULE__), Macro.var(:b, __MODULE__)], nil, body, - spec: { - [ - quote(do: String.t()), - quote(do: atom()) - ], - quote(do: String.t() | nil) - } - ) - - assert format_code(fun) == - """ - @doc false - @spec hello(String.t(), atom()) :: String.t() | nil - def hello(a, b) do - nil - end - """ - |> format_code() - end - end - - defp format_code(code) when is_binary(code) do - code - |> Code.string_to_quoted!() - |> format_code() - end - - defp format_code(code) do - code - |> Code.quoted_to_algebra() - |> Inspect.Algebra.format(120) - |> IO.iodata_to_binary() - end -end