-module(dagger@dsl@env_file). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/dagger/dsl/env_file.gleam"). -export([none/1, raw/2, env_file/0, as_file/1, exists/4, get/5, id/1, namespace/2, variables/5, with_variable/3, without_variable/2]). -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(boolean())}. -file("src/dagger/dsl/env_file.gleam", 16). -spec defaults() -> opts(). defaults() -> {opts, none}. -file("src/dagger/dsl/env_file.gleam", 22). -spec none(opts()) -> opts(). none(Opts) -> Opts. -file("src/dagger/dsl/env_file.gleam", 26). -spec raw(opts(), boolean()) -> opts(). raw(Opts, Val) -> {opts, {some, Val}}. -file("src/dagger/dsl/env_file.gleam", 30). -spec env_file() -> dagger@dsl@types:env_file(). env_file() -> Field = {field, <<"envFile"/utf8>>, [], []}, {env_file, {pure, [Field]}}. -file("src/dagger/dsl/env_file.gleam", 36). ?DOC(" Return as a file\n"). -spec as_file(dagger@dsl@types:env_file()) -> dagger@dsl@types:file(). as_file(Parent) -> Field = {field, <<"asFile"/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/env_file.gleam", 46). ?DOC(" Check if a variable exists\n"). -spec exists( dagger@dsl@types:env_file(), binary(), dagger@types:client(), fun(({ok, boolean()} | {error, dagger@types:query_error()}) -> PJH) ) -> PJH. exists(Parent, Name, Client, Handler) -> Field = {field, <<"exists"/utf8>>, [{<<"name"/utf8>>, {g_string, Name}}], []}, 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, <<"exists"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/env_file.gleam", 66). -spec encode_get(opts()) -> list({binary(), dagger@types:value()}). encode_get(Opts) -> gleam@list:filter_map([case erlang:element(2, Opts) of {some, Val} -> {ok, {<<"raw"/utf8>>, {g_bool, Val}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/env_file.gleam", 76). ?DOC(" Lookup a variable (last occurrence wins) and return its value, or an empty string\n"). -spec get( dagger@dsl@types:env_file(), binary(), fun((opts()) -> opts()), dagger@types:client(), fun(({ok, binary()} | {error, dagger@types:query_error()}) -> PJK) ) -> PJK. get(Parent, Name, With_fn, Client, Handler) -> Opts = With_fn(defaults()), Field = {field, <<"get"/utf8>>, lists:append([{<<"name"/utf8>>, {g_string, Name}}], encode_get(Opts)), []}, 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_string/1} ) ) of {ok, Val} -> {pure, {ok, Val}}; {error, _} -> {pure, {error, {decoding_error, <<"get"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/env_file.gleam", 98). ?DOC(" A unique identifier for this EnvFile.\n"). -spec id(dagger@dsl@types:env_file()) -> dagger@dsl@types:env_file(). 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, {env_file, New_op}. -file("src/dagger/dsl/env_file.gleam", 108). ?DOC(" Filters variables by prefix and removes the pref from keys. Variables without the prefix are excluded. For example, with the prefix \"MY_APP_\" and variables: MY_APP_TOKEN=topsecret MY_APP_NAME=hello FOO=bar the resulting environment will contain: TOKEN=topsecret NAME=hello\n"). -spec namespace(dagger@dsl@types:env_file(), binary()) -> dagger@dsl@types:env_file(). namespace(Parent, Prefix) -> Field = {field, <<"namespace"/utf8>>, [{<<"prefix"/utf8>>, {g_string, Prefix}}], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {env_file, New_op}. -file("src/dagger/dsl/env_file.gleam", 117). -spec encode_variables(opts()) -> list({binary(), dagger@types:value()}). encode_variables(Opts) -> gleam@list:filter_map([case erlang:element(2, Opts) of {some, Val} -> {ok, {<<"raw"/utf8>>, {g_bool, Val}}}; none -> {error, nil} end], fun(X) -> X end). -file("src/dagger/dsl/env_file.gleam", 127). ?DOC(" Return all variables\n"). -spec variables( dagger@dsl@types:env_file(), fun((opts()) -> opts()), fun((dagger@dsl@types:env_variable()) -> list(dagger@types:field())), dagger@types:client(), fun(({ok, list(dagger@dsl@types:env_variable())} | {error, dagger@types:query_error()}) -> PJP) ) -> PJP. variables(Parent, With_fn, Select, Client, Handler) -> Opts = With_fn(defaults()), Subfields = Select({env_variable, {pure, []}}), Field = {field, <<"variables"/utf8>>, encode_variables(Opts), Subfields}, 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_dynamic/1} ) ) ) of {ok, Items} -> {pure, {ok, gleam@list:map( Items, fun(_) -> {env_variable, {pure, Full_query}} end )}}; {error, _} -> {pure, {error, {decoding_error, <<"variables"/utf8>>}}} end end} end ) end, Handler(dagger@interpreter:run(Op, Client)). -file("src/dagger/dsl/env_file.gleam", 150). ?DOC(" Add a variable\n"). -spec with_variable(dagger@dsl@types:env_file(), binary(), binary()) -> dagger@dsl@types:env_file(). with_variable(Parent, Name, Value) -> Field = {field, <<"withVariable"/utf8>>, [{<<"name"/utf8>>, {g_string, Name}}, {<<"value"/utf8>>, {g_string, Value}}], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {env_file, New_op}. -file("src/dagger/dsl/env_file.gleam", 160). ?DOC(" Remove all occurrences of the named variable\n"). -spec without_variable(dagger@dsl@types:env_file(), binary()) -> dagger@dsl@types:env_file(). without_variable(Parent, Name) -> Field = {field, <<"withoutVariable"/utf8>>, [{<<"name"/utf8>>, {g_string, Name}}], []}, New_op = begin dagger@types:bind( erlang:element(2, Parent), fun(Q) -> {pure, lists:append(Q, [Field])} end ) end, {env_file, New_op}.