Packages

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

Current section

Files

Jump to
dagger_gleam src dagger dsl engine.gleam
Raw

src/dagger/dsl/engine.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 ForPrune
pub type ForEntrySet
pub opaque type Opts(tag_) {
Opts(
key: Option(String),
use_default_policy: Option(Bool),
max_used_space: Option(String),
reserved_space: Option(String),
min_free_space: Option(String),
target_space: Option(String),
)
}
fn defaults() -> Opts(a) {
Opts(
key: None,
use_default_policy: None,
max_used_space: None,
reserved_space: None,
min_free_space: None,
target_space: None,
)
}
pub fn none(opts: Opts(a)) -> Opts(a) {
opts
}
pub fn opt_key(opts: Opts(ForEntrySet), val: String) -> Opts(ForEntrySet) {
Opts(..opts, key: Some(val))
}
pub fn opt_use_default_policy(opts: Opts(ForPrune), val: Bool) -> Opts(ForPrune) {
Opts(..opts, use_default_policy: Some(val))
}
pub fn opt_max_used_space(opts: Opts(ForPrune), val: String) -> Opts(ForPrune) {
Opts(..opts, max_used_space: Some(val))
}
pub fn opt_reserved_space(opts: Opts(ForPrune), val: String) -> Opts(ForPrune) {
Opts(..opts, reserved_space: Some(val))
}
pub fn opt_min_free_space(opts: Opts(ForPrune), val: String) -> Opts(ForPrune) {
Opts(..opts, min_free_space: Some(val))
}
pub fn opt_target_space(opts: Opts(ForPrune), val: String) -> Opts(ForPrune) {
Opts(..opts, target_space: Some(val))
}
pub fn engine() -> t.Engine {
let field = types.Field(name: "engine", args: [], subfields: [])
t.Engine(op: types.Pure([field]))
}
/// The list of connected client IDs
pub fn clients(parent: t.Engine, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "clients", 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.list(decode.string))) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("clients")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this Engine.
pub fn engine_id(parent: t.Engine) -> t.Engine {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Engine(op: new_op)
}
/// The local (on-disk) cache for the Dagger engine
pub fn local_cache(parent: t.Engine) -> t.EngineCache {
let field = types.Field(name: "localCache", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EngineCache(op: new_op)
}
/// The name of the engine instance.
pub fn name(parent: t.Engine, 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))
}
pub fn engine_cache(id id: t.EngineCache) -> t.EngineCache {
let field = types.Field(name: "loadEngineCacheFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.EngineCache(op: types.Pure([field]))
}
fn encode_entry_set(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.key {
Some(val) -> Ok(#("key", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// The current set of entries in the cache
pub fn entry_set(parent: t.EngineCache, with with_fn: fn(Opts(ForEntrySet)) -> Opts(ForEntrySet)) -> t.EngineCacheEntrySet {
let opts = with_fn(defaults())
let field = types.Field(name: "entrySet", args: encode_entry_set(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EngineCacheEntrySet(op: new_op)
}
/// A unique identifier for this EngineCache.
pub fn cache_id(parent: t.EngineCache) -> t.EngineCache {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EngineCache(op: new_op)
}
/// The maximum bytes to keep in the cache without pruning.
pub fn max_used_space(parent: t.EngineCache, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "maxUsedSpace", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("maxUsedSpace")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The target amount of free disk space the garbage collector will attempt to leave.
pub fn min_free_space(parent: t.EngineCache, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "minFreeSpace", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("minFreeSpace")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_prune(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.use_default_policy {
Some(val) -> Ok(#("useDefaultPolicy", types.GBool(val)))
None -> Error(Nil)
},
case opts.max_used_space {
Some(val) -> Ok(#("maxUsedSpace", types.GString(val)))
None -> Error(Nil)
},
case opts.reserved_space {
Some(val) -> Ok(#("reservedSpace", types.GString(val)))
None -> Error(Nil)
},
case opts.min_free_space {
Some(val) -> Ok(#("minFreeSpace", types.GString(val)))
None -> Error(Nil)
},
case opts.target_space {
Some(val) -> Ok(#("targetSpace", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Prune the cache of releaseable entries
pub fn prune(parent: t.EngineCache, with with_fn: fn(Opts(ForPrune)) -> Opts(ForPrune), client client: Client, then handler: fn(Try(Nil)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "prune", args: encode_prune(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("prune")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The minimum amount of disk space this policy is guaranteed to retain.
pub fn reserved_space(parent: t.EngineCache, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "reservedSpace", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("reservedSpace")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The target number of bytes to keep when pruning.
pub fn target_space(parent: t.EngineCache, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "targetSpace", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("targetSpace")))
}
}
)
}
handler(interpreter.run(op, client))
}
pub fn engine_cache_entry_set(id id: t.EngineCacheEntrySet) -> t.EngineCacheEntrySet {
let field = types.Field(name: "loadEngineCacheEntrySetFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.EngineCacheEntrySet(op: types.Pure([field]))
}
/// The total disk space used by the cache entries in this set.
pub fn disk_space_bytes(parent: t.EngineCacheEntrySet, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "diskSpaceBytes", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("diskSpaceBytes")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The list of individual cache entries in the set
pub fn entries(parent: t.EngineCacheEntrySet, select select: fn(t.EngineCacheEntry) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.EngineCacheEntry))) -> a) -> a {
let subfields = select(t.EngineCacheEntry(op: types.Pure([])))
let field = types.Field(name: "entries", 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.EngineCacheEntry(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("entries")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The number of cache entries in this set.
pub fn entry_count(parent: t.EngineCacheEntrySet, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "entryCount", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("entryCount")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this EngineCacheEntrySet.
pub fn cache_entry_set_id(parent: t.EngineCacheEntrySet) -> t.EngineCacheEntrySet {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EngineCacheEntrySet(op: new_op)
}