Current section
Files
Jump to
Current section
Files
src/dagger/dsl/workspace.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 ForFindUp
pub type ForDirectory
pub type ForWorkspace
pub opaque type Opts(tag_) {
Opts(
skip_migration_check: Option(Bool),
exclude: Option(List(String)),
include: Option(List(String)),
gitignore: Option(Bool),
from: Option(String),
)
}
fn defaults() -> Opts(a) {
Opts(
skip_migration_check: None,
exclude: None,
include: None,
gitignore: None,
from: None,
)
}
pub fn none(opts: Opts(a)) -> Opts(a) {
opts
}
pub fn opt_skip_migration_check(opts: Opts(ForWorkspace), val: Bool) -> Opts(ForWorkspace) {
Opts(..opts, skip_migration_check: Some(val))
}
pub fn opt_exclude(opts: Opts(ForDirectory), val: List(String)) -> Opts(ForDirectory) {
Opts(..opts, exclude: Some(val))
}
pub fn opt_include(opts: Opts(ForDirectory), val: List(String)) -> Opts(ForDirectory) {
Opts(..opts, include: Some(val))
}
pub fn opt_gitignore(opts: Opts(ForDirectory), val: Bool) -> Opts(ForDirectory) {
Opts(..opts, gitignore: Some(val))
}
pub fn opt_from(opts: Opts(ForFindUp), val: String) -> Opts(ForFindUp) {
Opts(..opts, from: Some(val))
}
fn encode_workspace(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.skip_migration_check {
Some(val) -> Ok(#("skipMigrationCheck", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
pub fn workspace(with with_fn: fn(Opts(ForWorkspace)) -> Opts(ForWorkspace)) -> t.Workspace {
let opts = with_fn(defaults())
let field = types.Field(name: "currentWorkspace", args: encode_workspace(opts), subfields: [])
t.Workspace(op: types.Pure([field]))
}
/// The client ID that owns this workspace's host filesystem.
pub fn client_id(parent: t.Workspace, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "clientId", 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("clientId")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_directory(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.exclude {
Some(val) -> Ok(#("exclude", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.include {
Some(val) -> Ok(#("include", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.gitignore {
Some(val) -> Ok(#("gitignore", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Returns a Directory from the workspace.
/// Path is relative to workspace root. Use "." for the root directory.
pub fn directory(parent: t.Workspace, path path: String, with with_fn: fn(Opts(ForDirectory)) -> Opts(ForDirectory)) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "directory", args: list.append([#("path", types.GString(path))], encode_directory(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Returns a File from the workspace.
/// Path is relative to workspace root.
pub fn file(parent: t.Workspace, path path: String) -> t.File {
let field = types.Field(name: "file", args: [#("path", types.GString(path))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
fn encode_find_up(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.from {
Some(val) -> Ok(#("from", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Search for a file or directory by walking up from the start path within the workspace.
/// Returns the path relative to the workspace root if found, or null if not found.
/// The search stops at the workspace root and will not traverse above it.
pub fn find_up(parent: t.Workspace, name name: String, with with_fn: fn(Opts(ForFindUp)) -> Opts(ForFindUp), client client: Client, then handler: fn(Try(String)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "findUp", args: list.append([#("name", types.GString(name))], encode_find_up(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("findUp")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this Workspace.
pub fn id(parent: t.Workspace) -> t.Workspace {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Workspace(op: new_op)
}
/// Absolute path to the workspace root directory.
pub fn root(parent: t.Workspace, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "root", 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("root")))
}
}
)
}
handler(interpreter.run(op, client))
}