// 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 ForChanges pub opaque type Opts(tag_) { Opts( on_conflict: Option(t.ChangesetsMergeConflict), ) } fn defaults() -> Opts(a) { Opts( on_conflict: None, ) } pub fn none(opts: Opts(a)) -> Opts(a) { opts } pub fn opt_on_conflict(opts: Opts(ForChanges), val: t.ChangesetsMergeConflict) -> Opts(ForChanges) { Opts(on_conflict: Some(val)) } pub fn generator_group(id id: t.GeneratorGroup) -> t.GeneratorGroup { let field = types.Field(name: "loadGeneratorGroupFromID", args: [#("id", types.GDeferred(id.op))], subfields: []) t.GeneratorGroup(op: types.Pure([field])) } fn encode_changes(opts: Opts(tag_)) -> List(#(String, types.Value)) { list.filter_map([ case opts.on_conflict { Some(val) -> Ok(#("onConflict", types.GString(t.changesets_merge_conflict_to_json(val)))) None -> Error(Nil) } ], fn(x) { x }) } /// The combined changes from the generators execution /// If any conflict occurs, for instance if the same file is modified by multiple generators, or if a file is both modified and deleted, an error is raised and the merge of the changesets will failed. /// Set 'continueOnConflicts' flag to force to merge the changes in a 'last write wins' strategy. pub fn changes(parent: t.GeneratorGroup, with with_fn: fn(Opts(ForChanges)) -> Opts(ForChanges)) -> t.Changeset { let opts = with_fn(defaults()) let field = types.Field(name: "changes", args: encode_changes(opts), subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Changeset(op: new_op) } /// A unique identifier for this GeneratorGroup. pub fn id(parent: t.GeneratorGroup) -> t.GeneratorGroup { let field = types.Field(name: "id", args: [], subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.GeneratorGroup(op: new_op) } /// Whether the generated changeset is empty or not pub fn is_empty(parent: t.GeneratorGroup, 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 list of individual generators and their details pub fn list(parent: t.GeneratorGroup, select select: fn(t.Generator) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.Generator))) -> a) -> a { let subfields = select(t.Generator(op: types.Pure([]))) let field = types.Field(name: "list", 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.Generator(op: types.Pure(full_query)) }))) Error(_) -> types.Pure(Error(types.DecodingError("list"))) } } ) } handler(interpreter.run(op, client)) } /// Execute all selected generators pub fn run(parent: t.GeneratorGroup) -> t.GeneratorGroup { let field = types.Field(name: "run", args: [], subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.GeneratorGroup(op: new_op) }