// 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 ForTunnel pub type ForService pub type ForDirectory pub opaque type Opts(tag_) { Opts( exclude: Option(List(String)), include: Option(List(String)), no_cache: Option(Bool), gitignore: Option(Bool), host: Option(String), native: Option(Bool), ports: Option(List(t.PortForward)), ) } fn defaults() -> Opts(a) { Opts( exclude: None, include: None, no_cache: None, gitignore: None, host: None, native: None, ports: None, ) } pub fn none(opts: Opts(a)) -> Opts(a) { opts } 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_no_cache(opts: Opts(a), val: Bool) -> Opts(a) { Opts(..opts, no_cache: Some(val)) } pub fn opt_gitignore(opts: Opts(ForDirectory), val: Bool) -> Opts(ForDirectory) { Opts(..opts, gitignore: Some(val)) } pub fn opt_host(opts: Opts(ForService), val: String) -> Opts(ForService) { Opts(..opts, host: Some(val)) } pub fn opt_native(opts: Opts(ForTunnel), val: Bool) -> Opts(ForTunnel) { Opts(..opts, native: Some(val)) } pub fn opt_ports(opts: Opts(ForTunnel), val: List(t.PortForward)) -> Opts(ForTunnel) { Opts(..opts, ports: Some(val)) } pub fn host() -> t.Host { let field = types.Field(name: "host", args: [], subfields: []) t.Host(op: types.Pure([field])) } /// Accesses a container image on the host. pub fn container_image(parent: t.Host, name name: String) -> t.Container { let field = types.Field(name: "containerImage", args: [#("name", types.GString(name))], subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Container(op: new_op) } 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.no_cache { Some(val) -> Ok(#("noCache", types.GBool(val))) None -> Error(Nil) }, case opts.gitignore { Some(val) -> Ok(#("gitignore", types.GBool(val))) None -> Error(Nil) } ], fn(x) { x }) } /// Accesses a directory on the host. pub fn directory(parent: t.Host, 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) } fn encode_file(opts: Opts(tag_)) -> List(#(String, types.Value)) { list.filter_map([ case opts.no_cache { Some(val) -> Ok(#("noCache", types.GBool(val))) None -> Error(Nil) } ], fn(x) { x }) } /// Accesses a file on the host. pub fn file(parent: t.Host, path path: String, with with_fn: fn(Opts(a)) -> Opts(a)) -> t.File { let opts = with_fn(defaults()) let field = types.Field(name: "file", args: list.append([#("path", types.GString(path))], encode_file(opts)), 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.no_cache { Some(val) -> Ok(#("noCache", types.GBool(val))) None -> Error(Nil) } ], fn(x) { x }) } /// Search for a file or directory by walking up the tree from system workdir. Return its relative path. If no match, return null pub fn find_up(parent: t.Host, name name: String, with with_fn: fn(Opts(a)) -> Opts(a), 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 Host. pub fn id(parent: t.Host) -> t.Host { let field = types.Field(name: "id", args: [], subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Host(op: new_op) } fn encode_service(opts: Opts(tag_)) -> List(#(String, types.Value)) { list.filter_map([ case opts.host { Some(val) -> Ok(#("host", types.GString(val))) None -> Error(Nil) } ], fn(x) { x }) } /// Creates a service that forwards traffic to a specified address via the host. pub fn service(parent: t.Host, ports ports: List(t.PortForward), with with_fn: fn(Opts(ForService)) -> Opts(ForService)) -> t.Service { let opts = with_fn(defaults()) let field = types.Field(name: "service", args: list.append([#("ports", types.GList(list.map(ports, fn(x) { types.GObject(t.port_forward_to_json(x)) })))], encode_service(opts)), subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Service(op: new_op) } fn encode_tunnel(opts: Opts(tag_)) -> List(#(String, types.Value)) { list.filter_map([ case opts.native { Some(val) -> Ok(#("native", types.GBool(val))) None -> Error(Nil) }, case opts.ports { Some(val) -> Ok(#("ports", types.GList(list.map(val, fn(x) { types.GObject(t.port_forward_to_json(x)) })))) None -> Error(Nil) } ], fn(x) { x }) } /// Creates a tunnel that forwards traffic from the host to a service. pub fn tunnel(parent: t.Host, service service: t.Service, with with_fn: fn(Opts(ForTunnel)) -> Opts(ForTunnel)) -> t.Service { let opts = with_fn(defaults()) let field = types.Field(name: "tunnel", args: list.append([#("service", types.GDeferred(service.op))], encode_tunnel(opts)), subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Service(op: new_op) } /// Accesses a Unix socket on the host. pub fn unix_socket(parent: t.Host, path path: String) -> t.Socket { let field = types.Field(name: "unixSocket", args: [#("path", types.GString(path))], subfields: []) let new_op = { use q <- types.bind(parent.op) types.Pure(list.append(q, [field])) } t.Socket(op: new_op) }