Packages

Gleam SDK for Dagger — type-safe pipelines via GraphQL codegen

Current section

Files

Jump to
dagger_gleam src dagger dsl module.gleam
Raw

src/dagger/dsl/module.gleam

// AUTO-GENERATED BY DAGGER_GLEAM - DO NOT EDIT
import dagger/types.{type Client, type Try} as types
import dagger/interpreter
import dagger/dsl/types as t
import gleam/dynamic/decode
import gleam/list
import gleam/option.{type Option, None, Some}
pub type Opts {
Opts(
include: Option(List(String)),
include_dependencies: Option(Bool),
)
}
fn defaults() -> Opts {
Opts(
include: None,
include_dependencies: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
pub fn include(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, include: Some(val))
}
pub fn include_dependencies(opts: Opts, val: Bool) -> Opts {
Opts(..opts, include_dependencies: Some(val))
}
pub fn module(id id: t.Module) -> t.Module {
let field = types.Field(name: "loadModuleFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.Module(op: types.Pure([field]))
}
/// Return the check defined by the module with the given name. Must match to exactly one check.
pub fn check(parent: t.Module, name name: String) -> t.Check {
let field = types.Field(name: "check", args: [#("name", types.GString(name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Check(op: new_op)
}
fn encode_checks(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.include {
Some(val) -> Ok(#("include", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return all checks defined by the module
pub fn checks(parent: t.Module, with with_fn: fn(Opts) -> Opts) -> t.CheckGroup {
let opts = with_fn(defaults())
let field = types.Field(name: "checks", args: encode_checks(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.CheckGroup(op: new_op)
}
/// The dependencies of the module.
pub fn dependencies(parent: t.Module, select select: fn(t.Module) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.Module))) -> a) -> a {
let subfields = select(t.Module(op: types.Pure([])))
let field = types.Field(name: "dependencies", args: [], subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.Module(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("dependencies")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The doc string of the module, if any
pub fn description(parent: t.Module, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "description", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("description")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Enumerations served by this module.
pub fn enums(parent: t.Module, select select: fn(t.TypeDef) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.TypeDef))) -> a) -> a {
let subfields = select(t.TypeDef(op: types.Pure([])))
let field = types.Field(name: "enums", args: [], subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.TypeDef(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("enums")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The generated files and directories made on top of the module source's context directory.
pub fn generated_context_directory(parent: t.Module) -> t.Directory {
let field = types.Field(name: "generatedContextDirectory", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return the generator defined by the module with the given name. Must match to exactly one generator.
pub fn generator(parent: t.Module, name name: String) -> t.Generator {
let field = types.Field(name: "generator", args: [#("name", types.GString(name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Generator(op: new_op)
}
fn encode_generators(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.include {
Some(val) -> Ok(#("include", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return all generators defined by the module
pub fn generators(parent: t.Module, with with_fn: fn(Opts) -> Opts) -> t.GeneratorGroup {
let opts = with_fn(defaults())
let field = types.Field(name: "generators", args: encode_generators(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.GeneratorGroup(op: new_op)
}
/// A unique identifier for this Module.
pub fn id(parent: t.Module) -> t.Module {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
/// Interfaces served by this module.
pub fn interfaces(parent: t.Module, select select: fn(t.TypeDef) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.TypeDef))) -> a) -> a {
let subfields = select(t.TypeDef(op: types.Pure([])))
let field = types.Field(name: "interfaces", args: [], subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.TypeDef(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("interfaces")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The introspection schema JSON file for this module.
/// This file represents the schema visible to the module's source code, including all core types and those from the dependencies.
/// Note: this is in the context of a module, so some core types may be hidden.
pub fn introspection_schema_j_s_o_n(parent: t.Module) -> t.File {
let field = types.Field(name: "introspectionSchemaJSON", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// The name of the module
pub fn name(parent: t.Module, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "name", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("name")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Objects served by this module.
pub fn objects(parent: t.Module, select select: fn(t.TypeDef) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.TypeDef))) -> a) -> a {
let subfields = select(t.TypeDef(op: types.Pure([])))
let field = types.Field(name: "objects", args: [], subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.TypeDef(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("objects")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The container that runs the module's entrypoint. It will fail to execute if the module doesn't compile.
pub fn runtime(parent: t.Module) -> t.Container {
let field = types.Field(name: "runtime", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Container(op: new_op)
}
/// The SDK config used by this module.
pub fn sdk(parent: t.Module) -> t.SDKConfig {
let field = types.Field(name: "sdk", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.SDKConfig(op: new_op)
}
fn encode_serve(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.include_dependencies {
Some(val) -> Ok(#("includeDependencies", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// 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.
pub fn serve(parent: t.Module, with with_fn: fn(Opts) -> Opts, client client: Client, then handler: fn(Try(Nil)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "serve", args: encode_serve(opts), subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.dynamic)) {
Ok(_) -> types.Pure(Ok(Nil))
Error(_) -> types.Pure(Error(types.DecodingError("serve")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The source for the module.
pub fn source(parent: t.Module) -> t.ModuleSource {
let field = types.Field(name: "source", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.ModuleSource(op: new_op)
}
/// Forces evaluation of the module, including any loading into the engine and associated validation.
pub fn sync(parent: t.Module) -> t.Module {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
/// User-defined default values, loaded from local .env files.
pub fn user_defaults(parent: t.Module) -> t.EnvFile {
let field = types.Field(name: "userDefaults", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}
/// Retrieves the module with the given description
pub fn with_description(parent: t.Module, description description: String) -> t.Module {
let field = types.Field(name: "withDescription", args: [#("description", types.GString(description))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
/// This module plus the given Enum type and associated values
pub fn with_enum(parent: t.Module, enum enum: t.TypeDef) -> t.Module {
let field = types.Field(name: "withEnum", args: [#("enum", types.GDeferred(enum.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
/// This module plus the given Interface type and associated functions
pub fn with_interface(parent: t.Module, iface iface: t.TypeDef) -> t.Module {
let field = types.Field(name: "withInterface", args: [#("iface", types.GDeferred(iface.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
/// This module plus the given Object type and associated functions.
pub fn with_object(parent: t.Module, object object: t.TypeDef) -> t.Module {
let field = types.Field(name: "withObject", args: [#("object", types.GDeferred(object.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}