Packages

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

Current section

Files

Jump to
dagger_gleam src dagger dsl function.gleam
Raw

src/dagger/dsl/function.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 ForWithDeprecated
pub type ForWithCachePolicy
pub type ForWithArg
pub opaque type Opts(tag_) {
Opts(
description: Option(String),
default_value: Option(String),
default_path: Option(String),
ignore: Option(List(String)),
source_map: Option(t.SourceMap),
deprecated: Option(String),
default_address: Option(String),
time_to_live: Option(String),
reason: Option(String),
)
}
fn defaults() -> Opts(a) {
Opts(
description: None,
default_value: None,
default_path: None,
ignore: None,
source_map: None,
deprecated: None,
default_address: None,
time_to_live: None,
reason: None,
)
}
pub fn none(opts: Opts(a)) -> Opts(a) {
opts
}
pub fn opt_description(opts: Opts(ForWithArg), val: String) -> Opts(ForWithArg) {
Opts(..opts, description: Some(val))
}
pub fn opt_default_value(opts: Opts(ForWithArg), val: String) -> Opts(ForWithArg) {
Opts(..opts, default_value: Some(val))
}
pub fn opt_default_path(opts: Opts(ForWithArg), val: String) -> Opts(ForWithArg) {
Opts(..opts, default_path: Some(val))
}
pub fn opt_ignore(opts: Opts(ForWithArg), val: List(String)) -> Opts(ForWithArg) {
Opts(..opts, ignore: Some(val))
}
pub fn opt_source_map(opts: Opts(ForWithArg), val: t.SourceMap) -> Opts(ForWithArg) {
Opts(..opts, source_map: Some(val))
}
pub fn opt_deprecated(opts: Opts(ForWithArg), val: String) -> Opts(ForWithArg) {
Opts(..opts, deprecated: Some(val))
}
pub fn opt_default_address(opts: Opts(ForWithArg), val: String) -> Opts(ForWithArg) {
Opts(..opts, default_address: Some(val))
}
pub fn opt_time_to_live(opts: Opts(ForWithCachePolicy), val: String) -> Opts(ForWithCachePolicy) {
Opts(..opts, time_to_live: Some(val))
}
pub fn opt_reason(opts: Opts(ForWithDeprecated), val: String) -> Opts(ForWithDeprecated) {
Opts(..opts, reason: Some(val))
}
pub fn function(name name: String, return_type return_type: t.TypeDef) -> t.Function {
let field = types.Field(name: "function", args: [#("name", types.GString(name)), #("returnType", types.GDeferred(return_type.op))], subfields: [])
t.Function(op: types.Pure([field]))
}
/// Arguments accepted by the function, if any.
pub fn args(parent: t.Function, select select: fn(t.FunctionArg) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.FunctionArg))) -> a) -> a {
let subfields = select(t.FunctionArg(op: types.Pure([])))
let field = types.Field(name: "args", 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.FunctionArg(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("args")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The reason this function is deprecated, if any.
pub fn deprecated(parent: t.Function, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "deprecated", 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("deprecated")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A doc string for the function, if any.
pub fn description(parent: t.Function, 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))
}
/// A unique identifier for this Function.
pub fn id(parent: t.Function) -> t.Function {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
/// The name of the function.
pub fn name(parent: t.Function, 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))
}
/// The type returned by the function.
pub fn return_type(parent: t.Function) -> t.TypeDef {
let field = types.Field(name: "returnType", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.TypeDef(op: new_op)
}
/// The location of this function declaration.
pub fn source_map(parent: t.Function) -> t.SourceMap {
let field = types.Field(name: "sourceMap", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.SourceMap(op: new_op)
}
fn encode_with_arg(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.description {
Some(val) -> Ok(#("description", types.GString(val)))
None -> Error(Nil)
},
case opts.default_value {
Some(val) -> Ok(#("defaultValue", types.GString(val)))
None -> Error(Nil)
},
case opts.default_path {
Some(val) -> Ok(#("defaultPath", types.GString(val)))
None -> Error(Nil)
},
case opts.ignore {
Some(val) -> Ok(#("ignore", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.source_map {
Some(val) -> Ok(#("sourceMap", types.GDeferred(val.op)))
None -> Error(Nil)
},
case opts.deprecated {
Some(val) -> Ok(#("deprecated", types.GString(val)))
None -> Error(Nil)
},
case opts.default_address {
Some(val) -> Ok(#("defaultAddress", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Returns the function with the provided argument
pub fn with_arg(parent: t.Function, name name: String, type_def type_def: t.TypeDef, with with_fn: fn(Opts(ForWithArg)) -> Opts(ForWithArg)) -> t.Function {
let opts = with_fn(defaults())
let field = types.Field(name: "withArg", args: list.append([#("name", types.GString(name)), #("typeDef", types.GDeferred(type_def.op))], encode_with_arg(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
fn encode_with_cache_policy(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.time_to_live {
Some(val) -> Ok(#("timeToLive", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Returns the function updated to use the provided cache policy.
pub fn with_cache_policy(parent: t.Function, policy policy: t.FunctionCachePolicy, with with_fn: fn(Opts(ForWithCachePolicy)) -> Opts(ForWithCachePolicy)) -> t.Function {
let opts = with_fn(defaults())
let field = types.Field(name: "withCachePolicy", args: list.append([#("policy", types.GString(t.function_cache_policy_to_json(policy)))], encode_with_cache_policy(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
/// Returns the function with a flag indicating it's a check.
pub fn with_check(parent: t.Function) -> t.Function {
let field = types.Field(name: "withCheck", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
fn encode_with_deprecated(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.reason {
Some(val) -> Ok(#("reason", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Returns the function with the provided deprecation reason.
pub fn with_deprecated(parent: t.Function, with with_fn: fn(Opts(ForWithDeprecated)) -> Opts(ForWithDeprecated)) -> t.Function {
let opts = with_fn(defaults())
let field = types.Field(name: "withDeprecated", args: encode_with_deprecated(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
/// Returns the function with the given doc string.
pub fn with_description(parent: t.Function, description description: String) -> t.Function {
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.Function(op: new_op)
}
/// Returns the function with a flag indicating it's a generator.
pub fn with_generator(parent: t.Function) -> t.Function {
let field = types.Field(name: "withGenerator", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}
/// Returns the function with the given source map.
pub fn with_source_map(parent: t.Function, source_map source_map: t.SourceMap) -> t.Function {
let field = types.Field(name: "withSourceMap", args: [#("sourceMap", types.GDeferred(source_map.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Function(op: new_op)
}