Packages

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

Current section

Files

Jump to
dagger_gleam src dagger dsl env_file.gleam
Raw

src/dagger/dsl/env_file.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(
raw: Option(Bool),
)
}
fn defaults() -> Opts {
Opts(
raw: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
pub fn raw(opts: Opts, val: Bool) -> Opts {
Opts(raw: Some(val))
}
pub fn env_file() -> t.EnvFile {
let field = types.Field(name: "envFile", args: [], subfields: [])
t.EnvFile(op: types.Pure([field]))
}
/// Return as a file
pub fn as_file(parent: t.EnvFile) -> t.File {
let field = types.Field(name: "asFile", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// Check if a variable exists
pub fn exists(parent: t.EnvFile, name name: String, client client: Client, then handler: fn(Try(Bool)) -> a) -> a {
let field = types.Field(name: "exists", args: [#("name", types.GString(name))], 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.bool)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("exists")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_get(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.raw {
Some(val) -> Ok(#("raw", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Lookup a variable (last occurrence wins) and return its value, or an empty string
pub fn get(parent: t.EnvFile, name name: String, with with_fn: fn(Opts) -> Opts, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "get", args: list.append([#("name", types.GString(name))], encode_get(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.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("get")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this EnvFile.
pub fn id(parent: t.EnvFile) -> t.EnvFile {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}
/// Filters variables by prefix and removes the pref from keys. Variables without the prefix are excluded. For example, with the prefix "MY_APP_" and variables: MY_APP_TOKEN=topsecret MY_APP_NAME=hello FOO=bar the resulting environment will contain: TOKEN=topsecret NAME=hello
pub fn namespace(parent: t.EnvFile, prefix prefix: String) -> t.EnvFile {
let field = types.Field(name: "namespace", args: [#("prefix", types.GString(prefix))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}
fn encode_variables(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.raw {
Some(val) -> Ok(#("raw", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return all variables
pub fn variables(parent: t.EnvFile, with with_fn: fn(Opts) -> Opts, select select: fn(t.EnvVariable) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.EnvVariable))) -> a) -> a {
let opts = with_fn(defaults())
let subfields = select(t.EnvVariable(op: types.Pure([])))
let field = types.Field(name: "variables", args: encode_variables(opts), 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.EnvVariable(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("variables")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Add a variable
pub fn with_variable(parent: t.EnvFile, name name: String, value value: String) -> t.EnvFile {
let field = types.Field(name: "withVariable", args: [#("name", types.GString(name)), #("value", types.GString(value))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}
/// Remove all occurrences of the named variable
pub fn without_variable(parent: t.EnvFile, name name: String) -> t.EnvFile {
let field = types.Field(name: "withoutVariable", args: [#("name", types.GString(name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}