Packages

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

Current section

Files

Jump to
dagger_gleam src dagger dsl changeset.gleam
Raw

src/dagger/dsl/changeset.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 opaque type Opts(tag_) {
Opts(
on_conflict: Option(t.ChangesetMergeConflict),
)
}
fn defaults() -> Opts(a) {
Opts(
on_conflict: None,
)
}
pub fn none(opts: Opts(a)) -> Opts(a) {
opts
}
pub fn opt_on_conflict(opts: Opts(a), val: t.ChangesetMergeConflict) -> Opts(a) {
Opts(on_conflict: Some(val))
}
pub fn changeset(id id: t.Changeset) -> t.Changeset {
let field = types.Field(name: "loadChangesetFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.Changeset(op: types.Pure([field]))
}
/// Files and directories that were added in the newer directory.
pub fn added_paths(parent: t.Changeset, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "addedPaths", 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("addedPaths")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The newer/upper snapshot.
pub fn after(parent: t.Changeset) -> t.Directory {
let field = types.Field(name: "after", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a Git-compatible patch of the changes
pub fn as_patch(parent: t.Changeset) -> t.File {
let field = types.Field(name: "asPatch", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// The older/lower snapshot to compare against.
pub fn before(parent: t.Changeset) -> t.Directory {
let field = types.Field(name: "before", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Applies the diff represented by this changeset to a path on the host.
pub fn export(parent: t.Changeset, path path: String, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "export", args: [#("path", types.GString(path))], 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("export")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this Changeset.
pub fn id(parent: t.Changeset) -> t.Changeset {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Changeset(op: new_op)
}
/// Returns true if the changeset is empty (i.e. there are no changes).
pub fn is_empty(parent: t.Changeset, client client: Client, then handler: fn(Try(Bool)) -> a) -> a {
let field = types.Field(name: "isEmpty", 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.bool)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("isEmpty")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Return a snapshot containing only the created and modified files
pub fn layer(parent: t.Changeset) -> t.Directory {
let field = types.Field(name: "layer", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Files and directories that existed before and were updated in the newer directory.
pub fn modified_paths(parent: t.Changeset, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "modifiedPaths", 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("modifiedPaths")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Files and directories that were removed. Directories are indicated by a trailing slash, and their child paths are not included.
pub fn removed_paths(parent: t.Changeset, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "removedPaths", 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("removedPaths")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Force evaluation in the engine.
pub fn sync(parent: t.Changeset) -> t.Changeset {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Changeset(op: new_op)
}
fn encode_with_changeset(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.on_conflict {
Some(val) -> Ok(#("onConflict", types.GString(t.changeset_merge_conflict_to_json(val))))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Add changes to an existing changeset
/// By default the operation will fail in case of conflicts, for instance a file modified in both changesets. The behavior can be adjusted using onConflict argument
pub fn with_changeset(parent: t.Changeset, changes changes: t.Changeset, with with_fn: fn(Opts(a)) -> Opts(a)) -> t.Changeset {
let opts = with_fn(defaults())
let field = types.Field(name: "withChangeset", args: list.append([#("changes", types.GDeferred(changes.op))], encode_with_changeset(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Changeset(op: new_op)
}
fn encode_with_changesets(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.on_conflict {
Some(val) -> Ok(#("onConflict", types.GString(t.changeset_merge_conflict_to_json(val))))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Add changes from multiple changesets using git octopus merge strategy
/// This is more efficient than chaining multiple withChangeset calls when merging many changesets.
/// Only FAIL and FAIL_EARLY conflict strategies are supported (octopus merge cannot use -X ours/theirs).
pub fn with_changesets(parent: t.Changeset, changes changes: List(t.Changeset), with with_fn: fn(Opts(a)) -> Opts(a)) -> t.Changeset {
let opts = with_fn(defaults())
let field = types.Field(name: "withChangesets", args: list.append([#("changes", types.GList(list.map(changes, fn(x) { types.GDeferred(x.op) })))], encode_with_changesets(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Changeset(op: new_op)
}