-module(dagger@dsl@changeset). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/dagger/dsl/changeset.gleam"). -export([none/1, on_conflict/2, changeset/1, added_paths/3, 'after'/1, as_patch/1, before/1, export/4, id/1, is_empty/3, layer/1, modified_paths/3, removed_paths/3, sync/1, with_changeset/3, with_changesets/3]). -export_type([opts/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type opts() :: {opts, gleam@option:option(dagger@dsl@types:changeset_merge_conflict())}. -file("src/dagger/dsl/changeset.gleam", 16). -spec defaults() -> opts(). defaults() -> {opts, none}. -file("src/dagger/dsl/changeset.gleam", 22). -spec none(opts()) -> opts(). none(Opts) -> Opts. -file("src/dagger/dsl/changeset.gleam", 26). -spec on_conflict(opts(), dagger@dsl@types:changeset_merge_conflict()) -> opts(). on_conflict(Opts, Val) -> {opts, {some, Val}}. -file("src/dagger/dsl/changeset.gleam", 30). -spec changeset(dagger@dsl@types:changeset()) -> dagger@dsl@types:changeset(). changeset(Id) -> Field = {field, <<"loadChangesetFromID"/utf8>>, [{<<"id"/utf8>>, {g_deferred, erlang:element(2, Id)}}], []}, {changeset, {pure, [Field]}}. -file("src/dagger/dsl/changeset.gleam", 36). ?DOC(" Files and directories that were added in the newer directory.\n"). -spec added_paths( dagger@dsl@types:changeset(), dagger@types:client(), fun(({ok, list(binary())} | {error, dagger@types:query_error()}) -> GVX) ) -> GVX. added_paths(Parent, Client, Handler) -> Field = {field, <<"addedPaths"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"addedPaths"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/changeset.gleam", 57). ?DOC(" The newer/upper snapshot.\n"). -spec 'after'(dagger@dsl@types:changeset()) -> dagger@dsl@types:directory(). 'after'(Parent) -> Field = {field, <<"after"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {directory, New_op}. -file("src/dagger/dsl/changeset.gleam", 67). ?DOC(" Return a Git-compatible patch of the changes\n"). -spec as_patch(dagger@dsl@types:changeset()) -> dagger@dsl@types:file(). as_patch(Parent) -> Field = {field, <<"asPatch"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {file, New_op}. -file("src/dagger/dsl/changeset.gleam", 77). ?DOC(" The older/lower snapshot to compare against.\n"). -spec before(dagger@dsl@types:changeset()) -> dagger@dsl@types:directory(). before(Parent) -> Field = {field, <<"before"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {directory, New_op}. -file("src/dagger/dsl/changeset.gleam", 87). ?DOC(" Applies the diff represented by this changeset to a path on the host.\n"). -spec export( dagger@dsl@types:changeset(), binary(), dagger@types:client(), fun(({ok, binary()} | {error, dagger@types:query_error()}) -> GVZ) ) -> GVZ. export(Parent, Path, Client, Handler) -> Field = {field, <<"export"/utf8>>, [{<<"path"/utf8>>, {g_string, Path}}], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path@1 = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path@1, {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"export"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/changeset.gleam", 108). ?DOC(" A unique identifier for this Changeset.\n"). -spec id(dagger@dsl@types:changeset()) -> dagger@dsl@types:changeset(). id(Parent) -> Field = {field, <<"id"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {changeset, New_op}. -file("src/dagger/dsl/changeset.gleam", 118). ?DOC(" Returns true if the changeset is empty (i.e. there are no changes).\n"). -spec is_empty( dagger@dsl@types:changeset(), dagger@types:client(), fun(({ok, boolean()} | {error, dagger@types:query_error()}) -> GWB) ) -> GWB. is_empty(Parent, Client, Handler) -> Field = {field, <<"isEmpty"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, {decoder, fun gleam@dynamic@decode:decode_bool/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"isEmpty"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/changeset.gleam", 139). ?DOC(" Return a snapshot containing only the created and modified files\n"). -spec layer(dagger@dsl@types:changeset()) -> dagger@dsl@types:directory(). layer(Parent) -> Field = {field, <<"layer"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {directory, New_op}. -file("src/dagger/dsl/changeset.gleam", 149). ?DOC(" Files and directories that existed before and were updated in the newer directory.\n"). -spec modified_paths( dagger@dsl@types:changeset(), dagger@types:client(), fun(({ok, list(binary())} | {error, dagger@types:query_error()}) -> GWE) ) -> GWE. modified_paths(Parent, Client, Handler) -> Field = {field, <<"modifiedPaths"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"modifiedPaths"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/changeset.gleam", 170). ?DOC(" Files and directories that were removed. Directories are indicated by a trailing slash, and their child paths are not included.\n"). -spec removed_paths( dagger@dsl@types:changeset(), dagger@types:client(), fun(({ok, list(binary())} | {error, dagger@types:query_error()}) -> GWH) ) -> GWH. removed_paths(Parent, Client, Handler) -> Field = {field, <<"removedPaths"/utf8>>, [], []}, Op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> Full_query = lists:append(Q, [Field]), {fetch, Full_query, {decoder, fun gleam@dynamic@decode:decode_dynamic/1}, fun(Dyn) -> Path = dagger@types:make_path(Full_query), case gleam@dynamic@decode:run( Dyn, gleam@dynamic@decode:at( Path, gleam@dynamic@decode:list( {decoder, fun gleam@dynamic@decode:decode_string/1} ) ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"removedPaths"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/changeset.gleam", 191). ?DOC(" Force evaluation in the engine.\n"). -spec sync(dagger@dsl@types:changeset()) -> dagger@dsl@types:changeset(). sync(Parent) -> Field = {field, <<"sync"/utf8>>, [], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {changeset, New_op}. -file("src/dagger/dsl/changeset.gleam", 200). -spec encode_with_changeset(opts()) -> list({binary(), dagger@types:value()}). encode_with_changeset(Opts) -> gleam@list:filter_map([case erlang:element(2, Opts) of {some, Val} -> {ok, {<<"onConflict"/utf8>>, {g_string, dagger@dsl@types:changeset_merge_conflict_to_json( Val )}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/changeset.gleam", 211). ?DOC( " Add changes to an existing changeset\n" " 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\n" ). -spec with_changeset( dagger@dsl@types:changeset(), dagger@dsl@types:changeset(), fun((opts()) -> opts()) ) -> dagger@dsl@types:changeset(). with_changeset(Parent, Changes, With_fn) -> Opts = With_fn(defaults()), Field = {field, <<"withChangeset"/utf8>>, lists:append( [{<<"changes"/utf8>>, {g_deferred, erlang:element(2, Changes)}}], encode_with_changeset(Opts) ), []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {changeset, New_op}. -file("src/dagger/dsl/changeset.gleam", 221). -spec encode_with_changesets(opts()) -> list({binary(), dagger@types:value()}). encode_with_changesets(Opts) -> gleam@list:filter_map([case erlang:element(2, Opts) of {some, Val} -> {ok, {<<"onConflict"/utf8>>, {g_string, dagger@dsl@types:changeset_merge_conflict_to_json( Val )}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/changeset.gleam", 233). ?DOC( " Add changes from multiple changesets using git octopus merge strategy\n" " This is more efficient than chaining multiple withChangeset calls when merging many changesets.\n" " Only FAIL and FAIL_EARLY conflict strategies are supported (octopus merge cannot use -X ours/theirs).\n" ). -spec with_changesets( dagger@dsl@types:changeset(), list(dagger@dsl@types:changeset()), fun((opts()) -> opts()) ) -> dagger@dsl@types:changeset(). with_changesets(Parent, Changes, With_fn) -> Opts = With_fn(defaults()), Field = {field, <<"withChangesets"/utf8>>, lists:append( [{<<"changes"/utf8>>, {g_list, gleam@list:map( Changes, fun(X) -> {g_deferred, erlang:element(2, X)} end )}}], encode_with_changesets(Opts) ), []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {changeset, New_op}.