// 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( key: Option(String), use_default_policy: Option(Bool), ) } fn defaults() -> Opts { Opts( key: None, use_default_policy: None, ) } pub fn none(opts: Opts) -> Opts { opts } pub fn key(opts: Opts, val: String) -> Opts { Opts(..opts, key: Some(val)) } pub fn use_default_policy(opts: Opts, val: Bool) -> Opts { Opts(..opts, use_default_policy: 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) -> 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) -> Opts) -> 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) -> List(#(String, types.Value)) { list.filter_map([ case opts.use_default_policy { Some(val) -> Ok(#("useDefaultPolicy", types.GBool(val))) None -> Error(Nil) } ], fn(x) { x }) } /// Prune the cache of releaseable entries pub fn prune(parent: t.EngineCache, 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: "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) }