Current section
Files
Jump to
Current section
Files
src/dagger/dsl/service.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 type ForUp
pub type ForTerminal
pub type ForStop
pub type ForEndpoint
pub opaque type Opts(tag_) {
Opts(
port: Option(Int),
scheme: Option(String),
kill: Option(Bool),
cmd: Option(List(String)),
ports: Option(List(t.PortForward)),
random: Option(Bool),
)
}
fn defaults() -> Opts(a) {
Opts(
port: None,
scheme: None,
kill: None,
cmd: None,
ports: None,
random: None,
)
}
pub fn none(opts: Opts(a)) -> Opts(a) {
opts
}
pub fn opt_port(opts: Opts(ForEndpoint), val: Int) -> Opts(ForEndpoint) {
Opts(..opts, port: Some(val))
}
pub fn opt_scheme(opts: Opts(ForEndpoint), val: String) -> Opts(ForEndpoint) {
Opts(..opts, scheme: Some(val))
}
pub fn opt_kill(opts: Opts(ForStop), val: Bool) -> Opts(ForStop) {
Opts(..opts, kill: Some(val))
}
pub fn opt_cmd(opts: Opts(ForTerminal), val: List(String)) -> Opts(ForTerminal) {
Opts(..opts, cmd: Some(val))
}
pub fn opt_ports(opts: Opts(ForUp), val: List(t.PortForward)) -> Opts(ForUp) {
Opts(..opts, ports: Some(val))
}
pub fn opt_random(opts: Opts(ForUp), val: Bool) -> Opts(ForUp) {
Opts(..opts, random: Some(val))
}
pub fn service(id id: t.Service) -> t.Service {
let field = types.Field(name: "loadServiceFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.Service(op: types.Pure([field]))
}
fn encode_endpoint(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.port {
Some(val) -> Ok(#("port", types.GInt(val)))
None -> Error(Nil)
},
case opts.scheme {
Some(val) -> Ok(#("scheme", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves an endpoint that clients can use to reach this container.
/// If no port is specified, the first exposed port is used. If none exist an error is returned.
/// If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned.
pub fn endpoint(parent: t.Service, with with_fn: fn(Opts(ForEndpoint)) -> Opts(ForEndpoint), client client: Client, then handler: fn(Try(String)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "endpoint", args: encode_endpoint(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("endpoint")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Retrieves a hostname which can be used by clients to reach this container.
pub fn hostname(parent: t.Service, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "hostname", 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.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("hostname")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this Service.
pub fn id(parent: t.Service) -> t.Service {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
/// Retrieves the list of ports provided by the service.
pub fn ports(parent: t.Service, select select: fn(t.Port) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.Port))) -> a) -> a {
let subfields = select(t.Port(op: types.Pure([])))
let field = types.Field(name: "ports", 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.Port(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("ports")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Start the service and wait for its health checks to succeed.
/// Services bound to a Container do not need to be manually started.
pub fn start(parent: t.Service) -> t.Service {
let field = types.Field(name: "start", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
fn encode_stop(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.kill {
Some(val) -> Ok(#("kill", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Stop the service.
pub fn stop(parent: t.Service, with with_fn: fn(Opts(ForStop)) -> Opts(ForStop)) -> t.Service {
let opts = with_fn(defaults())
let field = types.Field(name: "stop", args: encode_stop(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
/// Forces evaluation of the pipeline in the engine.
pub fn sync(parent: t.Service) -> t.Service {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
fn encode_terminal(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
case opts.cmd {
Some(val) -> Ok(#("cmd", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
}
], fn(x) { x })
}
pub fn terminal(parent: t.Service, with with_fn: fn(Opts(ForTerminal)) -> Opts(ForTerminal)) -> t.Service {
let opts = with_fn(defaults())
let field = types.Field(name: "terminal", args: encode_terminal(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
fn encode_up(opts: Opts(tag_)) -> List(#(String, types.Value)) {
list.filter_map([
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)
},
case opts.random {
Some(val) -> Ok(#("random", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Creates a tunnel that forwards traffic from the caller's network to this service.
pub fn up(parent: t.Service, with with_fn: fn(Opts(ForUp)) -> Opts(ForUp), client client: Client, then handler: fn(Try(Nil)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "up", args: encode_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.dynamic)) {
Ok(_) -> types.Pure(Ok(Nil))
Error(_) -> types.Pure(Error(types.DecodingError("up")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Configures a hostname which can be used by clients within the session to reach this container.
pub fn with_hostname(parent: t.Service, hostname hostname: String) -> t.Service {
let field = types.Field(name: "withHostname", args: [#("hostname", types.GString(hostname))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}