From c6da949e1a089ed4a06b7025f53f97faae2d6ab9 Mon Sep 17 00:00:00 2001 From: Dudesons Date: Tue, 30 Sep 2025 12:50:49 +0200 Subject: [PATCH] Allow to select redis image --- redis/.gitattributes | 1 + redis/.gitignore | 3 + redis/README.md | 8 +- redis/cli.go | 17 +- redis/dagger.json | 7 +- redis/go.mod | 52 +- redis/go.sum | 104 +- redis/internal/dagger/dagger.gen.go | 9337 +++++++++++++++++++-------- redis/redis.go | 40 +- redis/server.go | 9 +- 10 files changed, 6880 insertions(+), 2698 deletions(-) diff --git a/redis/.gitattributes b/redis/.gitattributes index b94d9fd..738cf71 100644 --- a/redis/.gitattributes +++ b/redis/.gitattributes @@ -2,3 +2,4 @@ /querybuilder/** linguist-generated /internal/dagger/** linguist-generated /internal/querybuilder/** linguist-generated +/internal/telemetry/** linguist-generated diff --git a/redis/.gitignore b/redis/.gitignore index d10f24a..7e2fe63 100644 --- a/redis/.gitignore +++ b/redis/.gitignore @@ -1,3 +1,6 @@ /dagger.gen.go /internal/querybuilder/ /querybuilder/ +/internal/dagger +/internal/telemetry +/.env diff --git a/redis/README.md b/redis/README.md index ce38682..6b8451a 100644 --- a/redis/README.md +++ b/redis/README.md @@ -17,7 +17,13 @@ A simple module to start and interact with a Redis service. ### Create a Redis server ```shell -dagger -m github.com/quartz-technology/daggerverse/redis call server expose up +dagger -m github.com/quartz-technology/daggerverse/redis call server up +``` + +#### Test the server from local +```shell +dagger -m github.com/quartz-technology/daggerverse/redis call cli --server=tcp://localhost:6379 set --key=foo --value=bar +dagger -m github.com/quartz-technology/daggerverse/redis call cli --server=tcp://localhost:6379 get --key=foo ``` ### Create a Redis client diff --git a/redis/cli.go b/redis/cli.go index 8ee8145..81f7669 100644 --- a/redis/cli.go +++ b/redis/cli.go @@ -1,15 +1,18 @@ package main -import "context" +import ( + "context" + "redis/internal/dagger" +) type Cli struct { - Ctr *Container + Ctr *dagger.Container } // CLI returns a new container running the Redis CLI connected to a redis Service. func (r *Redis) Cli( // The Redis server to connect to. - server *Service, + server *dagger.Service, ) (*Cli, error) { ctr, err := r.Server() if err != nil { @@ -30,14 +33,14 @@ func (r *Redis) Cli( }, nil } -func (c *Cli) Container() *Container { +func (c *Cli) Container() *dagger.Container { return c.Ctr } -func (c *Cli) Set(key, value string) *Container { - return c.Ctr.WithExec([]string{"SET", key, value}) +func (c *Cli) Set(key, value string) *dagger.Container { + return c.Ctr.WithExec([]string{"SET", key, value}, dagger.ContainerWithExecOpts{UseEntrypoint: true}) } func (c *Cli) Get(ctx context.Context, key string) (string, error) { - return c.Ctr.WithExec([]string{"GET", key}).Stdout(ctx) + return c.Ctr.WithExec([]string{"GET", key}, dagger.ContainerWithExecOpts{UseEntrypoint: true}).Stdout(ctx) } diff --git a/redis/dagger.json b/redis/dagger.json index 5576c10..60bf307 100644 --- a/redis/dagger.json +++ b/redis/dagger.json @@ -1,6 +1,7 @@ { "name": "redis", - "sdk": "go", - "source": ".", - "engineVersion": "v0.10.2" + "engineVersion": "v0.18.16", + "sdk": { + "source": "go" + } } diff --git a/redis/go.mod b/redis/go.mod index f20961a..35f0302 100644 --- a/redis/go.mod +++ b/redis/go.mod @@ -1,15 +1,53 @@ module redis -go 1.21 +go 1.23.0 + +toolchain go1.24.6 require ( - github.com/99designs/gqlgen v0.17.31 - github.com/Khan/genqlient v0.6.0 - golang.org/x/sync v0.6.0 + github.com/99designs/gqlgen v0.17.75 + github.com/Khan/genqlient v0.8.1 + golang.org/x/sync v0.15.0 ) require ( - github.com/stretchr/testify v1.9.0 // indirect - github.com/vektah/gqlparser/v2 v2.5.6 - golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/cenkalti/backoff/v5 v5.0.2 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect + github.com/sosodev/duration v1.3.1 // indirect + github.com/vektah/gqlparser/v2 v2.5.28 + go.opentelemetry.io/auto/sdk v1.1.0 // indirect + go.opentelemetry.io/otel v1.36.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.12.2 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.12.2 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 + go.opentelemetry.io/otel/log v0.12.2 + go.opentelemetry.io/otel/metric v1.36.0 + go.opentelemetry.io/otel/sdk v1.36.0 + go.opentelemetry.io/otel/sdk/log v0.12.2 + go.opentelemetry.io/otel/sdk/metric v1.36.0 + go.opentelemetry.io/otel/trace v1.36.0 + go.opentelemetry.io/proto/otlp v1.6.0 + golang.org/x/net v0.41.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect + google.golang.org/grpc v1.73.0 + google.golang.org/protobuf v1.36.6 // indirect ) + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.12.2 + +replace go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp => go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.12.2 + +replace go.opentelemetry.io/otel/log => go.opentelemetry.io/otel/log v0.12.2 + +replace go.opentelemetry.io/otel/sdk/log => go.opentelemetry.io/otel/sdk/log v0.12.2 diff --git a/redis/go.sum b/redis/go.sum index 6b16e9f..7475895 100644 --- a/redis/go.sum +++ b/redis/go.sum @@ -1,35 +1,89 @@ -github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158= -github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4= -github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk= -github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM= -github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/99designs/gqlgen v0.17.75 h1:GwHJsptXWLHeY7JO8b7YueUI4w9Pom6wJTICosDtQuI= +github.com/99designs/gqlgen v0.17.75/go.mod h1:p7gbTpdnHyl70hmSpM8XG8GiKwmCv+T5zkdY8U8bLog= +github.com/Khan/genqlient v0.8.1 h1:wtOCc8N9rNynRLXN3k3CnfzheCUNKBcvXmVv5zt6WCs= +github.com/Khan/genqlient v0.8.1/go.mod h1:R2G6DzjBvCbhjsEajfRjbWdVglSH/73kSivC9TLWVjU= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8= +github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU= -github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= +github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vektah/gqlparser/v2 v2.5.28 h1:bIulcl3LF69ba6EiZVGD88y4MkM+Jxrf3P2MX8xLRkY= +github.com/vektah/gqlparser/v2 v2.5.28/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg= +go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.12.2 h1:06ZeJRe5BnYXceSM9Vya83XXVaNGe3H1QqsvqRANQq8= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.12.2/go.mod h1:DvPtKE63knkDVP88qpatBj81JxN+w1bqfVbsbCbj1WY= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.12.2 h1:tPLwQlXbJ8NSOfZc4OkgU5h2A38M4c9kfHSVc4PFQGs= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.12.2/go.mod h1:QTnxBwT/1rBIgAG1goq6xMydfYOBKU6KTiYF4fp5zL8= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0 h1:j7ZSD+5yn+lo3sGV69nW04rRR0jhYnBwjuX3r0HvnK0= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0/go.mod h1:WXbYJTUaZXAbYd8lbgGuvih0yuCfOFC5RJoYnoLcGz8= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0 h1:t/Qur3vKSkUCcDVaSumWF2PKHt85pc7fRvFuoVT8qFU= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0/go.mod h1:Rl61tySSdcOJWoEgYZVtmnKdA0GeKrSqkHC1t+91CH8= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 h1:IJFEoHiytixx8cMiVAO+GmHR6Frwu+u5Ur8njpFO6Ac= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0/go.mod h1:3rHrKNtLIoS0oZwkY2vxi+oJcwFRWdtUyRII+so45p8= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 h1:9kV11HXBHZAvuPUZxmMWrH8hZn/6UnHX4K0mu36vNsU= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0/go.mod h1:JyA0FHXe22E1NeNiHmVp7kFHglnexDQ7uRWDiiJ1hKQ= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 h1:cMyu9O88joYEaI47CnQkxO1XZdpoTF9fEnW2duIddhw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0/go.mod h1:6Am3rn7P9TVVeXYG+wtcGE7IE1tsQ+bP3AuWcKt/gOI= +go.opentelemetry.io/otel/log v0.12.2 h1:yob9JVHn2ZY24byZeaXpTVoPS6l+UrrxmxmPKohXTwc= +go.opentelemetry.io/otel/log v0.12.2/go.mod h1:ShIItIxSYxufUMt+1H5a2wbckGli3/iCfuEbVZi/98E= +go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE= +go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs= +go.opentelemetry.io/otel/sdk v1.36.0 h1:b6SYIuLRs88ztox4EyrvRti80uXIFy+Sqzoh9kFULbs= +go.opentelemetry.io/otel/sdk v1.36.0/go.mod h1:+lC+mTgD+MUWfjJubi2vvXWcVxyr9rmlshZni72pXeY= +go.opentelemetry.io/otel/sdk/log v0.12.2 h1:yNoETvTByVKi7wHvYS6HMcZrN5hFLD7I++1xIZ/k6W0= +go.opentelemetry.io/otel/sdk/log v0.12.2/go.mod h1:DcpdmUXHJgSqN/dh+XMWa7Vf89u9ap0/AAk/XGLnEzY= +go.opentelemetry.io/otel/sdk/log/logtest v0.0.0-20250521073539-a85ae98dcedc h1:uqxdywfHqqCl6LmZzI3pUnXT1RGFYyUgxj0AkWPFxi0= +go.opentelemetry.io/otel/sdk/log/logtest v0.0.0-20250521073539-a85ae98dcedc/go.mod h1:TY/N/FT7dmFrP/r5ym3g0yysP1DefqGpAZr4f82P0dE= +go.opentelemetry.io/otel/sdk/metric v1.36.0 h1:r0ntwwGosWGaa0CrSt8cuNuTcccMXERFwHX4dThiPis= +go.opentelemetry.io/otel/sdk/metric v1.36.0/go.mod h1:qTNOhFDfKRwX0yXOqJYegL5WRaW376QbB7P4Pb0qva4= +go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w= +go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA= +go.opentelemetry.io/proto/otlp v1.6.0 h1:jQjP+AQyTf+Fe7OKj/MfkDrmK4MNVtw2NpXsf9fefDI= +go.opentelemetry.io/proto/otlp v1.6.0/go.mod h1:cicgGehlFuNdgZkcALOCh3VE6K/u2tAjzlRhDwmVpZc= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= +golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= +google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237 h1:Kog3KlB4xevJlAcbbbzPfRG0+X9fdoGM+UBRKVz6Wr0= +google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237/go.mod h1:ezi0AVyMKDWy5xAncvjLWH7UcLBB5n7y2fQ8MzjJcto= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 h1:cJfm9zPbe1e873mHJzmQ1nwVEeRDU/T1wXDK2kUSU34= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok= +google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/redis/internal/dagger/dagger.gen.go b/redis/internal/dagger/dagger.gen.go index f3cd40d..39156d7 100644 --- a/redis/internal/dagger/dagger.gen.go +++ b/redis/internal/dagger/dagger.gen.go @@ -12,14 +12,30 @@ import ( "os" "reflect" "strconv" - "strings" "github.com/Khan/genqlient/graphql" "github.com/vektah/gqlparser/v2/gqlerror" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" "redis/internal/querybuilder" + "redis/internal/telemetry" ) +func Tracer() trace.Tracer { + return otel.Tracer("dagger.io/sdk.go") +} + +// reassigned at runtime after the span is initialized +var marshalCtx = context.Background() + +// SetMarshalContext is a hack that lets us set the ctx to use for +// MarshalJSON implementations that get an object's ID. +func SetMarshalContext(ctx context.Context) { + marshalCtx = ctx +} + // assertNotNil panic if the given value is nil. // This function is used to validate that input with pointer type are not nil. // See https://github.com/dagger/dagger/issues/5696 for more context. @@ -32,12 +48,36 @@ func assertNotNil(argName string, value any) { } } -type DaggerObject querybuilder.GraphQLMarshaller +type DaggerObject = querybuilder.GraphQLMarshaller + +type gqlExtendedError struct { + inner *gqlerror.Error +} + +// Same as telemetry.ExtendedError, but without the dependency, to simplify +// client generation. +type extendedError interface { + error + Extensions() map[string]any +} + +func (e gqlExtendedError) Unwrap() error { + return e.inner +} + +var _ extendedError = gqlExtendedError{} + +func (e gqlExtendedError) Error() string { + return e.inner.Message +} + +func (e gqlExtendedError) Extensions() map[string]any { + return e.inner.Extensions +} // getCustomError parses a GraphQL error into a more specific error type. func getCustomError(err error) error { var gqlErr *gqlerror.Error - if !errors.As(err, &gqlErr) { return nil } @@ -46,12 +86,12 @@ func getCustomError(err error) error { typ, ok := ext["_type"].(string) if !ok { - return nil + return gqlExtendedError{gqlErr} } if typ == "EXEC_ERROR" { e := &ExecError{ - original: err, + original: gqlErr, } if code, ok := ext["exitCode"].(float64); ok { e.ExitCode = int(code) @@ -72,29 +112,26 @@ func getCustomError(err error) error { return e } - return nil + return gqlExtendedError{gqlErr} } // ExecError is an API error from an exec operation. type ExecError struct { - original error + original *gqlerror.Error Cmd []string ExitCode int Stdout string Stderr string } +var _ extendedError = (*ExecError)(nil) + func (e *ExecError) Error() string { - // As a default when just printing the error, include the stdout - // and stderr for visibility - msg := e.Message() - if strings.TrimSpace(e.Stdout) != "" { - msg += "\nStdout:\n" + e.Stdout - } - if strings.TrimSpace(e.Stderr) != "" { - msg += "\nStderr:\n" + e.Stderr - } - return msg + return e.Message() +} + +func (e *ExecError) Extensions() map[string]any { + return e.original.Extensions } func (e *ExecError) Message() string { @@ -105,9 +142,15 @@ func (e *ExecError) Unwrap() error { return e.original } +// The `BindingID` scalar type represents an identifier for an object of type Binding. +type BindingID string + // The `CacheVolumeID` scalar type represents an identifier for an object of type CacheVolume. type CacheVolumeID string +// The `CloudID` scalar type represents an identifier for an object of type Cloud. +type CloudID string + // The `ContainerID` scalar type represents an identifier for an object of type Container. type ContainerID string @@ -117,9 +160,24 @@ type CurrentModuleID string // The `DirectoryID` scalar type represents an identifier for an object of type Directory. type DirectoryID string +// The `EnumTypeDefID` scalar type represents an identifier for an object of type EnumTypeDef. +type EnumTypeDefID string + +// The `EnumValueTypeDefID` scalar type represents an identifier for an object of type EnumValueTypeDef. +type EnumValueTypeDefID string + +// The `EnvID` scalar type represents an identifier for an object of type Env. +type EnvID string + // The `EnvVariableID` scalar type represents an identifier for an object of type EnvVariable. type EnvVariableID string +// The `ErrorID` scalar type represents an identifier for an object of type Error. +type ErrorID string + +// The `ErrorValueID` scalar type represents an identifier for an object of type ErrorValue. +type ErrorValueID string + // The `FieldTypeDefID` scalar type represents an identifier for an object of type FieldTypeDef. type FieldTypeDefID string @@ -141,9 +199,6 @@ type FunctionID string // The `GeneratedCodeID` scalar type represents an identifier for an object of type GeneratedCode. type GeneratedCodeID string -// The `GitModuleSourceID` scalar type represents an identifier for an object of type GitModuleSource. -type GitModuleSourceID string - // The `GitRefID` scalar type represents an identifier for an object of type GitRef. type GitRefID string @@ -159,17 +214,20 @@ type InterfaceTypeDefID string // An arbitrary JSON-encoded value. type JSON string +// The `LLMID` scalar type represents an identifier for an object of type LLM. +type LLMID string + +// The `LLMTokenUsageID` scalar type represents an identifier for an object of type LLMTokenUsage. +type LLMTokenUsageID string + // The `LabelID` scalar type represents an identifier for an object of type Label. type LabelID string // The `ListTypeDefID` scalar type represents an identifier for an object of type ListTypeDef. type ListTypeDefID string -// The `LocalModuleSourceID` scalar type represents an identifier for an object of type LocalModuleSource. -type LocalModuleSourceID string - -// The `ModuleDependencyID` scalar type represents an identifier for an object of type ModuleDependency. -type ModuleDependencyID string +// The `ModuleConfigClientID` scalar type represents an identifier for an object of type ModuleConfigClient. +type ModuleConfigClientID string // The `ModuleID` scalar type represents an identifier for an object of type Module. type ModuleID string @@ -188,6 +246,12 @@ type Platform string // The `PortID` scalar type represents an identifier for an object of type Port. type PortID string +// The `SDKConfigID` scalar type represents an identifier for an object of type SDKConfig. +type SDKConfigID string + +// The `ScalarTypeDefID` scalar type represents an identifier for an object of type ScalarTypeDef. +type ScalarTypeDefID string + // The `SecretID` scalar type represents an identifier for an object of type Secret. type SecretID string @@ -197,6 +261,9 @@ type ServiceID string // The `SocketID` scalar type represents an identifier for an object of type Socket. type SocketID string +// The `SourceMapID` scalar type represents an identifier for an object of type SourceMap. +type SourceMapID string + // The `TerminalID` scalar type represents an identifier for an object of type Terminal. type TerminalID string @@ -238,234 +305,177 @@ type PortForward struct { Protocol NetworkProtocol `json:"protocol,omitempty"` } -// A directory whose contents persist across runs. -type CacheVolume struct { +type Binding struct { query *querybuilder.Selection - id *CacheVolumeID + asString *string + digest *string + id *BindingID + isNull *bool + name *string + typeName *string } -func (r *CacheVolume) WithGraphQLQuery(q *querybuilder.Selection) *CacheVolume { - return &CacheVolume{ +func (r *Binding) WithGraphQLQuery(q *querybuilder.Selection) *Binding { + return &Binding{ query: q, } } -// A unique identifier for this CacheVolume. -func (r *CacheVolume) ID(ctx context.Context) (CacheVolumeID, error) { - if r.id != nil { - return *r.id, nil +// Retrieve the binding value, as type CacheVolume +func (r *Binding) AsCacheVolume() *CacheVolume { + q := r.query.Select("asCacheVolume") + + return &CacheVolume{ + query: q, } - q := r.query.Select("id") +} - var response CacheVolumeID +// Retrieve the binding value, as type Cloud +func (r *Binding) AsCloud() *Cloud { + q := r.query.Select("asCloud") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Cloud{ + query: q, + } } -// XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *CacheVolume) XXX_GraphQLType() string { - return "CacheVolume" -} +// Retrieve the binding value, as type Container +func (r *Binding) AsContainer() *Container { + q := r.query.Select("asContainer") -// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *CacheVolume) XXX_GraphQLIDType() string { - return "CacheVolumeID" + return &Container{ + query: q, + } } -// XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *CacheVolume) XXX_GraphQLID(ctx context.Context) (string, error) { - id, err := r.ID(ctx) - if err != nil { - return "", err +// Retrieve the binding value, as type Directory +func (r *Binding) AsDirectory() *Directory { + q := r.query.Select("asDirectory") + + return &Directory{ + query: q, } - return string(id), nil } -func (r *CacheVolume) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) - if err != nil { - return nil, err +// Retrieve the binding value, as type Env +func (r *Binding) AsEnv() *Env { + q := r.query.Select("asEnv") + + return &Env{ + query: q, } - return json.Marshal(id) } -func (r *CacheVolume) UnmarshalJSON(bs []byte) error { - var id string - err := json.Unmarshal(bs, &id) - if err != nil { - return err + +// Retrieve the binding value, as type File +func (r *Binding) AsFile() *File { + q := r.query.Select("asFile") + + return &File{ + query: q, } - *r = *dag.LoadCacheVolumeFromID(CacheVolumeID(id)) - return nil } -// An OCI-compatible container, also known as a Docker container. -type Container struct { - query *querybuilder.Selection +// Retrieve the binding value, as type GitRef +func (r *Binding) AsGitRef() *GitRef { + q := r.query.Select("asGitRef") - envVariable *string - export *bool - id *ContainerID - imageRef *string - label *string - platform *Platform - publish *string - stderr *string - stdout *string - sync *ContainerID - user *string - workdir *string + return &GitRef{ + query: q, + } } -type WithContainerFunc func(r *Container) *Container -// With calls the provided function with current Container. -// -// This is useful for reusability and readability by not breaking the calling chain. -func (r *Container) With(f WithContainerFunc) *Container { - return f(r) -} +// Retrieve the binding value, as type GitRepository +func (r *Binding) AsGitRepository() *GitRepository { + q := r.query.Select("asGitRepository") -func (r *Container) WithGraphQLQuery(q *querybuilder.Selection) *Container { - return &Container{ + return &GitRepository{ query: q, } } -// Turn the container into a Service. -// -// Be sure to set any exposed ports before this conversion. -func (r *Container) AsService() *Service { - q := r.query.Select("asService") +// Retrieve the binding value, as type LLM +func (r *Binding) AsLLM() *LLM { + q := r.query.Select("asLLM") - return &Service{ + return &LLM{ query: q, } } -// ContainerAsTarballOpts contains options for Container.AsTarball -type ContainerAsTarballOpts struct { - // Identifiers for other platform specific containers. - // - // Used for multi-platform images. - PlatformVariants []*Container - // Force each layer of the image to use the specified compression algorithm. - // - // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. - ForcedCompression ImageLayerCompression - // Use the specified media types for the image's layers. - // - // Defaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support. - MediaTypes ImageMediaTypes -} +// Retrieve the binding value, as type Module +func (r *Binding) AsModule() *Module { + q := r.query.Select("asModule") -// Returns a File representing the container serialized to a tarball. -func (r *Container) AsTarball(opts ...ContainerAsTarballOpts) *File { - q := r.query.Select("asTarball") - for i := len(opts) - 1; i >= 0; i-- { - // `platformVariants` optional argument - if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { - q = q.Arg("platformVariants", opts[i].PlatformVariants) - } - // `forcedCompression` optional argument - if !querybuilder.IsZeroValue(opts[i].ForcedCompression) { - q = q.Arg("forcedCompression", opts[i].ForcedCompression) - } - // `mediaTypes` optional argument - if !querybuilder.IsZeroValue(opts[i].MediaTypes) { - q = q.Arg("mediaTypes", opts[i].MediaTypes) - } + return &Module{ + query: q, } +} - return &File{ +// Retrieve the binding value, as type ModuleConfigClient +func (r *Binding) AsModuleConfigClient() *ModuleConfigClient { + q := r.query.Select("asModuleConfigClient") + + return &ModuleConfigClient{ query: q, } } -// ContainerBuildOpts contains options for Container.Build -type ContainerBuildOpts struct { - // Path to the Dockerfile to use. - Dockerfile string - // Target build stage to build. - Target string - // Additional build arguments. - BuildArgs []BuildArg - // Secrets to pass to the build. - // - // They will be mounted at /run/secrets/[secret-name] in the build container - // - // They can be accessed in the Dockerfile using the "secret" mount type and mount path /run/secrets/[secret-name], e.g. RUN --mount=type=secret,id=my-secret curl [http://example.com?token=$(cat /run/secrets/my-secret)](http://example.com?token=$(cat /run/secrets/my-secret)) - Secrets []*Secret -} +// Retrieve the binding value, as type ModuleSource +func (r *Binding) AsModuleSource() *ModuleSource { + q := r.query.Select("asModuleSource") -// Initializes this container from a Dockerfile build. -func (r *Container) Build(context *Directory, opts ...ContainerBuildOpts) *Container { - assertNotNil("context", context) - q := r.query.Select("build") - for i := len(opts) - 1; i >= 0; i-- { - // `dockerfile` optional argument - if !querybuilder.IsZeroValue(opts[i].Dockerfile) { - q = q.Arg("dockerfile", opts[i].Dockerfile) - } - // `target` optional argument - if !querybuilder.IsZeroValue(opts[i].Target) { - q = q.Arg("target", opts[i].Target) - } - // `buildArgs` optional argument - if !querybuilder.IsZeroValue(opts[i].BuildArgs) { - q = q.Arg("buildArgs", opts[i].BuildArgs) - } - // `secrets` optional argument - if !querybuilder.IsZeroValue(opts[i].Secrets) { - q = q.Arg("secrets", opts[i].Secrets) - } + return &ModuleSource{ + query: q, } - q = q.Arg("context", context) +} - return &Container{ +// Retrieve the binding value, as type Secret +func (r *Binding) AsSecret() *Secret { + q := r.query.Select("asSecret") + + return &Secret{ query: q, } } -// Retrieves default arguments for future commands. -func (r *Container) DefaultArgs(ctx context.Context) ([]string, error) { - q := r.query.Select("defaultArgs") - - var response []string +// Retrieve the binding value, as type Service +func (r *Binding) AsService() *Service { + q := r.query.Select("asService") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Service{ + query: q, + } } -// Retrieves a directory at the given path. -// -// Mounts are included. -func (r *Container) Directory(path string) *Directory { - q := r.query.Select("directory") - q = q.Arg("path", path) +// Retrieve the binding value, as type Socket +func (r *Binding) AsSocket() *Socket { + q := r.query.Select("asSocket") - return &Directory{ + return &Socket{ query: q, } } -// Retrieves entrypoint to be prepended to the arguments of all commands. -func (r *Container) Entrypoint(ctx context.Context) ([]string, error) { - q := r.query.Select("entrypoint") +// The binding's string value +func (r *Binding) AsString(ctx context.Context) (string, error) { + if r.asString != nil { + return *r.asString, nil + } + q := r.query.Select("asString") - var response []string + var response string q = q.Bind(&response) return response, q.Execute(ctx) } -// Retrieves the value of the specified environment variable. -func (r *Container) EnvVariable(ctx context.Context, name string) (string, error) { - if r.envVariable != nil { - return *r.envVariable, nil +// The digest of the binding value +func (r *Binding) Digest(ctx context.Context) (string, error) { + if r.digest != nil { + return *r.digest, nil } - q := r.query.Select("envVariable") - q = q.Arg("name", name) + q := r.query.Select("digest") var response string @@ -473,107 +483,61 @@ func (r *Container) EnvVariable(ctx context.Context, name string) (string, error return response, q.Execute(ctx) } -// Retrieves the list of environment variables passed to commands. -func (r *Container) EnvVariables(ctx context.Context) ([]EnvVariable, error) { - q := r.query.Select("envVariables") +// A unique identifier for this Binding. +func (r *Binding) ID(ctx context.Context) (BindingID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") - q = q.Select("id") + var response BindingID - type envVariables struct { - Id EnvVariableID - } + q = q.Bind(&response) + return response, q.Execute(ctx) +} - convert := func(fields []envVariables) []EnvVariable { - out := []EnvVariable{} +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Binding) XXX_GraphQLType() string { + return "Binding" +} - for i := range fields { - val := EnvVariable{id: &fields[i].Id} - val.query = q.Root().Select("loadEnvVariableFromID").Arg("id", fields[i].Id) - out = append(out, val) - } - - return out - } - var response []envVariables - - q = q.Bind(&response) +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Binding) XXX_GraphQLIDType() string { + return "BindingID" +} - err := q.Execute(ctx) +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Binding) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) if err != nil { - return nil, err + return "", err } - - return convert(response), nil + return string(id), nil } -// EXPERIMENTAL API! Subject to change/removal at any time. -// -// Configures all available GPUs on the host to be accessible to this container. -// -// This currently works for Nvidia devices only. -func (r *Container) ExperimentalWithAllGPUs() *Container { - q := r.query.Select("experimentalWithAllGPUs") - - return &Container{ - query: q, +func (r *Binding) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err } + return json.Marshal(id) } - -// EXPERIMENTAL API! Subject to change/removal at any time. -// -// Configures the provided list of devices to be accesible to this container. -// -// This currently works for Nvidia devices only. -func (r *Container) ExperimentalWithGPU(devices []string) *Container { - q := r.query.Select("experimentalWithGPU") - q = q.Arg("devices", devices) - - return &Container{ - query: q, +func (r *Binding) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err } + *r = *dag.LoadBindingFromID(BindingID(id)) + return nil } -// ContainerExportOpts contains options for Container.Export -type ContainerExportOpts struct { - // Identifiers for other platform specific containers. - // - // Used for multi-platform image. - PlatformVariants []*Container - // Force each layer of the exported image to use the specified compression algorithm. - // - // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. - ForcedCompression ImageLayerCompression - // Use the specified media types for the exported image's layers. - // - // Defaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support. - MediaTypes ImageMediaTypes -} - -// Writes the container as an OCI tarball to the destination file path on the host. -// -// Return true on success. -// -// It can also export platform variants. -func (r *Container) Export(ctx context.Context, path string, opts ...ContainerExportOpts) (bool, error) { - if r.export != nil { - return *r.export, nil - } - q := r.query.Select("export") - for i := len(opts) - 1; i >= 0; i-- { - // `platformVariants` optional argument - if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { - q = q.Arg("platformVariants", opts[i].PlatformVariants) - } - // `forcedCompression` optional argument - if !querybuilder.IsZeroValue(opts[i].ForcedCompression) { - q = q.Arg("forcedCompression", opts[i].ForcedCompression) - } - // `mediaTypes` optional argument - if !querybuilder.IsZeroValue(opts[i].MediaTypes) { - q = q.Arg("mediaTypes", opts[i].MediaTypes) - } +// Returns true if the binding is null +func (r *Binding) IsNull(ctx context.Context) (bool, error) { + if r.isNull != nil { + return *r.isNull, nil } - q = q.Arg("path", path) + q := r.query.Select("isNull") var response bool @@ -581,88 +545,70 @@ func (r *Container) Export(ctx context.Context, path string, opts ...ContainerEx return response, q.Execute(ctx) } -// Retrieves the list of exposed ports. -// -// This includes ports already exposed by the image, even if not explicitly added with dagger. -func (r *Container) ExposedPorts(ctx context.Context) ([]Port, error) { - q := r.query.Select("exposedPorts") - - q = q.Select("id") - - type exposedPorts struct { - Id PortID +// The binding name +func (r *Binding) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil } + q := r.query.Select("name") - convert := func(fields []exposedPorts) []Port { - out := []Port{} - - for i := range fields { - val := Port{id: &fields[i].Id} - val.query = q.Root().Select("loadPortFromID").Arg("id", fields[i].Id) - out = append(out, val) - } - - return out - } - var response []exposedPorts + var response string q = q.Bind(&response) + return response, q.Execute(ctx) +} - err := q.Execute(ctx) - if err != nil { - return nil, err +// The binding type +func (r *Binding) TypeName(ctx context.Context) (string, error) { + if r.typeName != nil { + return *r.typeName, nil } + q := r.query.Select("typeName") - return convert(response), nil + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Retrieves a file at the given path. -// -// Mounts are included. -func (r *Container) File(path string) *File { - q := r.query.Select("file") - q = q.Arg("path", path) +// A directory whose contents persist across runs. +type CacheVolume struct { + query *querybuilder.Selection - return &File{ - query: q, - } + id *CacheVolumeID } -// Initializes this container from a pulled base image. -func (r *Container) From(address string) *Container { - q := r.query.Select("from") - q = q.Arg("address", address) - - return &Container{ +func (r *CacheVolume) WithGraphQLQuery(q *querybuilder.Selection) *CacheVolume { + return &CacheVolume{ query: q, } } -// A unique identifier for this Container. -func (r *Container) ID(ctx context.Context) (ContainerID, error) { +// A unique identifier for this CacheVolume. +func (r *CacheVolume) ID(ctx context.Context) (CacheVolumeID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response ContainerID + var response CacheVolumeID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *Container) XXX_GraphQLType() string { - return "Container" +func (r *CacheVolume) XXX_GraphQLType() string { + return "CacheVolume" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *Container) XXX_GraphQLIDType() string { - return "ContainerID" +func (r *CacheVolume) XXX_GraphQLIDType() string { + return "CacheVolumeID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *Container) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *CacheVolume) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -670,183 +616,213 @@ func (r *Container) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *Container) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *CacheVolume) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *Container) UnmarshalJSON(bs []byte) error { +func (r *CacheVolume) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadContainerFromID(ContainerID(id)) + *r = *dag.LoadCacheVolumeFromID(CacheVolumeID(id)) return nil } -// The unique image reference which can only be retrieved immediately after the 'Container.From' call. -func (r *Container) ImageRef(ctx context.Context) (string, error) { - if r.imageRef != nil { - return *r.imageRef, nil - } - q := r.query.Select("imageRef") - - var response string - - q = q.Bind(&response) - return response, q.Execute(ctx) -} +// Dagger Cloud configuration and state +type Cloud struct { + query *querybuilder.Selection -// ContainerImportOpts contains options for Container.Import -type ContainerImportOpts struct { - // Identifies the tag to import from the archive, if the archive bundles multiple tags. - Tag string + id *CloudID + traceURL *string } -// Reads the container from an OCI tarball. -func (r *Container) Import(source *File, opts ...ContainerImportOpts) *Container { - assertNotNil("source", source) - q := r.query.Select("import") - for i := len(opts) - 1; i >= 0; i-- { - // `tag` optional argument - if !querybuilder.IsZeroValue(opts[i].Tag) { - q = q.Arg("tag", opts[i].Tag) - } - } - q = q.Arg("source", source) - - return &Container{ +func (r *Cloud) WithGraphQLQuery(q *querybuilder.Selection) *Cloud { + return &Cloud{ query: q, } } -// Retrieves the value of the specified label. -func (r *Container) Label(ctx context.Context, name string) (string, error) { - if r.label != nil { - return *r.label, nil +// A unique identifier for this Cloud. +func (r *Cloud) ID(ctx context.Context) (CloudID, error) { + if r.id != nil { + return *r.id, nil } - q := r.query.Select("label") - q = q.Arg("name", name) + q := r.query.Select("id") - var response string + var response CloudID q = q.Bind(&response) return response, q.Execute(ctx) } -// Retrieves the list of labels passed to container. -func (r *Container) Labels(ctx context.Context) ([]Label, error) { - q := r.query.Select("labels") - - q = q.Select("id") - - type labels struct { - Id LabelID - } - - convert := func(fields []labels) []Label { - out := []Label{} +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Cloud) XXX_GraphQLType() string { + return "Cloud" +} - for i := range fields { - val := Label{id: &fields[i].Id} - val.query = q.Root().Select("loadLabelFromID").Arg("id", fields[i].Id) - out = append(out, val) - } +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Cloud) XXX_GraphQLIDType() string { + return "CloudID" +} - return out +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Cloud) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err } - var response []labels - - q = q.Bind(&response) + return string(id), nil +} - err := q.Execute(ctx) +func (r *Cloud) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } - - return convert(response), nil + return json.Marshal(id) +} +func (r *Cloud) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadCloudFromID(CloudID(id)) + return nil } -// Retrieves the list of paths where a directory is mounted. -func (r *Container) Mounts(ctx context.Context) ([]string, error) { - q := r.query.Select("mounts") +// The trace URL for the current session +func (r *Cloud) TraceURL(ctx context.Context) (string, error) { + if r.traceURL != nil { + return *r.traceURL, nil + } + q := r.query.Select("traceURL") - var response []string + var response string q = q.Bind(&response) return response, q.Execute(ctx) } -// ContainerPipelineOpts contains options for Container.Pipeline -type ContainerPipelineOpts struct { - // Description of the sub-pipeline. - Description string - // Labels to apply to the sub-pipeline. - Labels []PipelineLabel -} +// An OCI-compatible container, also known as a Docker container. +type Container struct { + query *querybuilder.Selection -// Creates a named sub-pipeline. -func (r *Container) Pipeline(name string, opts ...ContainerPipelineOpts) *Container { - q := r.query.Select("pipeline") - for i := len(opts) - 1; i >= 0; i-- { - // `description` optional argument - if !querybuilder.IsZeroValue(opts[i].Description) { - q = q.Arg("description", opts[i].Description) - } - // `labels` optional argument - if !querybuilder.IsZeroValue(opts[i].Labels) { - q = q.Arg("labels", opts[i].Labels) - } - } - q = q.Arg("name", name) + envVariable *string + exists *bool + exitCode *int + export *string + exportImage *Void + id *ContainerID + imageRef *string + label *string + platform *Platform + publish *string + stderr *string + stdout *string + sync *ContainerID + up *Void + user *string + workdir *string +} +type WithContainerFunc func(r *Container) *Container + +// With calls the provided function with current Container. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *Container) With(f WithContainerFunc) *Container { + return f(r) +} +func (r *Container) WithGraphQLQuery(q *querybuilder.Selection) *Container { return &Container{ query: q, } } -// The platform this container executes and publishes as. -func (r *Container) Platform(ctx context.Context) (Platform, error) { - if r.platform != nil { - return *r.platform, nil - } - q := r.query.Select("platform") +// ContainerAsServiceOpts contains options for Container.AsService +type ContainerAsServiceOpts struct { + // Command to run instead of the container's default command (e.g., ["go", "run", "main.go"]). + // + // If empty, the container's default command is used. + Args []string + // If the container has an entrypoint, prepend it to the args. + UseEntrypoint bool + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. + InsecureRootCapabilities bool + // Replace "${VAR}" or "$VAR" in the args according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool + // If set, skip the automatic init process injected into containers by default. + // + // This should only be used if the user requires that their exec process be the pid 1 process in the container. Otherwise it may result in unexpected behavior. + NoInit bool +} - var response Platform +// Turn the container into a Service. +// +// Be sure to set any exposed ports before this conversion. +func (r *Container) AsService(opts ...ContainerAsServiceOpts) *Service { + q := r.query.Select("asService") + for i := len(opts) - 1; i >= 0; i-- { + // `args` optional argument + if !querybuilder.IsZeroValue(opts[i].Args) { + q = q.Arg("args", opts[i].Args) + } + // `useEntrypoint` optional argument + if !querybuilder.IsZeroValue(opts[i].UseEntrypoint) { + q = q.Arg("useEntrypoint", opts[i].UseEntrypoint) + } + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + // `noInit` optional argument + if !querybuilder.IsZeroValue(opts[i].NoInit) { + q = q.Arg("noInit", opts[i].NoInit) + } + } - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Service{ + query: q, + } } -// ContainerPublishOpts contains options for Container.Publish -type ContainerPublishOpts struct { +// ContainerAsTarballOpts contains options for Container.AsTarball +type ContainerAsTarballOpts struct { // Identifiers for other platform specific containers. // - // Used for multi-platform image. + // Used for multi-platform images. PlatformVariants []*Container - // Force each layer of the published image to use the specified compression algorithm. + // Force each layer of the image to use the specified compression algorithm. // // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. ForcedCompression ImageLayerCompression - // Use the specified media types for the published image's layers. + // Use the specified media types for the image's layers. // - // Defaults to OCI, which is largely compatible with most recent registries, but Docker may be needed for older registries without OCI support. + // Defaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support. + // + // Default: OCIMediaTypes MediaTypes ImageMediaTypes } -// Publishes this container as a new image to the specified address. -// -// Publish returns a fully qualified ref. -// -// It can also publish platform variants. -func (r *Container) Publish(ctx context.Context, address string, opts ...ContainerPublishOpts) (string, error) { - if r.publish != nil { - return *r.publish, nil - } - q := r.query.Select("publish") +// Package the container state as an OCI image, and return it as a tar archive +func (r *Container) AsTarball(opts ...ContainerAsTarballOpts) *File { + q := r.query.Select("asTarball") for i := len(opts) - 1; i >= 0; i-- { // `platformVariants` optional argument if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { @@ -861,46 +837,120 @@ func (r *Container) Publish(ctx context.Context, address string, opts ...Contain q = q.Arg("mediaTypes", opts[i].MediaTypes) } } - q = q.Arg("address", address) - var response string + return &File{ + query: q, + } +} + +// ContainerBuildOpts contains options for Container.Build +type ContainerBuildOpts struct { + // Path to the Dockerfile to use. + // + // Default: "Dockerfile" + Dockerfile string + // Target build stage to build. + Target string + // Additional build arguments. + BuildArgs []BuildArg + // Secrets to pass to the build. + // + // They will be mounted at /run/secrets/[secret-name] in the build container + // + // They can be accessed in the Dockerfile using the "secret" mount type and mount path /run/secrets/[secret-name], e.g. RUN --mount=type=secret,id=my-secret curl [http://example.com?token=$(cat /run/secrets/my-secret)](http://example.com?token=$(cat /run/secrets/my-secret)) + Secrets []*Secret + // If set, skip the automatic init process injected into containers created by RUN statements. + // + // This should only be used if the user requires that their exec processes be the pid 1 process in the container. Otherwise it may result in unexpected behavior. + NoInit bool +} + +// Initializes this container from a Dockerfile build. +// +// Deprecated: Use `Directory.build` instead +func (r *Container) Build(context *Directory, opts ...ContainerBuildOpts) *Container { + assertNotNil("context", context) + q := r.query.Select("build") + for i := len(opts) - 1; i >= 0; i-- { + // `dockerfile` optional argument + if !querybuilder.IsZeroValue(opts[i].Dockerfile) { + q = q.Arg("dockerfile", opts[i].Dockerfile) + } + // `target` optional argument + if !querybuilder.IsZeroValue(opts[i].Target) { + q = q.Arg("target", opts[i].Target) + } + // `buildArgs` optional argument + if !querybuilder.IsZeroValue(opts[i].BuildArgs) { + q = q.Arg("buildArgs", opts[i].BuildArgs) + } + // `secrets` optional argument + if !querybuilder.IsZeroValue(opts[i].Secrets) { + q = q.Arg("secrets", opts[i].Secrets) + } + // `noInit` optional argument + if !querybuilder.IsZeroValue(opts[i].NoInit) { + q = q.Arg("noInit", opts[i].NoInit) + } + } + q = q.Arg("context", context) + + return &Container{ + query: q, + } +} + +// Return the container's default arguments. +func (r *Container) DefaultArgs(ctx context.Context) ([]string, error) { + q := r.query.Select("defaultArgs") + + var response []string q = q.Bind(&response) return response, q.Execute(ctx) } -// Retrieves this container's root filesystem. Mounts are not included. -func (r *Container) Rootfs() *Directory { - q := r.query.Select("rootfs") +// ContainerDirectoryOpts contains options for Container.Directory +type ContainerDirectoryOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieve a directory from the container's root filesystem +// +// Mounts are included. +func (r *Container) Directory(path string, opts ...ContainerDirectoryOpts) *Directory { + q := r.query.Select("directory") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) return &Directory{ query: q, } } -// The error stream of the last executed command. -// -// Will execute default command if none is set, or error if there's no default. -func (r *Container) Stderr(ctx context.Context) (string, error) { - if r.stderr != nil { - return *r.stderr, nil - } - q := r.query.Select("stderr") +// Return the container's OCI entrypoint. +func (r *Container) Entrypoint(ctx context.Context) ([]string, error) { + q := r.query.Select("entrypoint") - var response string + var response []string q = q.Bind(&response) return response, q.Execute(ctx) } -// The output stream of the last executed command. -// -// Will execute default command if none is set, or error if there's no default. -func (r *Container) Stdout(ctx context.Context) (string, error) { - if r.stdout != nil { - return *r.stdout, nil +// Retrieves the value of the specified environment variable. +func (r *Container) EnvVariable(ctx context.Context, name string) (string, error) { + if r.envVariable != nil { + return *r.envVariable, nil } - q := r.query.Select("stdout") + q := r.query.Select("envVariable") + q = q.Arg("name", name) var response string @@ -908,309 +958,357 @@ func (r *Container) Stdout(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// Forces evaluation of the pipeline in the engine. -// -// It doesn't run the default command if no exec has been set. -func (r *Container) Sync(ctx context.Context) (*Container, error) { - q := r.query.Select("sync") +// Retrieves the list of environment variables passed to commands. +func (r *Container) EnvVariables(ctx context.Context) ([]EnvVariable, error) { + q := r.query.Select("envVariables") - return r, q.Execute(ctx) -} + q = q.Select("id") -// ContainerTerminalOpts contains options for Container.Terminal -type ContainerTerminalOpts struct { - // If set, override the container's default terminal command and invoke these command arguments instead. - Cmd []string - // Provides Dagger access to the executed command. - // - // Do not use this option unless you trust the command being executed; the command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM. - ExperimentalPrivilegedNesting bool - // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. - InsecureRootCapabilities bool -} + type envVariables struct { + Id EnvVariableID + } -// Return an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default). -func (r *Container) Terminal(opts ...ContainerTerminalOpts) *Terminal { - q := r.query.Select("terminal") - for i := len(opts) - 1; i >= 0; i-- { - // `cmd` optional argument - if !querybuilder.IsZeroValue(opts[i].Cmd) { - q = q.Arg("cmd", opts[i].Cmd) - } - // `experimentalPrivilegedNesting` optional argument - if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { - q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) - } - // `insecureRootCapabilities` optional argument - if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { - q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + convert := func(fields []envVariables) []EnvVariable { + out := []EnvVariable{} + + for i := range fields { + val := EnvVariable{id: &fields[i].Id} + val.query = q.Root().Select("loadEnvVariableFromID").Arg("id", fields[i].Id) + out = append(out, val) } + + return out } + var response []envVariables - return &Terminal{ - query: q, + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err } + + return convert(response), nil } -// Retrieves the user to be set for all commands. -func (r *Container) User(ctx context.Context) (string, error) { - if r.user != nil { - return *r.user, nil +// ContainerExistsOpts contains options for Container.Exists +type ContainerExistsOpts struct { + // If specified, also validate the type of file (e.g. "REGULAR_TYPE", "DIRECTORY_TYPE", or "SYMLINK_TYPE"). + ExpectedType ExistsType + // If specified, do not follow symlinks. + DoNotFollowSymlinks bool +} + +// check if a file or directory exists +func (r *Container) Exists(ctx context.Context, path string, opts ...ContainerExistsOpts) (bool, error) { + if r.exists != nil { + return *r.exists, nil } - q := r.query.Select("user") + q := r.query.Select("exists") + for i := len(opts) - 1; i >= 0; i-- { + // `expectedType` optional argument + if !querybuilder.IsZeroValue(opts[i].ExpectedType) { + q = q.Arg("expectedType", opts[i].ExpectedType) + } + // `doNotFollowSymlinks` optional argument + if !querybuilder.IsZeroValue(opts[i].DoNotFollowSymlinks) { + q = q.Arg("doNotFollowSymlinks", opts[i].DoNotFollowSymlinks) + } + } + q = q.Arg("path", path) - var response string + var response bool q = q.Bind(&response) return response, q.Execute(ctx) } -// Configures default arguments for future commands. -func (r *Container) WithDefaultArgs(args []string) *Container { - q := r.query.Select("withDefaultArgs") - q = q.Arg("args", args) +// The exit code of the last executed command +// +// Returns an error if no command was executed +func (r *Container) ExitCode(ctx context.Context) (int, error) { + if r.exitCode != nil { + return *r.exitCode, nil + } + q := r.query.Select("exitCode") + + var response int + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// EXPERIMENTAL API! Subject to change/removal at any time. +// +// Configures all available GPUs on the host to be accessible to this container. +// +// This currently works for Nvidia devices only. +func (r *Container) ExperimentalWithAllGPUs() *Container { + q := r.query.Select("experimentalWithAllGPUs") return &Container{ query: q, } } -// ContainerWithDefaultTerminalCmdOpts contains options for Container.WithDefaultTerminalCmd -type ContainerWithDefaultTerminalCmdOpts struct { - // Provides Dagger access to the executed command. +// EXPERIMENTAL API! Subject to change/removal at any time. +// +// Configures the provided list of devices to be accessible to this container. +// +// This currently works for Nvidia devices only. +func (r *Container) ExperimentalWithGPU(devices []string) *Container { + q := r.query.Select("experimentalWithGPU") + q = q.Arg("devices", devices) + + return &Container{ + query: q, + } +} + +// ContainerExportOpts contains options for Container.Export +type ContainerExportOpts struct { + // Identifiers for other platform specific containers. // - // Do not use this option unless you trust the command being executed; the command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM. - ExperimentalPrivilegedNesting bool - // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. - InsecureRootCapabilities bool + // Used for multi-platform image. + PlatformVariants []*Container + // Force each layer of the exported image to use the specified compression algorithm. + // + // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. + ForcedCompression ImageLayerCompression + // Use the specified media types for the exported image's layers. + // + // Defaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support. + // + // Default: OCIMediaTypes + MediaTypes ImageMediaTypes + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool } -// Set the default command to invoke for the container's terminal API. -func (r *Container) WithDefaultTerminalCmd(args []string, opts ...ContainerWithDefaultTerminalCmdOpts) *Container { - q := r.query.Select("withDefaultTerminalCmd") +// Writes the container as an OCI tarball to the destination file path on the host. +// +// It can also export platform variants. +func (r *Container) Export(ctx context.Context, path string, opts ...ContainerExportOpts) (string, error) { + if r.export != nil { + return *r.export, nil + } + q := r.query.Select("export") for i := len(opts) - 1; i >= 0; i-- { - // `experimentalPrivilegedNesting` optional argument - if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { - q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + // `platformVariants` optional argument + if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { + q = q.Arg("platformVariants", opts[i].PlatformVariants) } - // `insecureRootCapabilities` optional argument - if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { - q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + // `forcedCompression` optional argument + if !querybuilder.IsZeroValue(opts[i].ForcedCompression) { + q = q.Arg("forcedCompression", opts[i].ForcedCompression) + } + // `mediaTypes` optional argument + if !querybuilder.IsZeroValue(opts[i].MediaTypes) { + q = q.Arg("mediaTypes", opts[i].MediaTypes) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) } } - q = q.Arg("args", args) + q = q.Arg("path", path) - return &Container{ - query: q, - } + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// ContainerWithDirectoryOpts contains options for Container.WithDirectory -type ContainerWithDirectoryOpts struct { - // Patterns to exclude in the written directory (e.g. ["node_modules/**", ".gitignore", ".git/"]). - Exclude []string - // Patterns to include in the written directory (e.g. ["*.go", "go.mod", "go.sum"]). - Include []string - // A user:group to set for the directory and its contents. +// ContainerExportImageOpts contains options for Container.ExportImage +type ContainerExportImageOpts struct { + // Identifiers for other platform specific containers. // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // Used for multi-platform image. + PlatformVariants []*Container + // Force each layer of the exported image to use the specified compression algorithm. // - // If the group is omitted, it defaults to the same as the user. - Owner string + // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. + ForcedCompression ImageLayerCompression + // Use the specified media types for the exported image's layers. + // + // Defaults to OCI, which is largely compatible with most recent container runtimes, but Docker may be needed for older runtimes without OCI support. + // + // Default: OCIMediaTypes + MediaTypes ImageMediaTypes } -// Retrieves this container plus a directory written at the given path. -func (r *Container) WithDirectory(path string, directory *Directory, opts ...ContainerWithDirectoryOpts) *Container { - assertNotNil("directory", directory) - q := r.query.Select("withDirectory") +// Exports the container as an image to the host's container image store. +func (r *Container) ExportImage(ctx context.Context, name string, opts ...ContainerExportImageOpts) error { + if r.exportImage != nil { + return nil + } + q := r.query.Select("exportImage") for i := len(opts) - 1; i >= 0; i-- { - // `exclude` optional argument - if !querybuilder.IsZeroValue(opts[i].Exclude) { - q = q.Arg("exclude", opts[i].Exclude) + // `platformVariants` optional argument + if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { + q = q.Arg("platformVariants", opts[i].PlatformVariants) } - // `include` optional argument - if !querybuilder.IsZeroValue(opts[i].Include) { - q = q.Arg("include", opts[i].Include) + // `forcedCompression` optional argument + if !querybuilder.IsZeroValue(opts[i].ForcedCompression) { + q = q.Arg("forcedCompression", opts[i].ForcedCompression) } - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) + // `mediaTypes` optional argument + if !querybuilder.IsZeroValue(opts[i].MediaTypes) { + q = q.Arg("mediaTypes", opts[i].MediaTypes) } } - q = q.Arg("path", path) - q = q.Arg("directory", directory) + q = q.Arg("name", name) - return &Container{ - query: q, - } + return q.Execute(ctx) } -// ContainerWithEntrypointOpts contains options for Container.WithEntrypoint -type ContainerWithEntrypointOpts struct { - // Don't remove the default arguments when setting the entrypoint. - KeepDefaultArgs bool -} +// Retrieves the list of exposed ports. +// +// This includes ports already exposed by the image, even if not explicitly added with dagger. +func (r *Container) ExposedPorts(ctx context.Context) ([]Port, error) { + q := r.query.Select("exposedPorts") -// Retrieves this container but with a different command entrypoint. -func (r *Container) WithEntrypoint(args []string, opts ...ContainerWithEntrypointOpts) *Container { - q := r.query.Select("withEntrypoint") - for i := len(opts) - 1; i >= 0; i-- { - // `keepDefaultArgs` optional argument - if !querybuilder.IsZeroValue(opts[i].KeepDefaultArgs) { - q = q.Arg("keepDefaultArgs", opts[i].KeepDefaultArgs) + q = q.Select("id") + + type exposedPorts struct { + Id PortID + } + + convert := func(fields []exposedPorts) []Port { + out := []Port{} + + for i := range fields { + val := Port{id: &fields[i].Id} + val.query = q.Root().Select("loadPortFromID").Arg("id", fields[i].Id) + out = append(out, val) } + + return out } - q = q.Arg("args", args) + var response []exposedPorts - return &Container{ - query: q, + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err } + + return convert(response), nil } -// ContainerWithEnvVariableOpts contains options for Container.WithEnvVariable -type ContainerWithEnvVariableOpts struct { - // Replace `${VAR}` or `$VAR` in the value according to the current environment variables defined in the container (e.g., "/opt/bin:$PATH"). +// ContainerFileOpts contains options for Container.File +type ContainerFileOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). Expand bool } -// Retrieves this container plus the given environment variable. -func (r *Container) WithEnvVariable(name string, value string, opts ...ContainerWithEnvVariableOpts) *Container { - q := r.query.Select("withEnvVariable") +// Retrieves a file at the given path. +// +// Mounts are included. +func (r *Container) File(path string, opts ...ContainerFileOpts) *File { + q := r.query.Select("file") for i := len(opts) - 1; i >= 0; i-- { // `expand` optional argument if !querybuilder.IsZeroValue(opts[i].Expand) { q = q.Arg("expand", opts[i].Expand) } } - q = q.Arg("name", name) - q = q.Arg("value", value) + q = q.Arg("path", path) - return &Container{ + return &File{ query: q, } } -// ContainerWithExecOpts contains options for Container.WithExec -type ContainerWithExecOpts struct { - // If the container has an entrypoint, ignore it for args rather than using it to wrap them. - SkipEntrypoint bool - // Content to write to the command's standard input before closing (e.g., "Hello world"). - Stdin string - // Redirect the command's standard output to a file in the container (e.g., "/tmp/stdout"). - RedirectStdout string - // Redirect the command's standard error to a file in the container (e.g., "/tmp/stderr"). - RedirectStderr string - // Provides Dagger access to the executed command. - // - // Do not use this option unless you trust the command being executed; the command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM. - ExperimentalPrivilegedNesting bool - // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. - InsecureRootCapabilities bool -} - -// Retrieves this container after executing the specified command inside it. -func (r *Container) WithExec(args []string, opts ...ContainerWithExecOpts) *Container { - q := r.query.Select("withExec") - for i := len(opts) - 1; i >= 0; i-- { - // `skipEntrypoint` optional argument - if !querybuilder.IsZeroValue(opts[i].SkipEntrypoint) { - q = q.Arg("skipEntrypoint", opts[i].SkipEntrypoint) - } - // `stdin` optional argument - if !querybuilder.IsZeroValue(opts[i].Stdin) { - q = q.Arg("stdin", opts[i].Stdin) - } - // `redirectStdout` optional argument - if !querybuilder.IsZeroValue(opts[i].RedirectStdout) { - q = q.Arg("redirectStdout", opts[i].RedirectStdout) - } - // `redirectStderr` optional argument - if !querybuilder.IsZeroValue(opts[i].RedirectStderr) { - q = q.Arg("redirectStderr", opts[i].RedirectStderr) - } - // `experimentalPrivilegedNesting` optional argument - if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { - q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) - } - // `insecureRootCapabilities` optional argument - if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { - q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) - } - } - q = q.Arg("args", args) +// Download a container image, and apply it to the container state. All previous state will be lost. +func (r *Container) From(address string) *Container { + q := r.query.Select("from") + q = q.Arg("address", address) return &Container{ query: q, } } -// ContainerWithExposedPortOpts contains options for Container.WithExposedPort -type ContainerWithExposedPortOpts struct { - // Transport layer network protocol - Protocol NetworkProtocol - // Optional port description - Description string - // Skip the health check when run as a service. - ExperimentalSkipHealthcheck bool +// A unique identifier for this Container. +func (r *Container) ID(ctx context.Context) (ContainerID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response ContainerID + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Expose a network port. -// -// Exposed ports serve two purposes: -// -// - For health checks and introspection, when running services -// -// - For setting the EXPOSE OCI field when publishing the container -func (r *Container) WithExposedPort(port int, opts ...ContainerWithExposedPortOpts) *Container { - q := r.query.Select("withExposedPort") - for i := len(opts) - 1; i >= 0; i-- { - // `protocol` optional argument - if !querybuilder.IsZeroValue(opts[i].Protocol) { - q = q.Arg("protocol", opts[i].Protocol) - } - // `description` optional argument - if !querybuilder.IsZeroValue(opts[i].Description) { - q = q.Arg("description", opts[i].Description) - } - // `experimentalSkipHealthcheck` optional argument - if !querybuilder.IsZeroValue(opts[i].ExperimentalSkipHealthcheck) { - q = q.Arg("experimentalSkipHealthcheck", opts[i].ExperimentalSkipHealthcheck) - } +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Container) XXX_GraphQLType() string { + return "Container" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Container) XXX_GraphQLIDType() string { + return "ContainerID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Container) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err } - q = q.Arg("port", port) + return string(id), nil +} - return &Container{ - query: q, +func (r *Container) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *Container) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err } + *r = *dag.LoadContainerFromID(ContainerID(id)) + return nil } -// ContainerWithFileOpts contains options for Container.WithFile -type ContainerWithFileOpts struct { - // Permission given to the copied file (e.g., 0600). - Permissions int - // A user:group to set for the file. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string +// The unique image reference which can only be retrieved immediately after the 'Container.From' call. +func (r *Container) ImageRef(ctx context.Context) (string, error) { + if r.imageRef != nil { + return *r.imageRef, nil + } + q := r.query.Select("imageRef") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Retrieves this container plus the contents of the given file copied to the given path. -func (r *Container) WithFile(path string, source *File, opts ...ContainerWithFileOpts) *Container { +// ContainerImportOpts contains options for Container.Import +type ContainerImportOpts struct { + // Identifies the tag to import from the archive, if the archive bundles multiple tags. + Tag string +} + +// Reads the container from an OCI tarball. +func (r *Container) Import(source *File, opts ...ContainerImportOpts) *Container { assertNotNil("source", source) - q := r.query.Select("withFile") + q := r.query.Select("import") for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) + // `tag` optional argument + if !querybuilder.IsZeroValue(opts[i].Tag) { + q = q.Arg("tag", opts[i].Tag) } } - q = q.Arg("path", path) q = q.Arg("source", source) return &Container{ @@ -1218,530 +1316,2873 @@ func (r *Container) WithFile(path string, source *File, opts ...ContainerWithFil } } -// ContainerWithFilesOpts contains options for Container.WithFiles -type ContainerWithFilesOpts struct { - // Permission given to the copied files (e.g., 0600). - Permissions int - // A user:group to set for the files. +// Retrieves the value of the specified label. +func (r *Container) Label(ctx context.Context, name string) (string, error) { + if r.label != nil { + return *r.label, nil + } + q := r.query.Select("label") + q = q.Arg("name", name) + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Retrieves the list of labels passed to container. +func (r *Container) Labels(ctx context.Context) ([]Label, error) { + q := r.query.Select("labels") + + q = q.Select("id") + + type labels struct { + Id LabelID + } + + convert := func(fields []labels) []Label { + out := []Label{} + + for i := range fields { + val := Label{id: &fields[i].Id} + val.query = q.Root().Select("loadLabelFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []labels + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil +} + +// Retrieves the list of paths where a directory is mounted. +func (r *Container) Mounts(ctx context.Context) ([]string, error) { + q := r.query.Select("mounts") + + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The platform this container executes and publishes as. +func (r *Container) Platform(ctx context.Context) (Platform, error) { + if r.platform != nil { + return *r.platform, nil + } + q := r.query.Select("platform") + + var response Platform + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// ContainerPublishOpts contains options for Container.Publish +type ContainerPublishOpts struct { + // Identifiers for other platform specific containers. // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // Used for multi-platform image. + PlatformVariants []*Container + // Force each layer of the published image to use the specified compression algorithm. // - // If the group is omitted, it defaults to the same as the user. - Owner string + // If this is unset, then if a layer already has a compressed blob in the engine's cache, that will be used (this can result in a mix of compression algorithms for different layers). If this is unset and a layer has no compressed blob in the engine's cache, then it will be compressed using Gzip. + ForcedCompression ImageLayerCompression + // Use the specified media types for the published image's layers. + // + // Defaults to "OCI", which is compatible with most recent registries, but "Docker" may be needed for older registries without OCI support. + // + // Default: OCIMediaTypes + MediaTypes ImageMediaTypes } -// Retrieves this container plus the contents of the given files copied to the given path. -func (r *Container) WithFiles(path string, sources []*File, opts ...ContainerWithFilesOpts) *Container { - q := r.query.Select("withFiles") +// Package the container state as an OCI image, and publish it to a registry +// +// Returns the fully qualified address of the published image, with digest +func (r *Container) Publish(ctx context.Context, address string, opts ...ContainerPublishOpts) (string, error) { + if r.publish != nil { + return *r.publish, nil + } + q := r.query.Select("publish") for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) + // `platformVariants` optional argument + if !querybuilder.IsZeroValue(opts[i].PlatformVariants) { + q = q.Arg("platformVariants", opts[i].PlatformVariants) } - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) + // `forcedCompression` optional argument + if !querybuilder.IsZeroValue(opts[i].ForcedCompression) { + q = q.Arg("forcedCompression", opts[i].ForcedCompression) + } + // `mediaTypes` optional argument + if !querybuilder.IsZeroValue(opts[i].MediaTypes) { + q = q.Arg("mediaTypes", opts[i].MediaTypes) } } - q = q.Arg("path", path) - q = q.Arg("sources", sources) + q = q.Arg("address", address) + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Return a snapshot of the container's root filesystem. The snapshot can be modified then written back using withRootfs. Use that method for filesystem modifications. +func (r *Container) Rootfs() *Directory { + q := r.query.Select("rootfs") + + return &Directory{ + query: q, + } +} + +// The buffered standard error stream of the last executed command +// +// Returns an error if no command was executed +func (r *Container) Stderr(ctx context.Context) (string, error) { + if r.stderr != nil { + return *r.stderr, nil + } + q := r.query.Select("stderr") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The buffered standard output stream of the last executed command +// +// Returns an error if no command was executed +func (r *Container) Stdout(ctx context.Context) (string, error) { + if r.stdout != nil { + return *r.stdout, nil + } + q := r.query.Select("stdout") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Forces evaluation of the pipeline in the engine. +// +// It doesn't run the default command if no exec has been set. +func (r *Container) Sync(ctx context.Context) (*Container, error) { + q := r.query.Select("sync") + + var id ContainerID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Container{ + query: q.Root().Select("loadContainerFromID").Arg("id", id), + }, nil +} + +// ContainerTerminalOpts contains options for Container.Terminal +type ContainerTerminalOpts struct { + // If set, override the container's default terminal command and invoke these command arguments instead. + Cmd []string + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. + InsecureRootCapabilities bool +} + +// Opens an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default). +func (r *Container) Terminal(opts ...ContainerTerminalOpts) *Container { + q := r.query.Select("terminal") + for i := len(opts) - 1; i >= 0; i-- { + // `cmd` optional argument + if !querybuilder.IsZeroValue(opts[i].Cmd) { + q = q.Arg("cmd", opts[i].Cmd) + } + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + } + + return &Container{ + query: q, + } +} + +// ContainerUpOpts contains options for Container.Up +type ContainerUpOpts struct { + // Bind each tunnel port to a random port on the host. + Random bool + // List of frontend/backend port mappings to forward. + // + // Frontend is the port accepting traffic on the host, backend is the service port. + Ports []PortForward + // Command to run instead of the container's default command (e.g., ["go", "run", "main.go"]). + // + // If empty, the container's default command is used. + Args []string + // If the container has an entrypoint, prepend it to the args. + UseEntrypoint bool + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. + InsecureRootCapabilities bool + // Replace "${VAR}" or "$VAR" in the args according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool + // If set, skip the automatic init process injected into containers by default. + // + // This should only be used if the user requires that their exec process be the pid 1 process in the container. Otherwise it may result in unexpected behavior. + NoInit bool +} + +// Starts a Service and creates a tunnel that forwards traffic from the caller's network to that service. +// +// Be sure to set any exposed ports before calling this api. +func (r *Container) Up(ctx context.Context, opts ...ContainerUpOpts) error { + if r.up != nil { + return nil + } + q := r.query.Select("up") + for i := len(opts) - 1; i >= 0; i-- { + // `random` optional argument + if !querybuilder.IsZeroValue(opts[i].Random) { + q = q.Arg("random", opts[i].Random) + } + // `ports` optional argument + if !querybuilder.IsZeroValue(opts[i].Ports) { + q = q.Arg("ports", opts[i].Ports) + } + // `args` optional argument + if !querybuilder.IsZeroValue(opts[i].Args) { + q = q.Arg("args", opts[i].Args) + } + // `useEntrypoint` optional argument + if !querybuilder.IsZeroValue(opts[i].UseEntrypoint) { + q = q.Arg("useEntrypoint", opts[i].UseEntrypoint) + } + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + // `noInit` optional argument + if !querybuilder.IsZeroValue(opts[i].NoInit) { + q = q.Arg("noInit", opts[i].NoInit) + } + } + + return q.Execute(ctx) +} + +// Retrieves the user to be set for all commands. +func (r *Container) User(ctx context.Context) (string, error) { + if r.user != nil { + return *r.user, nil + } + q := r.query.Select("user") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Retrieves this container plus the given OCI anotation. +func (r *Container) WithAnnotation(name string, value string) *Container { + q := r.query.Select("withAnnotation") + q = q.Arg("name", name) + q = q.Arg("value", value) + + return &Container{ + query: q, + } +} + +// Configures default arguments for future commands. Like CMD in Dockerfile. +func (r *Container) WithDefaultArgs(args []string) *Container { + q := r.query.Select("withDefaultArgs") + q = q.Arg("args", args) + + return &Container{ + query: q, + } +} + +// ContainerWithDefaultTerminalCmdOpts contains options for Container.WithDefaultTerminalCmd +type ContainerWithDefaultTerminalCmdOpts struct { + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. + InsecureRootCapabilities bool +} + +// Set the default command to invoke for the container's terminal API. +func (r *Container) WithDefaultTerminalCmd(args []string, opts ...ContainerWithDefaultTerminalCmdOpts) *Container { + q := r.query.Select("withDefaultTerminalCmd") + for i := len(opts) - 1; i >= 0; i-- { + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + } + q = q.Arg("args", args) + + return &Container{ + query: q, + } +} + +// ContainerWithDirectoryOpts contains options for Container.WithDirectory +type ContainerWithDirectoryOpts struct { + // Patterns to exclude in the written directory (e.g. ["node_modules/**", ".gitignore", ".git/"]). + Exclude []string + // Patterns to include in the written directory (e.g. ["*.go", "go.mod", "go.sum"]). + Include []string + // A user:group to set for the directory and its contents. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Return a new container snapshot, with a directory added to its filesystem +func (r *Container) WithDirectory(path string, directory *Directory, opts ...ContainerWithDirectoryOpts) *Container { + assertNotNil("directory", directory) + q := r.query.Select("withDirectory") + for i := len(opts) - 1; i >= 0; i-- { + // `exclude` optional argument + if !querybuilder.IsZeroValue(opts[i].Exclude) { + q = q.Arg("exclude", opts[i].Exclude) + } + // `include` optional argument + if !querybuilder.IsZeroValue(opts[i].Include) { + q = q.Arg("include", opts[i].Include) + } + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("directory", directory) + + return &Container{ + query: q, + } +} + +// ContainerWithEntrypointOpts contains options for Container.WithEntrypoint +type ContainerWithEntrypointOpts struct { + // Don't reset the default arguments when setting the entrypoint. By default it is reset, since entrypoint and default args are often tightly coupled. + KeepDefaultArgs bool +} + +// Set an OCI-style entrypoint. It will be included in the container's OCI configuration. Note, withExec ignores the entrypoint by default. +func (r *Container) WithEntrypoint(args []string, opts ...ContainerWithEntrypointOpts) *Container { + q := r.query.Select("withEntrypoint") + for i := len(opts) - 1; i >= 0; i-- { + // `keepDefaultArgs` optional argument + if !querybuilder.IsZeroValue(opts[i].KeepDefaultArgs) { + q = q.Arg("keepDefaultArgs", opts[i].KeepDefaultArgs) + } + } + q = q.Arg("args", args) + + return &Container{ + query: q, + } +} + +// ContainerWithEnvVariableOpts contains options for Container.WithEnvVariable +type ContainerWithEnvVariableOpts struct { + // Replace "${VAR}" or "$VAR" in the value according to the current environment variables defined in the container (e.g. "/opt/bin:$PATH"). + Expand bool +} + +// Set a new environment variable in the container. +func (r *Container) WithEnvVariable(name string, value string, opts ...ContainerWithEnvVariableOpts) *Container { + q := r.query.Select("withEnvVariable") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("name", name) + q = q.Arg("value", value) + + return &Container{ + query: q, + } +} + +// ContainerWithExecOpts contains options for Container.WithExec +type ContainerWithExecOpts struct { + // Apply the OCI entrypoint, if present, by prepending it to the args. Ignored by default. + UseEntrypoint bool + // Content to write to the command's standard input. Example: "Hello world") + Stdin string + // Redirect the command's standard input from a file in the container. Example: "./stdin.txt" + RedirectStdin string + // Redirect the command's standard output to a file in the container. Example: "./stdout.txt" + RedirectStdout string + // Redirect the command's standard error to a file in the container. Example: "./stderr.txt" + RedirectStderr string + // Exit codes this command is allowed to exit with without error + // + // Default: SUCCESS + Expect ReturnType + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. Like --privileged in Docker + // + // DANGER: this grants the command full access to the host system. Only use when 1) you trust the command being executed and 2) you specifically need this level of access. + InsecureRootCapabilities bool + // Replace "${VAR}" or "$VAR" in the args according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool + // Skip the automatic init process injected into containers by default. + // + // Only use this if you specifically need the command to be pid 1 in the container. Otherwise it may result in unexpected behavior. If you're not sure, you don't need this. + NoInit bool +} + +// Execute a command in the container, and return a new snapshot of the container state after execution. +func (r *Container) WithExec(args []string, opts ...ContainerWithExecOpts) *Container { + q := r.query.Select("withExec") + for i := len(opts) - 1; i >= 0; i-- { + // `useEntrypoint` optional argument + if !querybuilder.IsZeroValue(opts[i].UseEntrypoint) { + q = q.Arg("useEntrypoint", opts[i].UseEntrypoint) + } + // `stdin` optional argument + if !querybuilder.IsZeroValue(opts[i].Stdin) { + q = q.Arg("stdin", opts[i].Stdin) + } + // `redirectStdin` optional argument + if !querybuilder.IsZeroValue(opts[i].RedirectStdin) { + q = q.Arg("redirectStdin", opts[i].RedirectStdin) + } + // `redirectStdout` optional argument + if !querybuilder.IsZeroValue(opts[i].RedirectStdout) { + q = q.Arg("redirectStdout", opts[i].RedirectStdout) + } + // `redirectStderr` optional argument + if !querybuilder.IsZeroValue(opts[i].RedirectStderr) { + q = q.Arg("redirectStderr", opts[i].RedirectStderr) + } + // `expect` optional argument + if !querybuilder.IsZeroValue(opts[i].Expect) { + q = q.Arg("expect", opts[i].Expect) + } + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + // `noInit` optional argument + if !querybuilder.IsZeroValue(opts[i].NoInit) { + q = q.Arg("noInit", opts[i].NoInit) + } + } + q = q.Arg("args", args) + + return &Container{ + query: q, + } +} + +// ContainerWithExposedPortOpts contains options for Container.WithExposedPort +type ContainerWithExposedPortOpts struct { + // Network protocol. Example: "tcp" + // + // Default: TCP + Protocol NetworkProtocol + // Port description. Example: "payment API endpoint" + Description string + // Skip the health check when run as a service. + ExperimentalSkipHealthcheck bool +} + +// Expose a network port. Like EXPOSE in Dockerfile (but with healthcheck support) +// +// Exposed ports serve two purposes: +// +// - For health checks and introspection, when running services +// +// - For setting the EXPOSE OCI field when publishing the container +func (r *Container) WithExposedPort(port int, opts ...ContainerWithExposedPortOpts) *Container { + q := r.query.Select("withExposedPort") + for i := len(opts) - 1; i >= 0; i-- { + // `protocol` optional argument + if !querybuilder.IsZeroValue(opts[i].Protocol) { + q = q.Arg("protocol", opts[i].Protocol) + } + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + // `experimentalSkipHealthcheck` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalSkipHealthcheck) { + q = q.Arg("experimentalSkipHealthcheck", opts[i].ExperimentalSkipHealthcheck) + } + } + q = q.Arg("port", port) + + return &Container{ + query: q, + } +} + +// ContainerWithFileOpts contains options for Container.WithFile +type ContainerWithFileOpts struct { + // Permissions of the new file. Example: 0600 + Permissions int + // A user:group to set for the file. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Return a container snapshot with a file added +func (r *Container) WithFile(path string, source *File, opts ...ContainerWithFileOpts) *Container { + assertNotNil("source", source) + q := r.query.Select("withFile") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Container{ + query: q, + } +} + +// ContainerWithFilesOpts contains options for Container.WithFiles +type ContainerWithFilesOpts struct { + // Permission given to the copied files (e.g., 0600). + Permissions int + // A user:group to set for the files. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Retrieves this container plus the contents of the given files copied to the given path. +func (r *Container) WithFiles(path string, sources []*File, opts ...ContainerWithFilesOpts) *Container { + q := r.query.Select("withFiles") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("sources", sources) + + return &Container{ + query: q, + } +} + +// Retrieves this container plus the given label. +func (r *Container) WithLabel(name string, value string) *Container { + q := r.query.Select("withLabel") + q = q.Arg("name", name) + q = q.Arg("value", value) + + return &Container{ + query: q, + } +} + +// ContainerWithMountedCacheOpts contains options for Container.WithMountedCache +type ContainerWithMountedCacheOpts struct { + // Identifier of the directory to use as the cache volume's root. + Source *Directory + // Sharing mode of the cache volume. + // + // Default: SHARED + Sharing CacheSharingMode + // A user:group to set for the mounted cache directory. + // + // Note that this changes the ownership of the specified mount along with the initial filesystem provided by source (if any). It does not have any effect if/when the cache has already been created. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container plus a cache volume mounted at the given path. +func (r *Container) WithMountedCache(path string, cache *CacheVolume, opts ...ContainerWithMountedCacheOpts) *Container { + assertNotNil("cache", cache) + q := r.query.Select("withMountedCache") + for i := len(opts) - 1; i >= 0; i-- { + // `source` optional argument + if !querybuilder.IsZeroValue(opts[i].Source) { + q = q.Arg("source", opts[i].Source) + } + // `sharing` optional argument + if !querybuilder.IsZeroValue(opts[i].Sharing) { + q = q.Arg("sharing", opts[i].Sharing) + } + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("cache", cache) + + return &Container{ + query: q, + } +} + +// ContainerWithMountedDirectoryOpts contains options for Container.WithMountedDirectory +type ContainerWithMountedDirectoryOpts struct { + // A user:group to set for the mounted directory and its contents. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container plus a directory mounted at the given path. +func (r *Container) WithMountedDirectory(path string, source *Directory, opts ...ContainerWithMountedDirectoryOpts) *Container { + assertNotNil("source", source) + q := r.query.Select("withMountedDirectory") + for i := len(opts) - 1; i >= 0; i-- { + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Container{ + query: q, + } +} + +// ContainerWithMountedFileOpts contains options for Container.WithMountedFile +type ContainerWithMountedFileOpts struct { + // A user or user:group to set for the mounted file. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Retrieves this container plus a file mounted at the given path. +func (r *Container) WithMountedFile(path string, source *File, opts ...ContainerWithMountedFileOpts) *Container { + assertNotNil("source", source) + q := r.query.Select("withMountedFile") + for i := len(opts) - 1; i >= 0; i-- { + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Container{ + query: q, + } +} + +// ContainerWithMountedSecretOpts contains options for Container.WithMountedSecret +type ContainerWithMountedSecretOpts struct { + // A user:group to set for the mounted secret. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Permission given to the mounted secret (e.g., 0600). + // + // This option requires an owner to be set to be active. + // + // Default: 256 + Mode int + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container plus a secret mounted into a file at the given path. +func (r *Container) WithMountedSecret(path string, source *Secret, opts ...ContainerWithMountedSecretOpts) *Container { + assertNotNil("source", source) + q := r.query.Select("withMountedSecret") + for i := len(opts) - 1; i >= 0; i-- { + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `mode` optional argument + if !querybuilder.IsZeroValue(opts[i].Mode) { + q = q.Arg("mode", opts[i].Mode) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Container{ + query: q, + } +} + +// ContainerWithMountedTempOpts contains options for Container.WithMountedTemp +type ContainerWithMountedTempOpts struct { + // Size of the temporary directory in bytes. + Size int + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container plus a temporary directory mounted at the given path. Any writes will be ephemeral to a single withExec call; they will not be persisted to subsequent withExecs. +func (r *Container) WithMountedTemp(path string, opts ...ContainerWithMountedTempOpts) *Container { + q := r.query.Select("withMountedTemp") + for i := len(opts) - 1; i >= 0; i-- { + // `size` optional argument + if !querybuilder.IsZeroValue(opts[i].Size) { + q = q.Arg("size", opts[i].Size) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// ContainerWithNewFileOpts contains options for Container.WithNewFile +type ContainerWithNewFileOpts struct { + // Permissions of the new file. Example: 0600 + // + // Default: 420 + Permissions int + // A user:group to set for the file. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Return a new container snapshot, with a file added to its filesystem with text content +func (r *Container) WithNewFile(path string, contents string, opts ...ContainerWithNewFileOpts) *Container { + q := r.query.Select("withNewFile") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("contents", contents) + + return &Container{ + query: q, + } +} + +// Attach credentials for future publishing to a registry. Use in combination with publish +func (r *Container) WithRegistryAuth(address string, username string, secret *Secret) *Container { + assertNotNil("secret", secret) + q := r.query.Select("withRegistryAuth") + q = q.Arg("address", address) + q = q.Arg("username", username) + q = q.Arg("secret", secret) + + return &Container{ + query: q, + } +} + +// Change the container's root filesystem. The previous root filesystem will be lost. +func (r *Container) WithRootfs(directory *Directory) *Container { + assertNotNil("directory", directory) + q := r.query.Select("withRootfs") + q = q.Arg("directory", directory) + + return &Container{ + query: q, + } +} + +// Set a new environment variable, using a secret value +func (r *Container) WithSecretVariable(name string, secret *Secret) *Container { + assertNotNil("secret", secret) + q := r.query.Select("withSecretVariable") + q = q.Arg("name", name) + q = q.Arg("secret", secret) + + return &Container{ + query: q, + } +} + +// Establish a runtime dependency from a container to a network service. +// +// The service will be started automatically when needed and detached when it is no longer needed, executing the default command if none is set. +// +// The service will be reachable from the container via the provided hostname alias. +// +// The service dependency will also convey to any files or directories produced by the container. +func (r *Container) WithServiceBinding(alias string, service *Service) *Container { + assertNotNil("service", service) + q := r.query.Select("withServiceBinding") + q = q.Arg("alias", alias) + q = q.Arg("service", service) + + return &Container{ + query: q, + } +} + +// ContainerWithSymlinkOpts contains options for Container.WithSymlink +type ContainerWithSymlinkOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Return a snapshot with a symlink +func (r *Container) WithSymlink(target string, linkName string, opts ...ContainerWithSymlinkOpts) *Container { + q := r.query.Select("withSymlink") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("target", target) + q = q.Arg("linkName", linkName) + + return &Container{ + query: q, + } +} + +// ContainerWithUnixSocketOpts contains options for Container.WithUnixSocket +type ContainerWithUnixSocketOpts struct { + // A user:group to set for the mounted socket. + // + // The user and group can either be an ID (1000:1000) or a name (foo:bar). + // + // If the group is omitted, it defaults to the same as the user. + Owner string + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container plus a socket forwarded to the given Unix socket path. +func (r *Container) WithUnixSocket(path string, source *Socket, opts ...ContainerWithUnixSocketOpts) *Container { + assertNotNil("source", source) + q := r.query.Select("withUnixSocket") + for i := len(opts) - 1; i >= 0; i-- { + // `owner` optional argument + if !querybuilder.IsZeroValue(opts[i].Owner) { + q = q.Arg("owner", opts[i].Owner) + } + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Container{ + query: q, + } +} + +// Retrieves this container with a different command user. +func (r *Container) WithUser(name string) *Container { + q := r.query.Select("withUser") + q = q.Arg("name", name) + + return &Container{ + query: q, + } +} + +// ContainerWithWorkdirOpts contains options for Container.WithWorkdir +type ContainerWithWorkdirOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Change the container's working directory. Like WORKDIR in Dockerfile. +func (r *Container) WithWorkdir(path string, opts ...ContainerWithWorkdirOpts) *Container { + q := r.query.Select("withWorkdir") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// Retrieves this container minus the given OCI annotation. +func (r *Container) WithoutAnnotation(name string) *Container { + q := r.query.Select("withoutAnnotation") + q = q.Arg("name", name) + + return &Container{ + query: q, + } +} + +// Remove the container's default arguments. +func (r *Container) WithoutDefaultArgs() *Container { + q := r.query.Select("withoutDefaultArgs") + + return &Container{ + query: q, + } +} + +// ContainerWithoutDirectoryOpts contains options for Container.WithoutDirectory +type ContainerWithoutDirectoryOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Return a new container snapshot, with a directory removed from its filesystem +func (r *Container) WithoutDirectory(path string, opts ...ContainerWithoutDirectoryOpts) *Container { + q := r.query.Select("withoutDirectory") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// ContainerWithoutEntrypointOpts contains options for Container.WithoutEntrypoint +type ContainerWithoutEntrypointOpts struct { + // Don't remove the default arguments when unsetting the entrypoint. + KeepDefaultArgs bool +} + +// Reset the container's OCI entrypoint. +func (r *Container) WithoutEntrypoint(opts ...ContainerWithoutEntrypointOpts) *Container { + q := r.query.Select("withoutEntrypoint") + for i := len(opts) - 1; i >= 0; i-- { + // `keepDefaultArgs` optional argument + if !querybuilder.IsZeroValue(opts[i].KeepDefaultArgs) { + q = q.Arg("keepDefaultArgs", opts[i].KeepDefaultArgs) + } + } + + return &Container{ + query: q, + } +} + +// Retrieves this container minus the given environment variable. +func (r *Container) WithoutEnvVariable(name string) *Container { + q := r.query.Select("withoutEnvVariable") + q = q.Arg("name", name) + + return &Container{ + query: q, + } +} + +// ContainerWithoutExposedPortOpts contains options for Container.WithoutExposedPort +type ContainerWithoutExposedPortOpts struct { + // Port protocol to unexpose + // + // Default: TCP + Protocol NetworkProtocol +} + +// Unexpose a previously exposed port. +func (r *Container) WithoutExposedPort(port int, opts ...ContainerWithoutExposedPortOpts) *Container { + q := r.query.Select("withoutExposedPort") + for i := len(opts) - 1; i >= 0; i-- { + // `protocol` optional argument + if !querybuilder.IsZeroValue(opts[i].Protocol) { + q = q.Arg("protocol", opts[i].Protocol) + } + } + q = q.Arg("port", port) + + return &Container{ + query: q, + } +} + +// ContainerWithoutFileOpts contains options for Container.WithoutFile +type ContainerWithoutFileOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Retrieves this container with the file at the given path removed. +func (r *Container) WithoutFile(path string, opts ...ContainerWithoutFileOpts) *Container { + q := r.query.Select("withoutFile") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// ContainerWithoutFilesOpts contains options for Container.WithoutFiles +type ContainerWithoutFilesOpts struct { + // Replace "${VAR}" or "$VAR" in the value of paths according to the current environment variables defined in the container (e.g. "/$VAR/foo.txt"). + Expand bool +} + +// Return a new container spanshot with specified files removed +func (r *Container) WithoutFiles(paths []string, opts ...ContainerWithoutFilesOpts) *Container { + q := r.query.Select("withoutFiles") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("paths", paths) + + return &Container{ + query: q, + } +} + +// Retrieves this container minus the given environment label. +func (r *Container) WithoutLabel(name string) *Container { + q := r.query.Select("withoutLabel") + q = q.Arg("name", name) + + return &Container{ + query: q, + } +} + +// ContainerWithoutMountOpts contains options for Container.WithoutMount +type ContainerWithoutMountOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container after unmounting everything at the given path. +func (r *Container) WithoutMount(path string, opts ...ContainerWithoutMountOpts) *Container { + q := r.query.Select("withoutMount") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// Retrieves this container without the registry authentication of a given address. +func (r *Container) WithoutRegistryAuth(address string) *Container { + q := r.query.Select("withoutRegistryAuth") + q = q.Arg("address", address) + + return &Container{ + query: q, + } +} + +// Retrieves this container minus the given environment variable containing the secret. +func (r *Container) WithoutSecretVariable(name string) *Container { + q := r.query.Select("withoutSecretVariable") + q = q.Arg("name", name) + + return &Container{ + query: q, + } +} + +// ContainerWithoutUnixSocketOpts contains options for Container.WithoutUnixSocket +type ContainerWithoutUnixSocketOpts struct { + // Replace "${VAR}" or "$VAR" in the value of path according to the current environment variables defined in the container (e.g. "/$VAR/foo"). + Expand bool +} + +// Retrieves this container with a previously added Unix socket removed. +func (r *Container) WithoutUnixSocket(path string, opts ...ContainerWithoutUnixSocketOpts) *Container { + q := r.query.Select("withoutUnixSocket") + for i := len(opts) - 1; i >= 0; i-- { + // `expand` optional argument + if !querybuilder.IsZeroValue(opts[i].Expand) { + q = q.Arg("expand", opts[i].Expand) + } + } + q = q.Arg("path", path) + + return &Container{ + query: q, + } +} + +// Retrieves this container with an unset command user. +// +// Should default to root. +func (r *Container) WithoutUser() *Container { + q := r.query.Select("withoutUser") + + return &Container{ + query: q, + } +} + +// Unset the container's working directory. +// +// Should default to "/". +func (r *Container) WithoutWorkdir() *Container { + q := r.query.Select("withoutWorkdir") + + return &Container{ + query: q, + } +} + +// Retrieves the working directory for all commands. +func (r *Container) Workdir(ctx context.Context) (string, error) { + if r.workdir != nil { + return *r.workdir, nil + } + q := r.query.Select("workdir") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Reflective module API provided to functions at runtime. +type CurrentModule struct { + query *querybuilder.Selection + + id *CurrentModuleID + name *string +} + +func (r *CurrentModule) WithGraphQLQuery(q *querybuilder.Selection) *CurrentModule { + return &CurrentModule{ + query: q, + } +} + +// A unique identifier for this CurrentModule. +func (r *CurrentModule) ID(ctx context.Context) (CurrentModuleID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response CurrentModuleID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *CurrentModule) XXX_GraphQLType() string { + return "CurrentModule" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *CurrentModule) XXX_GraphQLIDType() string { + return "CurrentModuleID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *CurrentModule) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *CurrentModule) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *CurrentModule) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadCurrentModuleFromID(CurrentModuleID(id)) + return nil +} + +// The name of the module being executed in +func (r *CurrentModule) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The directory containing the module's source code loaded into the engine (plus any generated code that may have been created). +func (r *CurrentModule) Source() *Directory { + q := r.query.Select("source") + + return &Directory{ + query: q, + } +} + +// CurrentModuleWorkdirOpts contains options for CurrentModule.Workdir +type CurrentModuleWorkdirOpts struct { + // Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]). + Exclude []string + // Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]). + Include []string +} + +// Load a directory from the module's scratch working directory, including any changes that may have been made to it during module function execution. +func (r *CurrentModule) Workdir(path string, opts ...CurrentModuleWorkdirOpts) *Directory { + q := r.query.Select("workdir") + for i := len(opts) - 1; i >= 0; i-- { + // `exclude` optional argument + if !querybuilder.IsZeroValue(opts[i].Exclude) { + q = q.Arg("exclude", opts[i].Exclude) + } + // `include` optional argument + if !querybuilder.IsZeroValue(opts[i].Include) { + q = q.Arg("include", opts[i].Include) + } + } + q = q.Arg("path", path) + + return &Directory{ + query: q, + } +} + +// Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution. +func (r *CurrentModule) WorkdirFile(path string) *File { + q := r.query.Select("workdirFile") + q = q.Arg("path", path) + + return &File{ + query: q, + } +} + +// A directory. +type Directory struct { + query *querybuilder.Selection + + digest *string + exists *bool + export *string + id *DirectoryID + name *string + sync *DirectoryID +} +type WithDirectoryFunc func(r *Directory) *Directory + +// With calls the provided function with current Directory. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *Directory) With(f WithDirectoryFunc) *Directory { + return f(r) +} + +func (r *Directory) WithGraphQLQuery(q *querybuilder.Selection) *Directory { + return &Directory{ + query: q, + } +} + +// Converts this directory to a local git repository +func (r *Directory) AsGit() *GitRepository { + q := r.query.Select("asGit") + + return &GitRepository{ + query: q, + } +} + +// DirectoryAsModuleOpts contains options for Directory.AsModule +type DirectoryAsModuleOpts struct { + // An optional subpath of the directory which contains the module's configuration file. + // + // If not set, the module source code is loaded from the root of the directory. + // + // Default: "." + SourceRootPath string +} + +// Load the directory as a Dagger module source +func (r *Directory) AsModule(opts ...DirectoryAsModuleOpts) *Module { + q := r.query.Select("asModule") + for i := len(opts) - 1; i >= 0; i-- { + // `sourceRootPath` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceRootPath) { + q = q.Arg("sourceRootPath", opts[i].SourceRootPath) + } + } + + return &Module{ + query: q, + } +} + +// DirectoryAsModuleSourceOpts contains options for Directory.AsModuleSource +type DirectoryAsModuleSourceOpts struct { + // An optional subpath of the directory which contains the module's configuration file. + // + // If not set, the module source code is loaded from the root of the directory. + // + // Default: "." + SourceRootPath string +} + +// Load the directory as a Dagger module source +func (r *Directory) AsModuleSource(opts ...DirectoryAsModuleSourceOpts) *ModuleSource { + q := r.query.Select("asModuleSource") + for i := len(opts) - 1; i >= 0; i-- { + // `sourceRootPath` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceRootPath) { + q = q.Arg("sourceRootPath", opts[i].SourceRootPath) + } + } + + return &ModuleSource{ + query: q, + } +} + +// Return the difference between this directory and an another directory. The difference is encoded as a directory. +func (r *Directory) Diff(other *Directory) *Directory { + assertNotNil("other", other) + q := r.query.Select("diff") + q = q.Arg("other", other) + + return &Directory{ + query: q, + } +} + +// Return the directory's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same Dagger engine. +func (r *Directory) Digest(ctx context.Context) (string, error) { + if r.digest != nil { + return *r.digest, nil + } + q := r.query.Select("digest") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Retrieves a directory at the given path. +func (r *Directory) Directory(path string) *Directory { + q := r.query.Select("directory") + q = q.Arg("path", path) + + return &Directory{ + query: q, + } +} + +// DirectoryDockerBuildOpts contains options for Directory.DockerBuild +type DirectoryDockerBuildOpts struct { + // Path to the Dockerfile to use (e.g., "frontend.Dockerfile"). + // + // Default: "Dockerfile" + Dockerfile string + // The platform to build. + Platform Platform + // Build arguments to use in the build. + BuildArgs []BuildArg + // Target build stage to build. + Target string + // Secrets to pass to the build. + // + // They will be mounted at /run/secrets/[secret-name]. + Secrets []*Secret + // If set, skip the automatic init process injected into containers created by RUN statements. + // + // This should only be used if the user requires that their exec processes be the pid 1 process in the container. Otherwise it may result in unexpected behavior. + NoInit bool +} + +// Use Dockerfile compatibility to build a container from this directory. Only use this function for Dockerfile compatibility. Otherwise use the native Container type directly, it is feature-complete and supports all Dockerfile features. +func (r *Directory) DockerBuild(opts ...DirectoryDockerBuildOpts) *Container { + q := r.query.Select("dockerBuild") + for i := len(opts) - 1; i >= 0; i-- { + // `dockerfile` optional argument + if !querybuilder.IsZeroValue(opts[i].Dockerfile) { + q = q.Arg("dockerfile", opts[i].Dockerfile) + } + // `platform` optional argument + if !querybuilder.IsZeroValue(opts[i].Platform) { + q = q.Arg("platform", opts[i].Platform) + } + // `buildArgs` optional argument + if !querybuilder.IsZeroValue(opts[i].BuildArgs) { + q = q.Arg("buildArgs", opts[i].BuildArgs) + } + // `target` optional argument + if !querybuilder.IsZeroValue(opts[i].Target) { + q = q.Arg("target", opts[i].Target) + } + // `secrets` optional argument + if !querybuilder.IsZeroValue(opts[i].Secrets) { + q = q.Arg("secrets", opts[i].Secrets) + } + // `noInit` optional argument + if !querybuilder.IsZeroValue(opts[i].NoInit) { + q = q.Arg("noInit", opts[i].NoInit) + } + } + + return &Container{ + query: q, + } +} + +// DirectoryEntriesOpts contains options for Directory.Entries +type DirectoryEntriesOpts struct { + // Location of the directory to look at (e.g., "/src"). + Path string +} + +// Returns a list of files and directories at the given path. +func (r *Directory) Entries(ctx context.Context, opts ...DirectoryEntriesOpts) ([]string, error) { + q := r.query.Select("entries") + for i := len(opts) - 1; i >= 0; i-- { + // `path` optional argument + if !querybuilder.IsZeroValue(opts[i].Path) { + q = q.Arg("path", opts[i].Path) + } + } + + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// DirectoryExistsOpts contains options for Directory.Exists +type DirectoryExistsOpts struct { + // If specified, also validate the type of file (e.g. "REGULAR_TYPE", "DIRECTORY_TYPE", or "SYMLINK_TYPE"). + ExpectedType ExistsType + // If specified, do not follow symlinks. + DoNotFollowSymlinks bool +} + +// check if a file or directory exists +func (r *Directory) Exists(ctx context.Context, path string, opts ...DirectoryExistsOpts) (bool, error) { + if r.exists != nil { + return *r.exists, nil + } + q := r.query.Select("exists") + for i := len(opts) - 1; i >= 0; i-- { + // `expectedType` optional argument + if !querybuilder.IsZeroValue(opts[i].ExpectedType) { + q = q.Arg("expectedType", opts[i].ExpectedType) + } + // `doNotFollowSymlinks` optional argument + if !querybuilder.IsZeroValue(opts[i].DoNotFollowSymlinks) { + q = q.Arg("doNotFollowSymlinks", opts[i].DoNotFollowSymlinks) + } + } + q = q.Arg("path", path) + + var response bool + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// DirectoryExportOpts contains options for Directory.Export +type DirectoryExportOpts struct { + // If true, then the host directory will be wiped clean before exporting so that it exactly matches the directory being exported; this means it will delete any files on the host that aren't in the exported dir. If false (the default), the contents of the directory will be merged with any existing contents of the host directory, leaving any existing files on the host that aren't in the exported directory alone. + Wipe bool +} + +// Writes the contents of the directory to a path on the host. +func (r *Directory) Export(ctx context.Context, path string, opts ...DirectoryExportOpts) (string, error) { + if r.export != nil { + return *r.export, nil + } + q := r.query.Select("export") + for i := len(opts) - 1; i >= 0; i-- { + // `wipe` optional argument + if !querybuilder.IsZeroValue(opts[i].Wipe) { + q = q.Arg("wipe", opts[i].Wipe) + } + } + q = q.Arg("path", path) + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Retrieve a file at the given path. +func (r *Directory) File(path string) *File { + q := r.query.Select("file") + q = q.Arg("path", path) + + return &File{ + query: q, + } +} + +// DirectoryFilterOpts contains options for Directory.Filter +type DirectoryFilterOpts struct { + // If set, paths matching one of these glob patterns is excluded from the new snapshot. Example: ["node_modules/", ".git*", ".env"] + Exclude []string + // If set, only paths matching one of these glob patterns is included in the new snapshot. Example: (e.g., ["app/", "package.*"]). + Include []string +} + +// Return a snapshot with some paths included or excluded +func (r *Directory) Filter(opts ...DirectoryFilterOpts) *Directory { + q := r.query.Select("filter") + for i := len(opts) - 1; i >= 0; i-- { + // `exclude` optional argument + if !querybuilder.IsZeroValue(opts[i].Exclude) { + q = q.Arg("exclude", opts[i].Exclude) + } + // `include` optional argument + if !querybuilder.IsZeroValue(opts[i].Include) { + q = q.Arg("include", opts[i].Include) + } + } + + return &Directory{ + query: q, + } +} + +// Returns a list of files and directories that matche the given pattern. +func (r *Directory) Glob(ctx context.Context, pattern string) ([]string, error) { + q := r.query.Select("glob") + q = q.Arg("pattern", pattern) + + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this Directory. +func (r *Directory) ID(ctx context.Context) (DirectoryID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response DirectoryID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Directory) XXX_GraphQLType() string { + return "Directory" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Directory) XXX_GraphQLIDType() string { + return "DirectoryID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Directory) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *Directory) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *Directory) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadDirectoryFromID(DirectoryID(id)) + return nil +} + +// Returns the name of the directory. +func (r *Directory) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Force evaluation in the engine. +func (r *Directory) Sync(ctx context.Context) (*Directory, error) { + q := r.query.Select("sync") + + var id DirectoryID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Directory{ + query: q.Root().Select("loadDirectoryFromID").Arg("id", id), + }, nil +} + +// DirectoryTerminalOpts contains options for Directory.Terminal +type DirectoryTerminalOpts struct { + // If set, override the default container used for the terminal. + Container *Container + // If set, override the container's default terminal command and invoke these command arguments instead. + Cmd []string + // Provides Dagger access to the executed command. + ExperimentalPrivilegedNesting bool + // Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing "docker run" with the "--privileged" flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands. + InsecureRootCapabilities bool +} + +// Opens an interactive terminal in new container with this directory mounted inside. +func (r *Directory) Terminal(opts ...DirectoryTerminalOpts) *Directory { + q := r.query.Select("terminal") + for i := len(opts) - 1; i >= 0; i-- { + // `container` optional argument + if !querybuilder.IsZeroValue(opts[i].Container) { + q = q.Arg("container", opts[i].Container) + } + // `cmd` optional argument + if !querybuilder.IsZeroValue(opts[i].Cmd) { + q = q.Arg("cmd", opts[i].Cmd) + } + // `experimentalPrivilegedNesting` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalPrivilegedNesting) { + q = q.Arg("experimentalPrivilegedNesting", opts[i].ExperimentalPrivilegedNesting) + } + // `insecureRootCapabilities` optional argument + if !querybuilder.IsZeroValue(opts[i].InsecureRootCapabilities) { + q = q.Arg("insecureRootCapabilities", opts[i].InsecureRootCapabilities) + } + } + + return &Directory{ + query: q, + } +} + +// DirectoryWithDirectoryOpts contains options for Directory.WithDirectory +type DirectoryWithDirectoryOpts struct { + // Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]). + Exclude []string + // Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]). + Include []string +} + +// Return a snapshot with a directory added +func (r *Directory) WithDirectory(path string, directory *Directory, opts ...DirectoryWithDirectoryOpts) *Directory { + assertNotNil("directory", directory) + q := r.query.Select("withDirectory") + for i := len(opts) - 1; i >= 0; i-- { + // `exclude` optional argument + if !querybuilder.IsZeroValue(opts[i].Exclude) { + q = q.Arg("exclude", opts[i].Exclude) + } + // `include` optional argument + if !querybuilder.IsZeroValue(opts[i].Include) { + q = q.Arg("include", opts[i].Include) + } + } + q = q.Arg("path", path) + q = q.Arg("directory", directory) + + return &Directory{ + query: q, + } +} + +// DirectoryWithFileOpts contains options for Directory.WithFile +type DirectoryWithFileOpts struct { + // Permission given to the copied file (e.g., 0600). + Permissions int +} + +// Retrieves this directory plus the contents of the given file copied to the given path. +func (r *Directory) WithFile(path string, source *File, opts ...DirectoryWithFileOpts) *Directory { + assertNotNil("source", source) + q := r.query.Select("withFile") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + } + q = q.Arg("path", path) + q = q.Arg("source", source) + + return &Directory{ + query: q, + } +} + +// DirectoryWithFilesOpts contains options for Directory.WithFiles +type DirectoryWithFilesOpts struct { + // Permission given to the copied files (e.g., 0600). + Permissions int +} + +// Retrieves this directory plus the contents of the given files copied to the given path. +func (r *Directory) WithFiles(path string, sources []*File, opts ...DirectoryWithFilesOpts) *Directory { + q := r.query.Select("withFiles") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + } + q = q.Arg("path", path) + q = q.Arg("sources", sources) + + return &Directory{ + query: q, + } +} + +// DirectoryWithNewDirectoryOpts contains options for Directory.WithNewDirectory +type DirectoryWithNewDirectoryOpts struct { + // Permission granted to the created directory (e.g., 0777). + // + // Default: 420 + Permissions int +} + +// Retrieves this directory plus a new directory created at the given path. +func (r *Directory) WithNewDirectory(path string, opts ...DirectoryWithNewDirectoryOpts) *Directory { + q := r.query.Select("withNewDirectory") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + } + q = q.Arg("path", path) + + return &Directory{ + query: q, + } +} + +// DirectoryWithNewFileOpts contains options for Directory.WithNewFile +type DirectoryWithNewFileOpts struct { + // Permissions of the new file. Example: 0600 + // + // Default: 420 + Permissions int +} + +// Return a snapshot with a new file added +func (r *Directory) WithNewFile(path string, contents string, opts ...DirectoryWithNewFileOpts) *Directory { + q := r.query.Select("withNewFile") + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + } + q = q.Arg("path", path) + q = q.Arg("contents", contents) + + return &Directory{ + query: q, + } +} + +// Retrieves this directory with the given Git-compatible patch applied. +// +// Experimental: This API is highly experimental and may be removed or replaced entirely. +func (r *Directory) WithPatch(patch string) *Directory { + q := r.query.Select("withPatch") + q = q.Arg("patch", patch) + + return &Directory{ + query: q, + } +} + +// Return a snapshot with a symlink +func (r *Directory) WithSymlink(target string, linkName string) *Directory { + q := r.query.Select("withSymlink") + q = q.Arg("target", target) + q = q.Arg("linkName", linkName) + + return &Directory{ + query: q, + } +} + +// Retrieves this directory with all file/dir timestamps set to the given time. +func (r *Directory) WithTimestamps(timestamp int) *Directory { + q := r.query.Select("withTimestamps") + q = q.Arg("timestamp", timestamp) + + return &Directory{ + query: q, + } +} + +// Return a snapshot with a subdirectory removed +func (r *Directory) WithoutDirectory(path string) *Directory { + q := r.query.Select("withoutDirectory") + q = q.Arg("path", path) + + return &Directory{ + query: q, + } +} + +// Return a snapshot with a file removed +func (r *Directory) WithoutFile(path string) *Directory { + q := r.query.Select("withoutFile") + q = q.Arg("path", path) + + return &Directory{ + query: q, + } +} + +// Return a snapshot with files removed +func (r *Directory) WithoutFiles(paths []string) *Directory { + q := r.query.Select("withoutFiles") + q = q.Arg("paths", paths) + + return &Directory{ + query: q, + } +} + +// A definition of a custom enum defined in a Module. +type EnumTypeDef struct { + query *querybuilder.Selection + + description *string + id *EnumTypeDefID + name *string + sourceModuleName *string +} + +func (r *EnumTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *EnumTypeDef { + return &EnumTypeDef{ + query: q, + } +} + +// A doc string for the enum, if any. +func (r *EnumTypeDef) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil + } + q := r.query.Select("description") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this EnumTypeDef. +func (r *EnumTypeDef) ID(ctx context.Context) (EnumTypeDefID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response EnumTypeDefID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *EnumTypeDef) XXX_GraphQLType() string { + return "EnumTypeDef" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *EnumTypeDef) XXX_GraphQLIDType() string { + return "EnumTypeDefID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *EnumTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *EnumTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *EnumTypeDef) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadEnumTypeDefFromID(EnumTypeDefID(id)) + return nil +} + +// The members of the enum. +func (r *EnumTypeDef) Members(ctx context.Context) ([]EnumValueTypeDef, error) { + q := r.query.Select("members") + + q = q.Select("id") + + type members struct { + Id EnumValueTypeDefID + } + + convert := func(fields []members) []EnumValueTypeDef { + out := []EnumValueTypeDef{} + + for i := range fields { + val := EnumValueTypeDef{id: &fields[i].Id} + val.query = q.Root().Select("loadEnumValueTypeDefFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []members + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil +} + +// The name of the enum. +func (r *EnumTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The location of this enum declaration. +func (r *EnumTypeDef) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") + + return &SourceMap{ + query: q, + } +} + +// If this EnumTypeDef is associated with a Module, the name of the module. Unset otherwise. +func (r *EnumTypeDef) SourceModuleName(ctx context.Context) (string, error) { + if r.sourceModuleName != nil { + return *r.sourceModuleName, nil + } + q := r.query.Select("sourceModuleName") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Deprecated: use members instead +func (r *EnumTypeDef) Values(ctx context.Context) ([]EnumValueTypeDef, error) { + q := r.query.Select("values") + + q = q.Select("id") + + type values struct { + Id EnumValueTypeDefID + } + + convert := func(fields []values) []EnumValueTypeDef { + out := []EnumValueTypeDef{} + + for i := range fields { + val := EnumValueTypeDef{id: &fields[i].Id} + val.query = q.Root().Select("loadEnumValueTypeDefFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []values + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil +} + +// A definition of a value in a custom enum defined in a Module. +type EnumValueTypeDef struct { + query *querybuilder.Selection + + description *string + id *EnumValueTypeDefID + name *string + value *string +} + +func (r *EnumValueTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *EnumValueTypeDef { + return &EnumValueTypeDef{ + query: q, + } +} + +// A doc string for the enum member, if any. +func (r *EnumValueTypeDef) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil + } + q := r.query.Select("description") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this EnumValueTypeDef. +func (r *EnumValueTypeDef) ID(ctx context.Context) (EnumValueTypeDefID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response EnumValueTypeDefID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *EnumValueTypeDef) XXX_GraphQLType() string { + return "EnumValueTypeDef" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *EnumValueTypeDef) XXX_GraphQLIDType() string { + return "EnumValueTypeDefID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *EnumValueTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *EnumValueTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *EnumValueTypeDef) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadEnumValueTypeDefFromID(EnumValueTypeDefID(id)) + return nil +} + +// The name of the enum member. +func (r *EnumValueTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The location of this enum member declaration. +func (r *EnumValueTypeDef) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") + + return &SourceMap{ + query: q, + } +} + +// The value of the enum member +func (r *EnumValueTypeDef) Value(ctx context.Context) (string, error) { + if r.value != nil { + return *r.value, nil + } + q := r.query.Select("value") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +type Env struct { + query *querybuilder.Selection + + id *EnvID +} +type WithEnvFunc func(r *Env) *Env + +// With calls the provided function with current Env. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *Env) With(f WithEnvFunc) *Env { + return f(r) +} + +func (r *Env) WithGraphQLQuery(q *querybuilder.Selection) *Env { + return &Env{ + query: q, + } +} + +// A unique identifier for this Env. +func (r *Env) ID(ctx context.Context) (EnvID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response EnvID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Env) XXX_GraphQLType() string { + return "Env" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Env) XXX_GraphQLIDType() string { + return "EnvID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Env) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *Env) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *Env) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadEnvFromID(EnvID(id)) + return nil +} + +// retrieve an input value by name +func (r *Env) Input(name string) *Binding { + q := r.query.Select("input") + q = q.Arg("name", name) + + return &Binding{ + query: q, + } +} + +// return all input values for the environment +func (r *Env) Inputs(ctx context.Context) ([]Binding, error) { + q := r.query.Select("inputs") + + q = q.Select("id") + + type inputs struct { + Id BindingID + } + + convert := func(fields []inputs) []Binding { + out := []Binding{} + + for i := range fields { + val := Binding{id: &fields[i].Id} + val.query = q.Root().Select("loadBindingFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []inputs + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil +} + +// retrieve an output value by name +func (r *Env) Output(name string) *Binding { + q := r.query.Select("output") + q = q.Arg("name", name) + + return &Binding{ + query: q, + } +} + +// return all output values for the environment +func (r *Env) Outputs(ctx context.Context) ([]Binding, error) { + q := r.query.Select("outputs") + + q = q.Select("id") + + type outputs struct { + Id BindingID + } + + convert := func(fields []outputs) []Binding { + out := []Binding{} + + for i := range fields { + val := Binding{id: &fields[i].Id} + val.query = q.Root().Select("loadBindingFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []outputs + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } - return &Container{ + return convert(response), nil +} + +// Create or update a binding of type CacheVolume in the environment +func (r *Env) WithCacheVolumeInput(name string, value *CacheVolume, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withCacheVolumeInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) + + return &Env{ query: q, } } -// Indicate that subsequent operations should be featured more prominently in the UI. -func (r *Container) WithFocus() *Container { - q := r.query.Select("withFocus") +// Declare a desired CacheVolume output to be assigned in the environment +func (r *Env) WithCacheVolumeOutput(name string, description string) *Env { + q := r.query.Select("withCacheVolumeOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container plus the given label. -func (r *Container) WithLabel(name string, value string) *Container { - q := r.query.Select("withLabel") +// Create or update a binding of type Cloud in the environment +func (r *Env) WithCloudInput(name string, value *Cloud, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withCloudInput") q = q.Arg("name", name) q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithMountedCacheOpts contains options for Container.WithMountedCache -type ContainerWithMountedCacheOpts struct { - // Identifier of the directory to use as the cache volume's root. - Source *Directory - // Sharing mode of the cache volume. - Sharing CacheSharingMode - // A user:group to set for the mounted cache directory. - // - // Note that this changes the ownership of the specified mount along with the initial filesystem provided by source (if any). It does not have any effect if/when the cache has already been created. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string -} - -// Retrieves this container plus a cache volume mounted at the given path. -func (r *Container) WithMountedCache(path string, cache *CacheVolume, opts ...ContainerWithMountedCacheOpts) *Container { - assertNotNil("cache", cache) - q := r.query.Select("withMountedCache") - for i := len(opts) - 1; i >= 0; i-- { - // `source` optional argument - if !querybuilder.IsZeroValue(opts[i].Source) { - q = q.Arg("source", opts[i].Source) - } - // `sharing` optional argument - if !querybuilder.IsZeroValue(opts[i].Sharing) { - q = q.Arg("sharing", opts[i].Sharing) - } - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } - } - q = q.Arg("path", path) - q = q.Arg("cache", cache) +// Declare a desired Cloud output to be assigned in the environment +func (r *Env) WithCloudOutput(name string, description string) *Env { + q := r.query.Select("withCloudOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithMountedDirectoryOpts contains options for Container.WithMountedDirectory -type ContainerWithMountedDirectoryOpts struct { - // A user:group to set for the mounted directory and its contents. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string -} - -// Retrieves this container plus a directory mounted at the given path. -func (r *Container) WithMountedDirectory(path string, source *Directory, opts ...ContainerWithMountedDirectoryOpts) *Container { - assertNotNil("source", source) - q := r.query.Select("withMountedDirectory") - for i := len(opts) - 1; i >= 0; i-- { - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } - } - q = q.Arg("path", path) - q = q.Arg("source", source) +// Create or update a binding of type Container in the environment +func (r *Env) WithContainerInput(name string, value *Container, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withContainerInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithMountedFileOpts contains options for Container.WithMountedFile -type ContainerWithMountedFileOpts struct { - // A user or user:group to set for the mounted file. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string -} +// Declare a desired Container output to be assigned in the environment +func (r *Env) WithContainerOutput(name string, description string) *Env { + q := r.query.Select("withContainerOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) -// Retrieves this container plus a file mounted at the given path. -func (r *Container) WithMountedFile(path string, source *File, opts ...ContainerWithMountedFileOpts) *Container { - assertNotNil("source", source) - q := r.query.Select("withMountedFile") - for i := len(opts) - 1; i >= 0; i-- { - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } + return &Env{ + query: q, } - q = q.Arg("path", path) - q = q.Arg("source", source) +} - return &Container{ +// Create or update a binding of type Directory in the environment +func (r *Env) WithDirectoryInput(name string, value *Directory, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withDirectoryInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) + + return &Env{ query: q, } } -// ContainerWithMountedSecretOpts contains options for Container.WithMountedSecret -type ContainerWithMountedSecretOpts struct { - // A user:group to set for the mounted secret. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string - // Permission given to the mounted secret (e.g., 0600). - // - // This option requires an owner to be set to be active. - Mode int -} +// Declare a desired Directory output to be assigned in the environment +func (r *Env) WithDirectoryOutput(name string, description string) *Env { + q := r.query.Select("withDirectoryOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) -// Retrieves this container plus a secret mounted into a file at the given path. -func (r *Container) WithMountedSecret(path string, source *Secret, opts ...ContainerWithMountedSecretOpts) *Container { - assertNotNil("source", source) - q := r.query.Select("withMountedSecret") - for i := len(opts) - 1; i >= 0; i-- { - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } - // `mode` optional argument - if !querybuilder.IsZeroValue(opts[i].Mode) { - q = q.Arg("mode", opts[i].Mode) - } + return &Env{ + query: q, } - q = q.Arg("path", path) - q = q.Arg("source", source) +} - return &Container{ +// Create or update a binding of type Env in the environment +func (r *Env) WithEnvInput(name string, value *Env, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withEnvInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) + + return &Env{ query: q, } } -// Retrieves this container plus a temporary directory mounted at the given path. -func (r *Container) WithMountedTemp(path string) *Container { - q := r.query.Select("withMountedTemp") - q = q.Arg("path", path) +// Declare a desired Env output to be assigned in the environment +func (r *Env) WithEnvOutput(name string, description string) *Env { + q := r.query.Select("withEnvOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithNewFileOpts contains options for Container.WithNewFile -type ContainerWithNewFileOpts struct { - // Content of the file to write (e.g., "Hello world!"). - Contents string - // Permission given to the written file (e.g., 0600). - Permissions int - // A user:group to set for the file. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string -} +// Create or update a binding of type File in the environment +func (r *Env) WithFileInput(name string, value *File, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withFileInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) -// Retrieves this container plus a new file written at the given path. -func (r *Container) WithNewFile(path string, opts ...ContainerWithNewFileOpts) *Container { - q := r.query.Select("withNewFile") - for i := len(opts) - 1; i >= 0; i-- { - // `contents` optional argument - if !querybuilder.IsZeroValue(opts[i].Contents) { - q = q.Arg("contents", opts[i].Contents) - } - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } + return &Env{ + query: q, } - q = q.Arg("path", path) +} - return &Container{ +// Declare a desired File output to be assigned in the environment +func (r *Env) WithFileOutput(name string, description string) *Env { + q := r.query.Select("withFileOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) + + return &Env{ query: q, } } -// Retrieves this container with a registry authentication for a given address. -func (r *Container) WithRegistryAuth(address string, username string, secret *Secret) *Container { - assertNotNil("secret", secret) - q := r.query.Select("withRegistryAuth") - q = q.Arg("address", address) - q = q.Arg("username", username) - q = q.Arg("secret", secret) +// Create or update a binding of type GitRef in the environment +func (r *Env) WithGitRefInput(name string, value *GitRef, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withGitRefInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves the container with the given directory mounted to /. -func (r *Container) WithRootfs(directory *Directory) *Container { - assertNotNil("directory", directory) - q := r.query.Select("withRootfs") - q = q.Arg("directory", directory) +// Declare a desired GitRef output to be assigned in the environment +func (r *Env) WithGitRefOutput(name string, description string) *Env { + q := r.query.Select("withGitRefOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container plus an env variable containing the given secret. -func (r *Container) WithSecretVariable(name string, secret *Secret) *Container { - assertNotNil("secret", secret) - q := r.query.Select("withSecretVariable") +// Create or update a binding of type GitRepository in the environment +func (r *Env) WithGitRepositoryInput(name string, value *GitRepository, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withGitRepositoryInput") q = q.Arg("name", name) - q = q.Arg("secret", secret) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Establish a runtime dependency on a service. -// -// The service will be started automatically when needed and detached when it is no longer needed, executing the default command if none is set. -// -// The service will be reachable from the container via the provided hostname alias. -// -// The service dependency will also convey to any files or directories produced by the container. -func (r *Container) WithServiceBinding(alias string, service *Service) *Container { - assertNotNil("service", service) - q := r.query.Select("withServiceBinding") - q = q.Arg("alias", alias) - q = q.Arg("service", service) +// Declare a desired GitRepository output to be assigned in the environment +func (r *Env) WithGitRepositoryOutput(name string, description string) *Env { + q := r.query.Select("withGitRepositoryOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithUnixSocketOpts contains options for Container.WithUnixSocket -type ContainerWithUnixSocketOpts struct { - // A user:group to set for the mounted socket. - // - // The user and group can either be an ID (1000:1000) or a name (foo:bar). - // - // If the group is omitted, it defaults to the same as the user. - Owner string -} +// Create or update a binding of type LLM in the environment +func (r *Env) WithLLMInput(name string, value *LLM, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withLLMInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) -// Retrieves this container plus a socket forwarded to the given Unix socket path. -func (r *Container) WithUnixSocket(path string, source *Socket, opts ...ContainerWithUnixSocketOpts) *Container { - assertNotNil("source", source) - q := r.query.Select("withUnixSocket") - for i := len(opts) - 1; i >= 0; i-- { - // `owner` optional argument - if !querybuilder.IsZeroValue(opts[i].Owner) { - q = q.Arg("owner", opts[i].Owner) - } + return &Env{ + query: q, } - q = q.Arg("path", path) - q = q.Arg("source", source) +} - return &Container{ +// Declare a desired LLM output to be assigned in the environment +func (r *Env) WithLLMOutput(name string, description string) *Env { + q := r.query.Select("withLLMOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) + + return &Env{ query: q, } } -// Retrieves this container with a different command user. -func (r *Container) WithUser(name string) *Container { - q := r.query.Select("withUser") +// Create or update a binding of type ModuleConfigClient in the environment +func (r *Env) WithModuleConfigClientInput(name string, value *ModuleConfigClient, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withModuleConfigClientInput") q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container with a different working directory. -func (r *Container) WithWorkdir(path string) *Container { - q := r.query.Select("withWorkdir") - q = q.Arg("path", path) +// Declare a desired ModuleConfigClient output to be assigned in the environment +func (r *Env) WithModuleConfigClientOutput(name string, description string) *Env { + q := r.query.Select("withModuleConfigClientOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container with unset default arguments for future commands. -func (r *Container) WithoutDefaultArgs() *Container { - q := r.query.Select("withoutDefaultArgs") +// Create or update a binding of type Module in the environment +func (r *Env) WithModuleInput(name string, value *Module, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withModuleInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithoutEntrypointOpts contains options for Container.WithoutEntrypoint -type ContainerWithoutEntrypointOpts struct { - // Don't remove the default arguments when unsetting the entrypoint. - KeepDefaultArgs bool -} - -// Retrieves this container with an unset command entrypoint. -func (r *Container) WithoutEntrypoint(opts ...ContainerWithoutEntrypointOpts) *Container { - q := r.query.Select("withoutEntrypoint") - for i := len(opts) - 1; i >= 0; i-- { - // `keepDefaultArgs` optional argument - if !querybuilder.IsZeroValue(opts[i].KeepDefaultArgs) { - q = q.Arg("keepDefaultArgs", opts[i].KeepDefaultArgs) - } - } +// Declare a desired Module output to be assigned in the environment +func (r *Env) WithModuleOutput(name string, description string) *Env { + q := r.query.Select("withModuleOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container minus the given environment variable. -func (r *Container) WithoutEnvVariable(name string) *Container { - q := r.query.Select("withoutEnvVariable") +// Create or update a binding of type ModuleSource in the environment +func (r *Env) WithModuleSourceInput(name string, value *ModuleSource, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withModuleSourceInput") q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// ContainerWithoutExposedPortOpts contains options for Container.WithoutExposedPort -type ContainerWithoutExposedPortOpts struct { - // Port protocol to unexpose - Protocol NetworkProtocol -} - -// Unexpose a previously exposed port. -func (r *Container) WithoutExposedPort(port int, opts ...ContainerWithoutExposedPortOpts) *Container { - q := r.query.Select("withoutExposedPort") - for i := len(opts) - 1; i >= 0; i-- { - // `protocol` optional argument - if !querybuilder.IsZeroValue(opts[i].Protocol) { - q = q.Arg("protocol", opts[i].Protocol) - } - } - q = q.Arg("port", port) +// Declare a desired ModuleSource output to be assigned in the environment +func (r *Env) WithModuleSourceOutput(name string, description string) *Env { + q := r.query.Select("withModuleSourceOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Indicate that subsequent operations should not be featured more prominently in the UI. -// -// This is the initial state of all containers. -func (r *Container) WithoutFocus() *Container { - q := r.query.Select("withoutFocus") +// Create or update a binding of type Secret in the environment +func (r *Env) WithSecretInput(name string, value *Secret, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withSecretInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container minus the given environment label. -func (r *Container) WithoutLabel(name string) *Container { - q := r.query.Select("withoutLabel") +// Declare a desired Secret output to be assigned in the environment +func (r *Env) WithSecretOutput(name string, description string) *Env { + q := r.query.Select("withSecretOutput") q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container after unmounting everything at the given path. -func (r *Container) WithoutMount(path string) *Container { - q := r.query.Select("withoutMount") - q = q.Arg("path", path) +// Create or update a binding of type Service in the environment +func (r *Env) WithServiceInput(name string, value *Service, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withServiceInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container without the registry authentication of a given address. -func (r *Container) WithoutRegistryAuth(address string) *Container { - q := r.query.Select("withoutRegistryAuth") - q = q.Arg("address", address) +// Declare a desired Service output to be assigned in the environment +func (r *Env) WithServiceOutput(name string, description string) *Env { + q := r.query.Select("withServiceOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container with a previously added Unix socket removed. -func (r *Container) WithoutUnixSocket(path string) *Container { - q := r.query.Select("withoutUnixSocket") - q = q.Arg("path", path) +// Create or update a binding of type Socket in the environment +func (r *Env) WithSocketInput(name string, value *Socket, description string) *Env { + assertNotNil("value", value) + q := r.query.Select("withSocketInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container with an unset command user. -// -// Should default to root. -func (r *Container) WithoutUser() *Container { - q := r.query.Select("withoutUser") +// Declare a desired Socket output to be assigned in the environment +func (r *Env) WithSocketOutput(name string, description string) *Env { + q := r.query.Select("withSocketOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves this container with an unset working directory. -// -// Should default to "/". -func (r *Container) WithoutWorkdir() *Container { - q := r.query.Select("withoutWorkdir") +// Create or update an input value of type string +func (r *Env) WithStringInput(name string, value string, description string) *Env { + q := r.query.Select("withStringInput") + q = q.Arg("name", name) + q = q.Arg("value", value) + q = q.Arg("description", description) - return &Container{ + return &Env{ query: q, } } -// Retrieves the working directory for all commands. -func (r *Container) Workdir(ctx context.Context) (string, error) { - if r.workdir != nil { - return *r.workdir, nil - } - q := r.query.Select("workdir") - - var response string +// Create or update an input value of type string +func (r *Env) WithStringOutput(name string, description string) *Env { + q := r.query.Select("withStringOutput") + q = q.Arg("name", name) + q = q.Arg("description", description) - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Env{ + query: q, + } } -// Reflective module API provided to functions at runtime. -type CurrentModule struct { +// An environment variable name and value. +type EnvVariable struct { query *querybuilder.Selection - id *CurrentModuleID - name *string + id *EnvVariableID + name *string + value *string } -func (r *CurrentModule) WithGraphQLQuery(q *querybuilder.Selection) *CurrentModule { - return &CurrentModule{ +func (r *EnvVariable) WithGraphQLQuery(q *querybuilder.Selection) *EnvVariable { + return &EnvVariable{ query: q, } } -// A unique identifier for this CurrentModule. -func (r *CurrentModule) ID(ctx context.Context) (CurrentModuleID, error) { +// A unique identifier for this EnvVariable. +func (r *EnvVariable) ID(ctx context.Context) (EnvVariableID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response CurrentModuleID + var response EnvVariableID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *CurrentModule) XXX_GraphQLType() string { - return "CurrentModule" +func (r *EnvVariable) XXX_GraphQLType() string { + return "EnvVariable" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *CurrentModule) XXX_GraphQLIDType() string { - return "CurrentModuleID" +func (r *EnvVariable) XXX_GraphQLIDType() string { + return "EnvVariableID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *CurrentModule) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *EnvVariable) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -1749,25 +4190,25 @@ func (r *CurrentModule) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *CurrentModule) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *EnvVariable) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *CurrentModule) UnmarshalJSON(bs []byte) error { +func (r *EnvVariable) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadCurrentModuleFromID(CurrentModuleID(id)) + *r = *dag.LoadEnvVariableFromID(EnvVariableID(id)) return nil } -// The name of the module being executed in -func (r *CurrentModule) Name(ctx context.Context) (string, error) { +// The environment variable name. +func (r *EnvVariable) Name(ctx context.Context) (string, error) { if r.name != nil { return *r.name, nil } @@ -1779,251 +4220,185 @@ func (r *CurrentModule) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The directory containing the module's source code loaded into the engine (plus any generated code that may have been created). -func (r *CurrentModule) Source() *Directory { - q := r.query.Select("source") - - return &Directory{ - query: q, - } -} - -// CurrentModuleWorkdirOpts contains options for CurrentModule.Workdir -type CurrentModuleWorkdirOpts struct { - // Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]). - Exclude []string - // Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]). - Include []string -} - -// Load a directory from the module's scratch working directory, including any changes that may have been made to it during module function execution. -func (r *CurrentModule) Workdir(path string, opts ...CurrentModuleWorkdirOpts) *Directory { - q := r.query.Select("workdir") - for i := len(opts) - 1; i >= 0; i-- { - // `exclude` optional argument - if !querybuilder.IsZeroValue(opts[i].Exclude) { - q = q.Arg("exclude", opts[i].Exclude) - } - // `include` optional argument - if !querybuilder.IsZeroValue(opts[i].Include) { - q = q.Arg("include", opts[i].Include) - } - } - q = q.Arg("path", path) - - return &Directory{ - query: q, +// The environment variable value. +func (r *EnvVariable) Value(ctx context.Context) (string, error) { + if r.value != nil { + return *r.value, nil } -} + q := r.query.Select("value") -// Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution. -func (r *CurrentModule) WorkdirFile(path string) *File { - q := r.query.Select("workdirFile") - q = q.Arg("path", path) + var response string - return &File{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// A directory. -type Directory struct { +type Error struct { query *querybuilder.Selection - export *bool - id *DirectoryID - sync *DirectoryID + id *ErrorID + message *string } -type WithDirectoryFunc func(r *Directory) *Directory +type WithErrorFunc func(r *Error) *Error -// With calls the provided function with current Directory. +// With calls the provided function with current Error. // // This is useful for reusability and readability by not breaking the calling chain. -func (r *Directory) With(f WithDirectoryFunc) *Directory { +func (r *Error) With(f WithErrorFunc) *Error { return f(r) } -func (r *Directory) WithGraphQLQuery(q *querybuilder.Selection) *Directory { - return &Directory{ - query: q, - } -} - -// DirectoryAsModuleOpts contains options for Directory.AsModule -type DirectoryAsModuleOpts struct { - // An optional subpath of the directory which contains the module's configuration file. - // - // This is needed when the module code is in a subdirectory but requires parent directories to be loaded in order to execute. For example, the module source code may need a go.mod, project.toml, package.json, etc. file from a parent directory. - // - // If not set, the module source code is loaded from the root of the directory. - SourceRootPath string -} - -// Load the directory as a Dagger module -func (r *Directory) AsModule(opts ...DirectoryAsModuleOpts) *Module { - q := r.query.Select("asModule") - for i := len(opts) - 1; i >= 0; i-- { - // `sourceRootPath` optional argument - if !querybuilder.IsZeroValue(opts[i].SourceRootPath) { - q = q.Arg("sourceRootPath", opts[i].SourceRootPath) - } - } - - return &Module{ +func (r *Error) WithGraphQLQuery(q *querybuilder.Selection) *Error { + return &Error{ query: q, } } -// Gets the difference between this directory and an another directory. -func (r *Directory) Diff(other *Directory) *Directory { - assertNotNil("other", other) - q := r.query.Select("diff") - q = q.Arg("other", other) - - return &Directory{ - query: q, +// A unique identifier for this Error. +func (r *Error) ID(ctx context.Context) (ErrorID, error) { + if r.id != nil { + return *r.id, nil } -} + q := r.query.Select("id") -// Retrieves a directory at the given path. -func (r *Directory) Directory(path string) *Directory { - q := r.query.Select("directory") - q = q.Arg("path", path) + var response ErrorID - return &Directory{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// DirectoryDockerBuildOpts contains options for Directory.DockerBuild -type DirectoryDockerBuildOpts struct { - // The platform to build. - Platform Platform - // Path to the Dockerfile to use (e.g., "frontend.Dockerfile"). - Dockerfile string - // Target build stage to build. - Target string - // Build arguments to use in the build. - BuildArgs []BuildArg - // Secrets to pass to the build. - // - // They will be mounted at /run/secrets/[secret-name]. - Secrets []*Secret +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *Error) XXX_GraphQLType() string { + return "Error" } -// Builds a new Docker container from this directory. -func (r *Directory) DockerBuild(opts ...DirectoryDockerBuildOpts) *Container { - q := r.query.Select("dockerBuild") - for i := len(opts) - 1; i >= 0; i-- { - // `platform` optional argument - if !querybuilder.IsZeroValue(opts[i].Platform) { - q = q.Arg("platform", opts[i].Platform) - } - // `dockerfile` optional argument - if !querybuilder.IsZeroValue(opts[i].Dockerfile) { - q = q.Arg("dockerfile", opts[i].Dockerfile) - } - // `target` optional argument - if !querybuilder.IsZeroValue(opts[i].Target) { - q = q.Arg("target", opts[i].Target) - } - // `buildArgs` optional argument - if !querybuilder.IsZeroValue(opts[i].BuildArgs) { - q = q.Arg("buildArgs", opts[i].BuildArgs) - } - // `secrets` optional argument - if !querybuilder.IsZeroValue(opts[i].Secrets) { - q = q.Arg("secrets", opts[i].Secrets) - } - } +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *Error) XXX_GraphQLIDType() string { + return "ErrorID" +} - return &Container{ - query: q, +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *Error) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err } + return string(id), nil } -// DirectoryEntriesOpts contains options for Directory.Entries -type DirectoryEntriesOpts struct { - // Location of the directory to look at (e.g., "/src"). - Path string +func (r *Error) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *Error) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadErrorFromID(ErrorID(id)) + return nil } -// Returns a list of files and directories at the given path. -func (r *Directory) Entries(ctx context.Context, opts ...DirectoryEntriesOpts) ([]string, error) { - q := r.query.Select("entries") - for i := len(opts) - 1; i >= 0; i-- { - // `path` optional argument - if !querybuilder.IsZeroValue(opts[i].Path) { - q = q.Arg("path", opts[i].Path) - } +// A description of the error. +func (r *Error) Message(ctx context.Context) (string, error) { + if r.message != nil { + return *r.message, nil } + q := r.query.Select("message") - var response []string + var response string q = q.Bind(&response) return response, q.Execute(ctx) } -// Writes the contents of the directory to a path on the host. -func (r *Directory) Export(ctx context.Context, path string) (bool, error) { - if r.export != nil { - return *r.export, nil +// The extensions of the error. +func (r *Error) Values(ctx context.Context) ([]ErrorValue, error) { + q := r.query.Select("values") + + q = q.Select("id") + + type values struct { + Id ErrorValueID } - q := r.query.Select("export") - q = q.Arg("path", path) - var response bool + convert := func(fields []values) []ErrorValue { + out := []ErrorValue{} + + for i := range fields { + val := ErrorValue{id: &fields[i].Id} + val.query = q.Root().Select("loadErrorValueFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []values q = q.Bind(&response) - return response, q.Execute(ctx) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil } -// Retrieves a file at the given path. -func (r *Directory) File(path string) *File { - q := r.query.Select("file") - q = q.Arg("path", path) +// Add a value to the error. +func (r *Error) WithValue(name string, value JSON) *Error { + q := r.query.Select("withValue") + q = q.Arg("name", name) + q = q.Arg("value", value) - return &File{ + return &Error{ query: q, } } -// Returns a list of files and directories that matche the given pattern. -func (r *Directory) Glob(ctx context.Context, pattern string) ([]string, error) { - q := r.query.Select("glob") - q = q.Arg("pattern", pattern) +type ErrorValue struct { + query *querybuilder.Selection - var response []string + id *ErrorValueID + name *string + value *JSON +} - q = q.Bind(&response) - return response, q.Execute(ctx) +func (r *ErrorValue) WithGraphQLQuery(q *querybuilder.Selection) *ErrorValue { + return &ErrorValue{ + query: q, + } } -// A unique identifier for this Directory. -func (r *Directory) ID(ctx context.Context) (DirectoryID, error) { +// A unique identifier for this ErrorValue. +func (r *ErrorValue) ID(ctx context.Context) (ErrorValueID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response DirectoryID + var response ErrorValueID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *Directory) XXX_GraphQLType() string { - return "Directory" +func (r *ErrorValue) XXX_GraphQLType() string { + return "ErrorValue" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *Directory) XXX_GraphQLIDType() string { - return "DirectoryID" +func (r *ErrorValue) XXX_GraphQLIDType() string { + return "ErrorValueID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *Directory) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *ErrorValue) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2031,250 +4406,275 @@ func (r *Directory) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *Directory) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *ErrorValue) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *Directory) UnmarshalJSON(bs []byte) error { +func (r *ErrorValue) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadDirectoryFromID(DirectoryID(id)) + *r = *dag.LoadErrorValueFromID(ErrorValueID(id)) return nil } -// DirectoryPipelineOpts contains options for Directory.Pipeline -type DirectoryPipelineOpts struct { - // Description of the sub-pipeline. - Description string - // Labels to apply to the sub-pipeline. - Labels []PipelineLabel +// The name of the value. +func (r *ErrorValue) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Creates a named sub-pipeline. -func (r *Directory) Pipeline(name string, opts ...DirectoryPipelineOpts) *Directory { - q := r.query.Select("pipeline") - for i := len(opts) - 1; i >= 0; i-- { - // `description` optional argument - if !querybuilder.IsZeroValue(opts[i].Description) { - q = q.Arg("description", opts[i].Description) - } - // `labels` optional argument - if !querybuilder.IsZeroValue(opts[i].Labels) { - q = q.Arg("labels", opts[i].Labels) - } +// The value. +func (r *ErrorValue) Value(ctx context.Context) (JSON, error) { + if r.value != nil { + return *r.value, nil } - q = q.Arg("name", name) + q := r.query.Select("value") - return &Directory{ - query: q, - } + var response JSON + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Force evaluation in the engine. -func (r *Directory) Sync(ctx context.Context) (*Directory, error) { - q := r.query.Select("sync") +// A definition of a field on a custom object defined in a Module. +// +// A field on an object has a static value, as opposed to a function on an object whose value is computed by invoking code (and can accept arguments). +type FieldTypeDef struct { + query *querybuilder.Selection - return r, q.Execute(ctx) + description *string + id *FieldTypeDefID + name *string } -// DirectoryWithDirectoryOpts contains options for Directory.WithDirectory -type DirectoryWithDirectoryOpts struct { - // Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]). - Exclude []string - // Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]). - Include []string +func (r *FieldTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *FieldTypeDef { + return &FieldTypeDef{ + query: q, + } } -// Retrieves this directory plus a directory written at the given path. -func (r *Directory) WithDirectory(path string, directory *Directory, opts ...DirectoryWithDirectoryOpts) *Directory { - assertNotNil("directory", directory) - q := r.query.Select("withDirectory") - for i := len(opts) - 1; i >= 0; i-- { - // `exclude` optional argument - if !querybuilder.IsZeroValue(opts[i].Exclude) { - q = q.Arg("exclude", opts[i].Exclude) - } - // `include` optional argument - if !querybuilder.IsZeroValue(opts[i].Include) { - q = q.Arg("include", opts[i].Include) - } +// A doc string for the field, if any. +func (r *FieldTypeDef) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil } - q = q.Arg("path", path) - q = q.Arg("directory", directory) + q := r.query.Select("description") - return &Directory{ - query: q, + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this FieldTypeDef. +func (r *FieldTypeDef) ID(ctx context.Context) (FieldTypeDefID, error) { + if r.id != nil { + return *r.id, nil } + q := r.query.Select("id") + + var response FieldTypeDefID + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// DirectoryWithFileOpts contains options for Directory.WithFile -type DirectoryWithFileOpts struct { - // Permission given to the copied file (e.g., 0600). - Permissions int +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *FieldTypeDef) XXX_GraphQLType() string { + return "FieldTypeDef" } -// Retrieves this directory plus the contents of the given file copied to the given path. -func (r *Directory) WithFile(path string, source *File, opts ...DirectoryWithFileOpts) *Directory { - assertNotNil("source", source) - q := r.query.Select("withFile") - for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *FieldTypeDef) XXX_GraphQLIDType() string { + return "FieldTypeDefID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *FieldTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err } - q = q.Arg("path", path) - q = q.Arg("source", source) + return string(id), nil +} - return &Directory{ - query: q, +func (r *FieldTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *FieldTypeDef) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err } + *r = *dag.LoadFieldTypeDefFromID(FieldTypeDefID(id)) + return nil } -// DirectoryWithFilesOpts contains options for Directory.WithFiles -type DirectoryWithFilesOpts struct { - // Permission given to the copied files (e.g., 0600). - Permissions int +// The name of the field in lowerCamelCase format. +func (r *FieldTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Retrieves this directory plus the contents of the given files copied to the given path. -func (r *Directory) WithFiles(path string, sources []*File, opts ...DirectoryWithFilesOpts) *Directory { - q := r.query.Select("withFiles") - for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } - } - q = q.Arg("path", path) - q = q.Arg("sources", sources) +// The location of this field declaration. +func (r *FieldTypeDef) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") - return &Directory{ + return &SourceMap{ query: q, } } -// DirectoryWithNewDirectoryOpts contains options for Directory.WithNewDirectory -type DirectoryWithNewDirectoryOpts struct { - // Permission granted to the created directory (e.g., 0777). - Permissions int -} - -// Retrieves this directory plus a new directory created at the given path. -func (r *Directory) WithNewDirectory(path string, opts ...DirectoryWithNewDirectoryOpts) *Directory { - q := r.query.Select("withNewDirectory") - for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } - } - q = q.Arg("path", path) +// The type of the field. +func (r *FieldTypeDef) TypeDef() *TypeDef { + q := r.query.Select("typeDef") - return &Directory{ + return &TypeDef{ query: q, } } -// DirectoryWithNewFileOpts contains options for Directory.WithNewFile -type DirectoryWithNewFileOpts struct { - // Permission given to the copied file (e.g., 0600). - Permissions int +// A file. +type File struct { + query *querybuilder.Selection + + contents *string + digest *string + export *string + id *FileID + name *string + size *int + sync *FileID } +type WithFileFunc func(r *File) *File -// Retrieves this directory plus a new file written at the given path. -func (r *Directory) WithNewFile(path string, contents string, opts ...DirectoryWithNewFileOpts) *Directory { - q := r.query.Select("withNewFile") - for i := len(opts) - 1; i >= 0; i-- { - // `permissions` optional argument - if !querybuilder.IsZeroValue(opts[i].Permissions) { - q = q.Arg("permissions", opts[i].Permissions) - } - } - q = q.Arg("path", path) - q = q.Arg("contents", contents) +// With calls the provided function with current File. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *File) With(f WithFileFunc) *File { + return f(r) +} - return &Directory{ +func (r *File) WithGraphQLQuery(q *querybuilder.Selection) *File { + return &File{ query: q, } } -// Retrieves this directory with all file/dir timestamps set to the given time. -func (r *Directory) WithTimestamps(timestamp int) *Directory { - q := r.query.Select("withTimestamps") - q = q.Arg("timestamp", timestamp) - - return &Directory{ - query: q, +// Retrieves the contents of the file. +func (r *File) Contents(ctx context.Context) (string, error) { + if r.contents != nil { + return *r.contents, nil } -} + q := r.query.Select("contents") -// Retrieves this directory with the directory at the given path removed. -func (r *Directory) WithoutDirectory(path string) *Directory { - q := r.query.Select("withoutDirectory") - q = q.Arg("path", path) + var response string - return &Directory{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Retrieves this directory with the file at the given path removed. -func (r *Directory) WithoutFile(path string) *Directory { - q := r.query.Select("withoutFile") - q = q.Arg("path", path) +// FileDigestOpts contains options for File.Digest +type FileDigestOpts struct { + // If true, exclude metadata from the digest. + ExcludeMetadata bool +} - return &Directory{ - query: q, +// Return the file's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same Dagger engine. +func (r *File) Digest(ctx context.Context, opts ...FileDigestOpts) (string, error) { + if r.digest != nil { + return *r.digest, nil + } + q := r.query.Select("digest") + for i := len(opts) - 1; i >= 0; i-- { + // `excludeMetadata` optional argument + if !querybuilder.IsZeroValue(opts[i].ExcludeMetadata) { + q = q.Arg("excludeMetadata", opts[i].ExcludeMetadata) + } } -} -// An environment variable name and value. -type EnvVariable struct { - query *querybuilder.Selection + var response string - id *EnvVariableID - name *string - value *string + q = q.Bind(&response) + return response, q.Execute(ctx) } -func (r *EnvVariable) WithGraphQLQuery(q *querybuilder.Selection) *EnvVariable { - return &EnvVariable{ - query: q, +// FileExportOpts contains options for File.Export +type FileExportOpts struct { + // If allowParentDirPath is true, the path argument can be a directory path, in which case the file will be created in that directory. + AllowParentDirPath bool +} + +// Writes the file to a file path on the host. +func (r *File) Export(ctx context.Context, path string, opts ...FileExportOpts) (string, error) { + if r.export != nil { + return *r.export, nil } + q := r.query.Select("export") + for i := len(opts) - 1; i >= 0; i-- { + // `allowParentDirPath` optional argument + if !querybuilder.IsZeroValue(opts[i].AllowParentDirPath) { + q = q.Arg("allowParentDirPath", opts[i].AllowParentDirPath) + } + } + q = q.Arg("path", path) + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// A unique identifier for this EnvVariable. -func (r *EnvVariable) ID(ctx context.Context) (EnvVariableID, error) { +// A unique identifier for this File. +func (r *File) ID(ctx context.Context) (FileID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response EnvVariableID + var response FileID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *EnvVariable) XXX_GraphQLType() string { - return "EnvVariable" +func (r *File) XXX_GraphQLType() string { + return "File" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *EnvVariable) XXX_GraphQLIDType() string { - return "EnvVariableID" +func (r *File) XXX_GraphQLIDType() string { + return "FileID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *EnvVariable) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *File) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2282,25 +4682,25 @@ func (r *EnvVariable) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *EnvVariable) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *File) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *EnvVariable) UnmarshalJSON(bs []byte) error { +func (r *File) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadEnvVariableFromID(EnvVariableID(id)) + *r = *dag.LoadFileFromID(FileID(id)) return nil } -// The environment variable name. -func (r *EnvVariable) Name(ctx context.Context) (string, error) { +// Retrieves the name of the file. +func (r *File) Name(ctx context.Context) (string, error) { if r.name != nil { return *r.name, nil } @@ -2312,38 +4712,112 @@ func (r *EnvVariable) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The environment variable value. -func (r *EnvVariable) Value(ctx context.Context) (string, error) { - if r.value != nil { - return *r.value, nil +// Retrieves the size of the file, in bytes. +func (r *File) Size(ctx context.Context) (int, error) { + if r.size != nil { + return *r.size, nil } - q := r.query.Select("value") + q := r.query.Select("size") - var response string + var response int + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Force evaluation in the engine. +func (r *File) Sync(ctx context.Context) (*File, error) { + q := r.query.Select("sync") + + var id FileID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &File{ + query: q.Root().Select("loadFileFromID").Arg("id", id), + }, nil +} + +// Retrieves this file with its name set to the given name. +func (r *File) WithName(name string) *File { + q := r.query.Select("withName") + q = q.Arg("name", name) + + return &File{ + query: q, + } +} + +// Retrieves this file with its created/modified timestamps set to the given time. +func (r *File) WithTimestamps(timestamp int) *File { + q := r.query.Select("withTimestamps") + q = q.Arg("timestamp", timestamp) + + return &File{ + query: q, + } +} + +// Function represents a resolver provided by a Module. +// +// A function always evaluates against a parent object and is given a set of named arguments. +type Function struct { + query *querybuilder.Selection + + description *string + id *FunctionID + name *string +} +type WithFunctionFunc func(r *Function) *Function + +// With calls the provided function with current Function. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *Function) With(f WithFunctionFunc) *Function { + return f(r) +} + +func (r *Function) WithGraphQLQuery(q *querybuilder.Selection) *Function { + return &Function{ + query: q, + } +} + +// Arguments accepted by the function, if any. +func (r *Function) Args(ctx context.Context) ([]FunctionArg, error) { + q := r.query.Select("args") + + q = q.Select("id") + + type args struct { + Id FunctionArgID + } + + convert := func(fields []args) []FunctionArg { + out := []FunctionArg{} - q = q.Bind(&response) - return response, q.Execute(ctx) -} + for i := range fields { + val := FunctionArg{id: &fields[i].Id} + val.query = q.Root().Select("loadFunctionArgFromID").Arg("id", fields[i].Id) + out = append(out, val) + } -// A definition of a field on a custom object defined in a Module. -// -// A field on an object has a static value, as opposed to a function on an object whose value is computed by invoking code (and can accept arguments). -type FieldTypeDef struct { - query *querybuilder.Selection + return out + } + var response []args - description *string - id *FieldTypeDefID - name *string -} + q = q.Bind(&response) -func (r *FieldTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *FieldTypeDef { - return &FieldTypeDef{ - query: q, + err := q.Execute(ctx) + if err != nil { + return nil, err } + + return convert(response), nil } -// A doc string for the field, if any. -func (r *FieldTypeDef) Description(ctx context.Context) (string, error) { +// A doc string for the function, if any. +func (r *Function) Description(ctx context.Context) (string, error) { if r.description != nil { return *r.description, nil } @@ -2355,31 +4829,31 @@ func (r *FieldTypeDef) Description(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// A unique identifier for this FieldTypeDef. -func (r *FieldTypeDef) ID(ctx context.Context) (FieldTypeDefID, error) { +// A unique identifier for this Function. +func (r *Function) ID(ctx context.Context) (FunctionID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response FieldTypeDefID + var response FunctionID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *FieldTypeDef) XXX_GraphQLType() string { - return "FieldTypeDef" +func (r *Function) XXX_GraphQLType() string { + return "Function" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *FieldTypeDef) XXX_GraphQLIDType() string { - return "FieldTypeDefID" +func (r *Function) XXX_GraphQLIDType() string { + return "FunctionID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *FieldTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *Function) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2387,25 +4861,25 @@ func (r *FieldTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *FieldTypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *Function) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *FieldTypeDef) UnmarshalJSON(bs []byte) error { +func (r *Function) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadFieldTypeDefFromID(FieldTypeDefID(id)) + *r = *dag.LoadFunctionFromID(FunctionID(id)) return nil } -// The name of the field in lowerCamelCase format. -func (r *FieldTypeDef) Name(ctx context.Context) (string, error) { +// The name of the function. +func (r *Function) Name(ctx context.Context) (string, error) { if r.name != nil { return *r.name, nil } @@ -2417,47 +4891,118 @@ func (r *FieldTypeDef) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The type of the field. -func (r *FieldTypeDef) TypeDef() *TypeDef { - q := r.query.Select("typeDef") +// The type returned by the function. +func (r *Function) ReturnType() *TypeDef { + q := r.query.Select("returnType") return &TypeDef{ query: q, } } -// A file. -type File struct { - query *querybuilder.Selection +// The location of this function declaration. +func (r *Function) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") - contents *string - export *bool - id *FileID - name *string - size *int - sync *FileID + return &SourceMap{ + query: q, + } } -type WithFileFunc func(r *File) *File -// With calls the provided function with current File. +// FunctionWithArgOpts contains options for Function.WithArg +type FunctionWithArgOpts struct { + // A doc string for the argument, if any + Description string + // A default value to use for this argument if not explicitly set by the caller, if any + DefaultValue JSON + // If the argument is a Directory or File type, default to load path from context directory, relative to root directory. + DefaultPath string + // Patterns to ignore when loading the contextual argument value. + Ignore []string + // The source map for the argument definition. + SourceMap *SourceMap +} + +// Returns the function with the provided argument +func (r *Function) WithArg(name string, typeDef *TypeDef, opts ...FunctionWithArgOpts) *Function { + assertNotNil("typeDef", typeDef) + q := r.query.Select("withArg") + for i := len(opts) - 1; i >= 0; i-- { + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + // `defaultValue` optional argument + if !querybuilder.IsZeroValue(opts[i].DefaultValue) { + q = q.Arg("defaultValue", opts[i].DefaultValue) + } + // `defaultPath` optional argument + if !querybuilder.IsZeroValue(opts[i].DefaultPath) { + q = q.Arg("defaultPath", opts[i].DefaultPath) + } + // `ignore` optional argument + if !querybuilder.IsZeroValue(opts[i].Ignore) { + q = q.Arg("ignore", opts[i].Ignore) + } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } + } + q = q.Arg("name", name) + q = q.Arg("typeDef", typeDef) + + return &Function{ + query: q, + } +} + +// Returns the function with the given doc string. +func (r *Function) WithDescription(description string) *Function { + q := r.query.Select("withDescription") + q = q.Arg("description", description) + + return &Function{ + query: q, + } +} + +// Returns the function with the given source map. +func (r *Function) WithSourceMap(sourceMap *SourceMap) *Function { + assertNotNil("sourceMap", sourceMap) + q := r.query.Select("withSourceMap") + q = q.Arg("sourceMap", sourceMap) + + return &Function{ + query: q, + } +} + +// An argument accepted by a function. // -// This is useful for reusability and readability by not breaking the calling chain. -func (r *File) With(f WithFileFunc) *File { - return f(r) +// This is a specification for an argument at function definition time, not an argument passed at function call time. +type FunctionArg struct { + query *querybuilder.Selection + + defaultPath *string + defaultValue *JSON + description *string + id *FunctionArgID + name *string } -func (r *File) WithGraphQLQuery(q *querybuilder.Selection) *File { - return &File{ +func (r *FunctionArg) WithGraphQLQuery(q *querybuilder.Selection) *FunctionArg { + return &FunctionArg{ query: q, } } -// Retrieves the contents of the file. -func (r *File) Contents(ctx context.Context) (string, error) { - if r.contents != nil { - return *r.contents, nil +// Only applies to arguments of type File or Directory. If the argument is not set, load it from the given path in the context directory +func (r *FunctionArg) DefaultPath(ctx context.Context) (string, error) { + if r.defaultPath != nil { + return *r.defaultPath, nil } - q := r.query.Select("contents") + q := r.query.Select("defaultPath") var response string @@ -2465,57 +5010,57 @@ func (r *File) Contents(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// FileExportOpts contains options for File.Export -type FileExportOpts struct { - // If allowParentDirPath is true, the path argument can be a directory path, in which case the file will be created in that directory. - AllowParentDirPath bool +// A default value to use for this argument when not explicitly set by the caller, if any. +func (r *FunctionArg) DefaultValue(ctx context.Context) (JSON, error) { + if r.defaultValue != nil { + return *r.defaultValue, nil + } + q := r.query.Select("defaultValue") + + var response JSON + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Writes the file to a file path on the host. -func (r *File) Export(ctx context.Context, path string, opts ...FileExportOpts) (bool, error) { - if r.export != nil { - return *r.export, nil - } - q := r.query.Select("export") - for i := len(opts) - 1; i >= 0; i-- { - // `allowParentDirPath` optional argument - if !querybuilder.IsZeroValue(opts[i].AllowParentDirPath) { - q = q.Arg("allowParentDirPath", opts[i].AllowParentDirPath) - } +// A doc string for the argument, if any. +func (r *FunctionArg) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil } - q = q.Arg("path", path) + q := r.query.Select("description") - var response bool + var response string q = q.Bind(&response) return response, q.Execute(ctx) } -// A unique identifier for this File. -func (r *File) ID(ctx context.Context) (FileID, error) { +// A unique identifier for this FunctionArg. +func (r *FunctionArg) ID(ctx context.Context) (FunctionArgID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response FileID + var response FunctionArgID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *File) XXX_GraphQLType() string { - return "File" +func (r *FunctionArg) XXX_GraphQLType() string { + return "FunctionArg" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *File) XXX_GraphQLIDType() string { - return "FileID" +func (r *FunctionArg) XXX_GraphQLIDType() string { + return "FunctionArgID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *File) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *FunctionArg) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2523,25 +5068,35 @@ func (r *File) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *File) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *FunctionArg) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *File) UnmarshalJSON(bs []byte) error { +func (r *FunctionArg) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadFileFromID(FileID(id)) + *r = *dag.LoadFunctionArgFromID(FunctionArgID(id)) return nil } -// Retrieves the name of the file. -func (r *File) Name(ctx context.Context) (string, error) { +// Only applies to arguments of type Directory. The ignore patterns are applied to the input directory, and matching entries are filtered out, in a cache-efficient manner. +func (r *FunctionArg) Ignore(ctx context.Context) ([]string, error) { + q := r.query.Select("ignore") + + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The name of the argument in lowerCamelCase format. +func (r *FunctionArg) Name(ctx context.Context) (string, error) { if r.name != nil { return *r.name, nil } @@ -2553,83 +5108,113 @@ func (r *File) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// Retrieves the size of the file, in bytes. -func (r *File) Size(ctx context.Context) (int, error) { - if r.size != nil { - return *r.size, nil +// The location of this arg declaration. +func (r *FunctionArg) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") + + return &SourceMap{ + query: q, } - q := r.query.Select("size") +} - var response int +// The type of the argument. +func (r *FunctionArg) TypeDef() *TypeDef { + q := r.query.Select("typeDef") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &TypeDef{ + query: q, + } } -// Force evaluation in the engine. -func (r *File) Sync(ctx context.Context) (*File, error) { - q := r.query.Select("sync") +// An active function call. +type FunctionCall struct { + query *querybuilder.Selection - return r, q.Execute(ctx) + id *FunctionCallID + name *string + parent *JSON + parentName *string + returnError *Void + returnValue *Void } -// Retrieves this file with its created/modified timestamps set to the given time. -func (r *File) WithTimestamps(timestamp int) *File { - q := r.query.Select("withTimestamps") - q = q.Arg("timestamp", timestamp) - - return &File{ +func (r *FunctionCall) WithGraphQLQuery(q *querybuilder.Selection) *FunctionCall { + return &FunctionCall{ query: q, } } -// Function represents a resolver provided by a Module. -// -// A function always evaluates against a parent object and is given a set of named arguments. -type Function struct { - query *querybuilder.Selection +// A unique identifier for this FunctionCall. +func (r *FunctionCall) ID(ctx context.Context) (FunctionCallID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response FunctionCallID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *FunctionCall) XXX_GraphQLType() string { + return "FunctionCall" +} - description *string - id *FunctionID - name *string +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *FunctionCall) XXX_GraphQLIDType() string { + return "FunctionCallID" } -type WithFunctionFunc func(r *Function) *Function -// With calls the provided function with current Function. -// -// This is useful for reusability and readability by not breaking the calling chain. -func (r *Function) With(f WithFunctionFunc) *Function { - return f(r) +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *FunctionCall) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil } -func (r *Function) WithGraphQLQuery(q *querybuilder.Selection) *Function { - return &Function{ - query: q, +func (r *FunctionCall) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *FunctionCall) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err } + *r = *dag.LoadFunctionCallFromID(FunctionCallID(id)) + return nil } -// Arguments accepted by the function, if any. -func (r *Function) Args(ctx context.Context) ([]FunctionArg, error) { - q := r.query.Select("args") +// The argument values the function is being invoked with. +func (r *FunctionCall) InputArgs(ctx context.Context) ([]FunctionCallArgValue, error) { + q := r.query.Select("inputArgs") q = q.Select("id") - type args struct { - Id FunctionArgID + type inputArgs struct { + Id FunctionCallArgValueID } - convert := func(fields []args) []FunctionArg { - out := []FunctionArg{} + convert := func(fields []inputArgs) []FunctionCallArgValue { + out := []FunctionCallArgValue{} for i := range fields { - val := FunctionArg{id: &fields[i].Id} - val.query = q.Root().Select("loadFunctionArgFromID").Arg("id", fields[i].Id) + val := FunctionCallArgValue{id: &fields[i].Id} + val.query = q.Root().Select("loadFunctionCallArgValueFromID").Arg("id", fields[i].Id) out = append(out, val) } return out } - var response []args + var response []inputArgs q = q.Bind(&response) @@ -2641,12 +5226,12 @@ func (r *Function) Args(ctx context.Context) ([]FunctionArg, error) { return convert(response), nil } -// A doc string for the function, if any. -func (r *Function) Description(ctx context.Context) (string, error) { - if r.description != nil { - return *r.description, nil +// The name of the function being called. +func (r *FunctionCall) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil } - q := r.query.Select("description") + q := r.query.Select("name") var response string @@ -2654,31 +5239,95 @@ func (r *Function) Description(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// A unique identifier for this Function. -func (r *Function) ID(ctx context.Context) (FunctionID, error) { +// The value of the parent object of the function being called. If the function is top-level to the module, this is always an empty object. +func (r *FunctionCall) Parent(ctx context.Context) (JSON, error) { + if r.parent != nil { + return *r.parent, nil + } + q := r.query.Select("parent") + + var response JSON + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The name of the parent object of the function being called. If the function is top-level to the module, this is the name of the module. +func (r *FunctionCall) ParentName(ctx context.Context) (string, error) { + if r.parentName != nil { + return *r.parentName, nil + } + q := r.query.Select("parentName") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Return an error from the function. +func (r *FunctionCall) ReturnError(ctx context.Context, error *Error) error { + assertNotNil("error", error) + if r.returnError != nil { + return nil + } + q := r.query.Select("returnError") + q = q.Arg("error", error) + + return q.Execute(ctx) +} + +// Set the return value of the function call to the provided value. +func (r *FunctionCall) ReturnValue(ctx context.Context, value JSON) error { + if r.returnValue != nil { + return nil + } + q := r.query.Select("returnValue") + q = q.Arg("value", value) + + return q.Execute(ctx) +} + +// A value passed as a named argument to a function call. +type FunctionCallArgValue struct { + query *querybuilder.Selection + + id *FunctionCallArgValueID + name *string + value *JSON +} + +func (r *FunctionCallArgValue) WithGraphQLQuery(q *querybuilder.Selection) *FunctionCallArgValue { + return &FunctionCallArgValue{ + query: q, + } +} + +// A unique identifier for this FunctionCallArgValue. +func (r *FunctionCallArgValue) ID(ctx context.Context) (FunctionCallArgValueID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response FunctionID + var response FunctionCallArgValueID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *Function) XXX_GraphQLType() string { - return "Function" +func (r *FunctionCallArgValue) XXX_GraphQLType() string { + return "FunctionCallArgValue" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *Function) XXX_GraphQLIDType() string { - return "FunctionID" +func (r *FunctionCallArgValue) XXX_GraphQLIDType() string { + return "FunctionCallArgValueID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *Function) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *FunctionCallArgValue) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2686,25 +5335,25 @@ func (r *Function) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *Function) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *FunctionCallArgValue) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *Function) UnmarshalJSON(bs []byte) error { +func (r *FunctionCallArgValue) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadFunctionFromID(FunctionID(id)) + *r = *dag.LoadFunctionCallArgValueFromID(FunctionCallArgValueID(id)) return nil } -// The name of the function. -func (r *Function) Name(ctx context.Context) (string, error) { +// The name of the argument. +func (r *FunctionCallArgValue) Name(ctx context.Context) (string, error) { if r.name != nil { return *r.name, nil } @@ -2716,124 +5365,74 @@ func (r *Function) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The type returned by the function. -func (r *Function) ReturnType() *TypeDef { - q := r.query.Select("returnType") - - return &TypeDef{ - query: q, +// The value of the argument represented as a JSON serialized string. +func (r *FunctionCallArgValue) Value(ctx context.Context) (JSON, error) { + if r.value != nil { + return *r.value, nil } -} - -// FunctionWithArgOpts contains options for Function.WithArg -type FunctionWithArgOpts struct { - // A doc string for the argument, if any - Description string - // A default value to use for this argument if not explicitly set by the caller, if any - DefaultValue JSON -} + q := r.query.Select("value") -// Returns the function with the provided argument -func (r *Function) WithArg(name string, typeDef *TypeDef, opts ...FunctionWithArgOpts) *Function { - assertNotNil("typeDef", typeDef) - q := r.query.Select("withArg") - for i := len(opts) - 1; i >= 0; i-- { - // `description` optional argument - if !querybuilder.IsZeroValue(opts[i].Description) { - q = q.Arg("description", opts[i].Description) - } - // `defaultValue` optional argument - if !querybuilder.IsZeroValue(opts[i].DefaultValue) { - q = q.Arg("defaultValue", opts[i].DefaultValue) - } - } - q = q.Arg("name", name) - q = q.Arg("typeDef", typeDef) + var response JSON - return &Function{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Returns the function with the given doc string. -func (r *Function) WithDescription(description string) *Function { - q := r.query.Select("withDescription") - q = q.Arg("description", description) +// The result of running an SDK's codegen. +type GeneratedCode struct { + query *querybuilder.Selection - return &Function{ - query: q, - } + id *GeneratedCodeID } +type WithGeneratedCodeFunc func(r *GeneratedCode) *GeneratedCode -// An argument accepted by a function. +// With calls the provided function with current GeneratedCode. // -// This is a specification for an argument at function definition time, not an argument passed at function call time. -type FunctionArg struct { - query *querybuilder.Selection - - defaultValue *JSON - description *string - id *FunctionArgID - name *string +// This is useful for reusability and readability by not breaking the calling chain. +func (r *GeneratedCode) With(f WithGeneratedCodeFunc) *GeneratedCode { + return f(r) } -func (r *FunctionArg) WithGraphQLQuery(q *querybuilder.Selection) *FunctionArg { - return &FunctionArg{ +func (r *GeneratedCode) WithGraphQLQuery(q *querybuilder.Selection) *GeneratedCode { + return &GeneratedCode{ query: q, } } -// A default value to use for this argument when not explicitly set by the caller, if any. -func (r *FunctionArg) DefaultValue(ctx context.Context) (JSON, error) { - if r.defaultValue != nil { - return *r.defaultValue, nil - } - q := r.query.Select("defaultValue") - - var response JSON - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// A doc string for the argument, if any. -func (r *FunctionArg) Description(ctx context.Context) (string, error) { - if r.description != nil { - return *r.description, nil - } - q := r.query.Select("description") - - var response string +// The directory containing the generated code. +func (r *GeneratedCode) Code() *Directory { + q := r.query.Select("code") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Directory{ + query: q, + } } -// A unique identifier for this FunctionArg. -func (r *FunctionArg) ID(ctx context.Context) (FunctionArgID, error) { +// A unique identifier for this GeneratedCode. +func (r *GeneratedCode) ID(ctx context.Context) (GeneratedCodeID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response FunctionArgID + var response GeneratedCodeID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *FunctionArg) XXX_GraphQLType() string { - return "FunctionArg" +func (r *GeneratedCode) XXX_GraphQLType() string { + return "GeneratedCode" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *FunctionArg) XXX_GraphQLIDType() string { - return "FunctionArgID" +func (r *GeneratedCode) XXX_GraphQLIDType() string { + return "GeneratedCodeID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *FunctionArg) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *GeneratedCode) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2841,87 +5440,135 @@ func (r *FunctionArg) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *FunctionArg) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *GeneratedCode) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *FunctionArg) UnmarshalJSON(bs []byte) error { +func (r *GeneratedCode) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadFunctionArgFromID(FunctionArgID(id)) + *r = *dag.LoadGeneratedCodeFromID(GeneratedCodeID(id)) return nil } -// The name of the argument in lowerCamelCase format. -func (r *FunctionArg) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil - } - q := r.query.Select("name") +// List of paths to mark generated in version control (i.e. .gitattributes). +func (r *GeneratedCode) VcsGeneratedPaths(ctx context.Context) ([]string, error) { + q := r.query.Select("vcsGeneratedPaths") - var response string + var response []string q = q.Bind(&response) return response, q.Execute(ctx) } -// The type of the argument. -func (r *FunctionArg) TypeDef() *TypeDef { - q := r.query.Select("typeDef") +// List of paths to ignore in version control (i.e. .gitignore). +func (r *GeneratedCode) VcsIgnoredPaths(ctx context.Context) ([]string, error) { + q := r.query.Select("vcsIgnoredPaths") - return &TypeDef{ + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Set the list of paths to mark generated in version control. +func (r *GeneratedCode) WithVCSGeneratedPaths(paths []string) *GeneratedCode { + q := r.query.Select("withVCSGeneratedPaths") + q = q.Arg("paths", paths) + + return &GeneratedCode{ query: q, } } -// An active function call. -type FunctionCall struct { +// Set the list of paths to ignore in version control. +func (r *GeneratedCode) WithVCSIgnoredPaths(paths []string) *GeneratedCode { + q := r.query.Select("withVCSIgnoredPaths") + q = q.Arg("paths", paths) + + return &GeneratedCode{ + query: q, + } +} + +// A git ref (tag, branch, or commit). +type GitRef struct { query *querybuilder.Selection - id *FunctionCallID - name *string - parent *JSON - parentName *string - returnValue *Void + commit *string + id *GitRefID + ref *string } +type WithGitRefFunc func(r *GitRef) *GitRef -func (r *FunctionCall) WithGraphQLQuery(q *querybuilder.Selection) *FunctionCall { - return &FunctionCall{ +// With calls the provided function with current GitRef. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *GitRef) With(f WithGitRefFunc) *GitRef { + return f(r) +} + +func (r *GitRef) WithGraphQLQuery(q *querybuilder.Selection) *GitRef { + return &GitRef{ query: q, } } -// A unique identifier for this FunctionCall. -func (r *FunctionCall) ID(ctx context.Context) (FunctionCallID, error) { +// The resolved commit id at this ref. +func (r *GitRef) Commit(ctx context.Context) (string, error) { + if r.commit != nil { + return *r.commit, nil + } + q := r.query.Select("commit") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Find the best common ancestor between this ref and another ref. +func (r *GitRef) CommonAncestor(other *GitRef) *GitRef { + assertNotNil("other", other) + q := r.query.Select("commonAncestor") + q = q.Arg("other", other) + + return &GitRef{ + query: q, + } +} + +// A unique identifier for this GitRef. +func (r *GitRef) ID(ctx context.Context) (GitRefID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response FunctionCallID + var response GitRefID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *FunctionCall) XXX_GraphQLType() string { - return "FunctionCall" +func (r *GitRef) XXX_GraphQLType() string { + return "GitRef" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *FunctionCall) XXX_GraphQLIDType() string { - return "FunctionCallID" +func (r *GitRef) XXX_GraphQLIDType() string { + return "GitRefID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *FunctionCall) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *GitRef) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -2929,62 +5576,29 @@ func (r *FunctionCall) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *FunctionCall) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *GitRef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *FunctionCall) UnmarshalJSON(bs []byte) error { +func (r *GitRef) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadFunctionCallFromID(FunctionCallID(id)) + *r = *dag.LoadGitRefFromID(GitRefID(id)) return nil } -// The argument values the function is being invoked with. -func (r *FunctionCall) InputArgs(ctx context.Context) ([]FunctionCallArgValue, error) { - q := r.query.Select("inputArgs") - - q = q.Select("id") - - type inputArgs struct { - Id FunctionCallArgValueID - } - - convert := func(fields []inputArgs) []FunctionCallArgValue { - out := []FunctionCallArgValue{} - - for i := range fields { - val := FunctionCallArgValue{id: &fields[i].Id} - val.query = q.Root().Select("loadFunctionCallArgValueFromID").Arg("id", fields[i].Id) - out = append(out, val) - } - - return out - } - var response []inputArgs - - q = q.Bind(&response) - - err := q.Execute(ctx) - if err != nil { - return nil, err - } - - return convert(response), nil -} - -// The name of the function being called. -func (r *FunctionCall) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil +// The resolved ref name at this ref. +func (r *GitRef) Ref(ctx context.Context) (string, error) { + if r.ref != nil { + return *r.ref, nil } - q := r.query.Select("name") + q := r.query.Select("ref") var response string @@ -2992,191 +5606,132 @@ func (r *FunctionCall) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The value of the parent object of the function being called. If the function is top-level to the module, this is always an empty object. -func (r *FunctionCall) Parent(ctx context.Context) (JSON, error) { - if r.parent != nil { - return *r.parent, nil - } - q := r.query.Select("parent") - - var response JSON - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// The name of the parent object of the function being called. If the function is top-level to the module, this is the name of the module. -func (r *FunctionCall) ParentName(ctx context.Context) (string, error) { - if r.parentName != nil { - return *r.parentName, nil - } - q := r.query.Select("parentName") - - var response string - - q = q.Bind(&response) - return response, q.Execute(ctx) +// GitRefTreeOpts contains options for GitRef.Tree +type GitRefTreeOpts struct { + // Set to true to discard .git directory. + DiscardGitDir bool + // The depth of the tree to fetch. + // + // Default: 1 + Depth int } -// Set the return value of the function call to the provided value. -func (r *FunctionCall) ReturnValue(ctx context.Context, value JSON) (Void, error) { - if r.returnValue != nil { - return *r.returnValue, nil +// The filesystem tree at this ref. +func (r *GitRef) Tree(opts ...GitRefTreeOpts) *Directory { + q := r.query.Select("tree") + for i := len(opts) - 1; i >= 0; i-- { + // `discardGitDir` optional argument + if !querybuilder.IsZeroValue(opts[i].DiscardGitDir) { + q = q.Arg("discardGitDir", opts[i].DiscardGitDir) + } + // `depth` optional argument + if !querybuilder.IsZeroValue(opts[i].Depth) { + q = q.Arg("depth", opts[i].Depth) + } } - q := r.query.Select("returnValue") - q = q.Arg("value", value) - - var response Void - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// A value passed as a named argument to a function call. -type FunctionCallArgValue struct { - query *querybuilder.Selection - - id *FunctionCallArgValueID - name *string - value *JSON -} -func (r *FunctionCallArgValue) WithGraphQLQuery(q *querybuilder.Selection) *FunctionCallArgValue { - return &FunctionCallArgValue{ + return &Directory{ query: q, } } -// A unique identifier for this FunctionCallArgValue. -func (r *FunctionCallArgValue) ID(ctx context.Context) (FunctionCallArgValueID, error) { - if r.id != nil { - return *r.id, nil - } - q := r.query.Select("id") - - var response FunctionCallArgValueID - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *FunctionCallArgValue) XXX_GraphQLType() string { - return "FunctionCallArgValue" -} +// A git repository. +type GitRepository struct { + query *querybuilder.Selection -// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *FunctionCallArgValue) XXX_GraphQLIDType() string { - return "FunctionCallArgValueID" + id *GitRepositoryID } +type WithGitRepositoryFunc func(r *GitRepository) *GitRepository -// XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *FunctionCallArgValue) XXX_GraphQLID(ctx context.Context) (string, error) { - id, err := r.ID(ctx) - if err != nil { - return "", err - } - return string(id), nil +// With calls the provided function with current GitRepository. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *GitRepository) With(f WithGitRepositoryFunc) *GitRepository { + return f(r) } -func (r *FunctionCallArgValue) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) - if err != nil { - return nil, err - } - return json.Marshal(id) -} -func (r *FunctionCallArgValue) UnmarshalJSON(bs []byte) error { - var id string - err := json.Unmarshal(bs, &id) - if err != nil { - return err +func (r *GitRepository) WithGraphQLQuery(q *querybuilder.Selection) *GitRepository { + return &GitRepository{ + query: q, } - *r = *dag.LoadFunctionCallArgValueFromID(FunctionCallArgValueID(id)) - return nil } -// The name of the argument. -func (r *FunctionCallArgValue) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil - } - q := r.query.Select("name") +// Returns details of a branch. +func (r *GitRepository) Branch(name string) *GitRef { + q := r.query.Select("branch") + q = q.Arg("name", name) - var response string + return &GitRef{ + query: q, + } +} - q = q.Bind(&response) - return response, q.Execute(ctx) +// GitRepositoryBranchesOpts contains options for GitRepository.Branches +type GitRepositoryBranchesOpts struct { + // Glob patterns (e.g., "refs/tags/v*"). + Patterns []string } -// The value of the argument represented as a JSON serialized string. -func (r *FunctionCallArgValue) Value(ctx context.Context) (JSON, error) { - if r.value != nil { - return *r.value, nil +// branches that match any of the given glob patterns. +func (r *GitRepository) Branches(ctx context.Context, opts ...GitRepositoryBranchesOpts) ([]string, error) { + q := r.query.Select("branches") + for i := len(opts) - 1; i >= 0; i-- { + // `patterns` optional argument + if !querybuilder.IsZeroValue(opts[i].Patterns) { + q = q.Arg("patterns", opts[i].Patterns) + } } - q := r.query.Select("value") - var response JSON + var response []string q = q.Bind(&response) return response, q.Execute(ctx) } -// The result of running an SDK's codegen. -type GeneratedCode struct { - query *querybuilder.Selection - - id *GeneratedCodeID -} -type WithGeneratedCodeFunc func(r *GeneratedCode) *GeneratedCode - -// With calls the provided function with current GeneratedCode. -// -// This is useful for reusability and readability by not breaking the calling chain. -func (r *GeneratedCode) With(f WithGeneratedCodeFunc) *GeneratedCode { - return f(r) -} +// Returns details of a commit. +func (r *GitRepository) Commit(id string) *GitRef { + q := r.query.Select("commit") + q = q.Arg("id", id) -func (r *GeneratedCode) WithGraphQLQuery(q *querybuilder.Selection) *GeneratedCode { - return &GeneratedCode{ + return &GitRef{ query: q, } } -// The directory containing the generated code. -func (r *GeneratedCode) Code() *Directory { - q := r.query.Select("code") +// Returns details for HEAD. +func (r *GitRepository) Head() *GitRef { + q := r.query.Select("head") - return &Directory{ + return &GitRef{ query: q, } } -// A unique identifier for this GeneratedCode. -func (r *GeneratedCode) ID(ctx context.Context) (GeneratedCodeID, error) { +// A unique identifier for this GitRepository. +func (r *GitRepository) ID(ctx context.Context) (GitRepositoryID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response GeneratedCodeID + var response GitRepositoryID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *GeneratedCode) XXX_GraphQLType() string { - return "GeneratedCode" +func (r *GitRepository) XXX_GraphQLType() string { + return "GitRepository" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *GeneratedCode) XXX_GraphQLIDType() string { - return "GeneratedCodeID" +func (r *GitRepository) XXX_GraphQLIDType() string { + return "GitRepositoryID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *GeneratedCode) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *GitRepository) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -3184,36 +5739,67 @@ func (r *GeneratedCode) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *GeneratedCode) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *GitRepository) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *GeneratedCode) UnmarshalJSON(bs []byte) error { +func (r *GitRepository) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadGeneratedCodeFromID(GeneratedCodeID(id)) + *r = *dag.LoadGitRepositoryFromID(GitRepositoryID(id)) return nil } -// List of paths to mark generated in version control (i.e. .gitattributes). -func (r *GeneratedCode) VcsGeneratedPaths(ctx context.Context) ([]string, error) { - q := r.query.Select("vcsGeneratedPaths") +// Returns details for the latest semver tag. +func (r *GitRepository) LatestVersion() *GitRef { + q := r.query.Select("latestVersion") - var response []string + return &GitRef{ + query: q, + } +} - q = q.Bind(&response) - return response, q.Execute(ctx) +// Returns details of a ref. +func (r *GitRepository) Ref(name string) *GitRef { + q := r.query.Select("ref") + q = q.Arg("name", name) + + return &GitRef{ + query: q, + } } -// List of paths to ignore in version control (i.e. .gitignore). -func (r *GeneratedCode) VcsIgnoredPaths(ctx context.Context) ([]string, error) { - q := r.query.Select("vcsIgnoredPaths") +// Returns details of a tag. +func (r *GitRepository) Tag(name string) *GitRef { + q := r.query.Select("tag") + q = q.Arg("name", name) + + return &GitRef{ + query: q, + } +} + +// GitRepositoryTagsOpts contains options for GitRepository.Tags +type GitRepositoryTagsOpts struct { + // Glob patterns (e.g., "refs/tags/v*"). + Patterns []string +} + +// tags that match any of the given glob patterns. +func (r *GitRepository) Tags(ctx context.Context, opts ...GitRepositoryTagsOpts) ([]string, error) { + q := r.query.Select("tags") + for i := len(opts) - 1; i >= 0; i-- { + // `patterns` optional argument + if !querybuilder.IsZeroValue(opts[i].Patterns) { + q = q.Arg("patterns", opts[i].Patterns) + } + } var response []string @@ -3221,117 +5807,107 @@ func (r *GeneratedCode) VcsIgnoredPaths(ctx context.Context) ([]string, error) { return response, q.Execute(ctx) } -// Set the list of paths to mark generated in version control. -func (r *GeneratedCode) WithVCSGeneratedPaths(paths []string) *GeneratedCode { - q := r.query.Select("withVCSGeneratedPaths") - q = q.Arg("paths", paths) +// Header to authenticate the remote with. +// +// Deprecated: Use "httpAuthHeader" in the constructor instead. +func (r *GitRepository) WithAuthHeader(header *Secret) *GitRepository { + assertNotNil("header", header) + q := r.query.Select("withAuthHeader") + q = q.Arg("header", header) - return &GeneratedCode{ + return &GitRepository{ query: q, } } -// Set the list of paths to ignore in version control. -func (r *GeneratedCode) WithVCSIgnoredPaths(paths []string) *GeneratedCode { - q := r.query.Select("withVCSIgnoredPaths") - q = q.Arg("paths", paths) +// Token to authenticate the remote with. +// +// Deprecated: Use "httpAuthToken" in the constructor instead. +func (r *GitRepository) WithAuthToken(token *Secret) *GitRepository { + assertNotNil("token", token) + q := r.query.Select("withAuthToken") + q = q.Arg("token", token) - return &GeneratedCode{ + return &GitRepository{ query: q, } } -// Module source originating from a git repo. -type GitModuleSource struct { +// A graphql input type, which is essentially just a group of named args. +// This is currently only used to represent pre-existing usage of graphql input types +// in the core API. It is not used by user modules and shouldn't ever be as user +// module accept input objects via their id rather than graphql input types. +type InputTypeDef struct { query *querybuilder.Selection - cloneURL *string - commit *string - htmlURL *string - id *GitModuleSourceID - rootSubpath *string - version *string + id *InputTypeDefID + name *string } -func (r *GitModuleSource) WithGraphQLQuery(q *querybuilder.Selection) *GitModuleSource { - return &GitModuleSource{ +func (r *InputTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *InputTypeDef { + return &InputTypeDef{ query: q, } } -// The URL from which the source's git repo can be cloned. -func (r *GitModuleSource) CloneURL(ctx context.Context) (string, error) { - if r.cloneURL != nil { - return *r.cloneURL, nil - } - q := r.query.Select("cloneURL") - - var response string +// Static fields defined on this input object, if any. +func (r *InputTypeDef) Fields(ctx context.Context) ([]FieldTypeDef, error) { + q := r.query.Select("fields") - q = q.Bind(&response) - return response, q.Execute(ctx) -} + q = q.Select("id") -// The resolved commit of the git repo this source points to. -func (r *GitModuleSource) Commit(ctx context.Context) (string, error) { - if r.commit != nil { - return *r.commit, nil + type fields struct { + Id FieldTypeDefID } - q := r.query.Select("commit") - - var response string - q = q.Bind(&response) - return response, q.Execute(ctx) -} + convert := func(fields []fields) []FieldTypeDef { + out := []FieldTypeDef{} -// The directory containing everything needed to load load and use the module. -func (r *GitModuleSource) ContextDirectory() *Directory { - q := r.query.Select("contextDirectory") + for i := range fields { + val := FieldTypeDef{id: &fields[i].Id} + val.query = q.Root().Select("loadFieldTypeDefFromID").Arg("id", fields[i].Id) + out = append(out, val) + } - return &Directory{ - query: q, + return out } -} + var response []fields -// The URL to the source's git repo in a web browser -func (r *GitModuleSource) HTMLURL(ctx context.Context) (string, error) { - if r.htmlURL != nil { - return *r.htmlURL, nil - } - q := r.query.Select("htmlURL") + q = q.Bind(&response) - var response string + err := q.Execute(ctx) + if err != nil { + return nil, err + } - q = q.Bind(&response) - return response, q.Execute(ctx) + return convert(response), nil } -// A unique identifier for this GitModuleSource. -func (r *GitModuleSource) ID(ctx context.Context) (GitModuleSourceID, error) { +// A unique identifier for this InputTypeDef. +func (r *InputTypeDef) ID(ctx context.Context) (InputTypeDefID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response GitModuleSourceID + var response InputTypeDefID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *GitModuleSource) XXX_GraphQLType() string { - return "GitModuleSource" +func (r *InputTypeDef) XXX_GraphQLType() string { + return "InputTypeDef" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *GitModuleSource) XXX_GraphQLIDType() string { - return "GitModuleSourceID" +func (r *InputTypeDef) XXX_GraphQLIDType() string { + return "InputTypeDefID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *GitModuleSource) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *InputTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -3339,29 +5915,29 @@ func (r *GitModuleSource) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *GitModuleSource) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *InputTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *GitModuleSource) UnmarshalJSON(bs []byte) error { +func (r *InputTypeDef) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadGitModuleSourceFromID(GitModuleSourceID(id)) + *r = *dag.LoadInputTypeDefFromID(InputTypeDefID(id)) return nil } -// The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory). -func (r *GitModuleSource) RootSubpath(ctx context.Context) (string, error) { - if r.rootSubpath != nil { - return *r.rootSubpath, nil +// The name of the input object. +func (r *InputTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil } - q := r.query.Select("rootSubpath") + q := r.query.Select("name") var response string @@ -3369,12 +5945,28 @@ func (r *GitModuleSource) RootSubpath(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The specified version of the git repo this source points to. -func (r *GitModuleSource) Version(ctx context.Context) (string, error) { - if r.version != nil { - return *r.version, nil +// A definition of a custom interface defined in a Module. +type InterfaceTypeDef struct { + query *querybuilder.Selection + + description *string + id *InterfaceTypeDefID + name *string + sourceModuleName *string +} + +func (r *InterfaceTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *InterfaceTypeDef { + return &InterfaceTypeDef{ + query: q, } - q := r.query.Select("version") +} + +// The doc string for the interface, if any. +func (r *InterfaceTypeDef) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil + } + q := r.query.Select("description") var response string @@ -3382,58 +5974,64 @@ func (r *GitModuleSource) Version(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// A git ref (tag, branch, or commit). -type GitRef struct { - query *querybuilder.Selection +// Functions defined on this interface, if any. +func (r *InterfaceTypeDef) Functions(ctx context.Context) ([]Function, error) { + q := r.query.Select("functions") - commit *string - id *GitRefID -} + q = q.Select("id") + + type functions struct { + Id FunctionID + } + + convert := func(fields []functions) []Function { + out := []Function{} + + for i := range fields { + val := Function{id: &fields[i].Id} + val.query = q.Root().Select("loadFunctionFromID").Arg("id", fields[i].Id) + out = append(out, val) + } -func (r *GitRef) WithGraphQLQuery(q *querybuilder.Selection) *GitRef { - return &GitRef{ - query: q, + return out } -} + var response []functions -// The resolved commit id at this ref. -func (r *GitRef) Commit(ctx context.Context) (string, error) { - if r.commit != nil { - return *r.commit, nil - } - q := r.query.Select("commit") + q = q.Bind(&response) - var response string + err := q.Execute(ctx) + if err != nil { + return nil, err + } - q = q.Bind(&response) - return response, q.Execute(ctx) + return convert(response), nil } -// A unique identifier for this GitRef. -func (r *GitRef) ID(ctx context.Context) (GitRefID, error) { +// A unique identifier for this InterfaceTypeDef. +func (r *InterfaceTypeDef) ID(ctx context.Context) (InterfaceTypeDefID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response GitRefID + var response InterfaceTypeDefID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *GitRef) XXX_GraphQLType() string { - return "GitRef" +func (r *InterfaceTypeDef) XXX_GraphQLType() string { + return "InterfaceTypeDef" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *GitRef) XXX_GraphQLIDType() string { - return "GitRefID" +func (r *InterfaceTypeDef) XXX_GraphQLIDType() string { + return "InterfaceTypeDefID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *GitRef) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *InterfaceTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -3441,108 +6039,161 @@ func (r *GitRef) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *GitRef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *InterfaceTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *GitRef) UnmarshalJSON(bs []byte) error { +func (r *InterfaceTypeDef) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadGitRefFromID(GitRefID(id)) + *r = *dag.LoadInterfaceTypeDefFromID(InterfaceTypeDefID(id)) return nil } -// GitRefTreeOpts contains options for GitRef.Tree -type GitRefTreeOpts struct { - // DEPRECATED: This option should be passed to `git` instead. - SSHKnownHosts string - // DEPRECATED: This option should be passed to `git` instead. - SSHAuthSocket *Socket +// The name of the interface. +func (r *InterfaceTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// The filesystem tree at this ref. -func (r *GitRef) Tree(opts ...GitRefTreeOpts) *Directory { - q := r.query.Select("tree") - for i := len(opts) - 1; i >= 0; i-- { - // `sshKnownHosts` optional argument - if !querybuilder.IsZeroValue(opts[i].SSHKnownHosts) { - q = q.Arg("sshKnownHosts", opts[i].SSHKnownHosts) - } - // `sshAuthSocket` optional argument - if !querybuilder.IsZeroValue(opts[i].SSHAuthSocket) { - q = q.Arg("sshAuthSocket", opts[i].SSHAuthSocket) - } - } +// The location of this interface declaration. +func (r *InterfaceTypeDef) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") - return &Directory{ + return &SourceMap{ query: q, } } -// A git repository. -type GitRepository struct { +// If this InterfaceTypeDef is associated with a Module, the name of the module. Unset otherwise. +func (r *InterfaceTypeDef) SourceModuleName(ctx context.Context) (string, error) { + if r.sourceModuleName != nil { + return *r.sourceModuleName, nil + } + q := r.query.Select("sourceModuleName") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +type LLM struct { query *querybuilder.Selection - id *GitRepositoryID + historyJSON *JSON + id *LLMID + lastReply *string + model *string + provider *string + sync *LLMID + tools *string } +type WithLLMFunc func(r *LLM) *LLM -func (r *GitRepository) WithGraphQLQuery(q *querybuilder.Selection) *GitRepository { - return &GitRepository{ +// With calls the provided function with current LLM. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *LLM) With(f WithLLMFunc) *LLM { + return f(r) +} + +func (r *LLM) WithGraphQLQuery(q *querybuilder.Selection) *LLM { + return &LLM{ query: q, } } -// Returns details of a branch. -func (r *GitRepository) Branch(name string) *GitRef { - q := r.query.Select("branch") +// create a branch in the LLM's history +func (r *LLM) Attempt(number int) *LLM { + q := r.query.Select("attempt") + q = q.Arg("number", number) + + return &LLM{ + query: q, + } +} + +// returns the type of the current state +func (r *LLM) BindResult(name string) *Binding { + q := r.query.Select("bindResult") q = q.Arg("name", name) - return &GitRef{ + return &Binding{ query: q, } } -// Returns details of a commit. -func (r *GitRepository) Commit(id string) *GitRef { - q := r.query.Select("commit") - q = q.Arg("id", id) +// return the LLM's current environment +func (r *LLM) Env() *Env { + q := r.query.Select("env") - return &GitRef{ + return &Env{ query: q, } } -// A unique identifier for this GitRepository. -func (r *GitRepository) ID(ctx context.Context) (GitRepositoryID, error) { +// return the llm message history +func (r *LLM) History(ctx context.Context) ([]string, error) { + q := r.query.Select("history") + + var response []string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// return the raw llm message history as json +func (r *LLM) HistoryJSON(ctx context.Context) (JSON, error) { + if r.historyJSON != nil { + return *r.historyJSON, nil + } + q := r.query.Select("historyJSON") + + var response JSON + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this LLM. +func (r *LLM) ID(ctx context.Context) (LLMID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response GitRepositoryID + var response LLMID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *GitRepository) XXX_GraphQLType() string { - return "GitRepository" +func (r *LLM) XXX_GraphQLType() string { + return "LLM" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *GitRepository) XXX_GraphQLIDType() string { - return "GitRepositoryID" +func (r *LLM) XXX_GraphQLIDType() string { + return "LLMID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *GitRepository) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *LLM) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -3550,242 +6201,233 @@ func (r *GitRepository) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *GitRepository) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *LLM) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *GitRepository) UnmarshalJSON(bs []byte) error { +func (r *LLM) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadGitRepositoryFromID(GitRepositoryID(id)) + *r = *dag.LoadLLMFromID(LLMID(id)) return nil } -// Returns details of a ref. -func (r *GitRepository) Ref(name string) *GitRef { - q := r.query.Select("ref") - q = q.Arg("name", name) - - return &GitRef{ - query: q, +// return the last llm reply from the history +func (r *LLM) LastReply(ctx context.Context) (string, error) { + if r.lastReply != nil { + return *r.lastReply, nil } -} + q := r.query.Select("lastReply") -// Returns details of a tag. -func (r *GitRepository) Tag(name string) *GitRef { - q := r.query.Select("tag") - q = q.Arg("name", name) + var response string - return &GitRef{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// A graphql input type, which is essentially just a group of named args. -// This is currently only used to represent pre-existing usage of graphql input types -// in the core API. It is not used by user modules and shouldn't ever be as user -// module accept input objects via their id rather than graphql input types. -type InputTypeDef struct { - query *querybuilder.Selection - - id *InputTypeDefID - name *string -} +// synchronize LLM state +func (r *LLM) Loop() *LLM { + q := r.query.Select("loop") -func (r *InputTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *InputTypeDef { - return &InputTypeDef{ + return &LLM{ query: q, } } -// Static fields defined on this input object, if any. -func (r *InputTypeDef) Fields(ctx context.Context) ([]FieldTypeDef, error) { - q := r.query.Select("fields") - - q = q.Select("id") - - type fields struct { - Id FieldTypeDefID +// return the model used by the llm +func (r *LLM) Model(ctx context.Context) (string, error) { + if r.model != nil { + return *r.model, nil } + q := r.query.Select("model") - convert := func(fields []fields) []FieldTypeDef { - out := []FieldTypeDef{} + var response string - for i := range fields { - val := FieldTypeDef{id: &fields[i].Id} - val.query = q.Root().Select("loadFieldTypeDefFromID").Arg("id", fields[i].Id) - out = append(out, val) - } + q = q.Bind(&response) + return response, q.Execute(ctx) +} - return out +// return the provider used by the llm +func (r *LLM) Provider(ctx context.Context) (string, error) { + if r.provider != nil { + return *r.provider, nil } - var response []fields + q := r.query.Select("provider") + + var response string q = q.Bind(&response) + return response, q.Execute(ctx) +} - err := q.Execute(ctx) - if err != nil { +// synchronize LLM state +func (r *LLM) Sync(ctx context.Context) (*LLM, error) { + q := r.query.Select("sync") + + var id LLMID + if err := q.Bind(&id).Execute(ctx); err != nil { return nil, err } + return &LLM{ + query: q.Root().Select("loadLLMFromID").Arg("id", id), + }, nil +} - return convert(response), nil +// returns the token usage of the current state +func (r *LLM) TokenUsage() *LLMTokenUsage { + q := r.query.Select("tokenUsage") + + return &LLMTokenUsage{ + query: q, + } } -// A unique identifier for this InputTypeDef. -func (r *InputTypeDef) ID(ctx context.Context) (InputTypeDefID, error) { - if r.id != nil { - return *r.id, nil +// print documentation for available tools +func (r *LLM) Tools(ctx context.Context) (string, error) { + if r.tools != nil { + return *r.tools, nil } - q := r.query.Select("id") + q := r.query.Select("tools") - var response InputTypeDefID + var response string q = q.Bind(&response) return response, q.Execute(ctx) } -// XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *InputTypeDef) XXX_GraphQLType() string { - return "InputTypeDef" -} +// allow the LLM to interact with an environment via MCP +func (r *LLM) WithEnv(env *Env) *LLM { + assertNotNil("env", env) + q := r.query.Select("withEnv") + q = q.Arg("env", env) -// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *InputTypeDef) XXX_GraphQLIDType() string { - return "InputTypeDefID" + return &LLM{ + query: q, + } } -// XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *InputTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { - id, err := r.ID(ctx) - if err != nil { - return "", err +// swap out the llm model +func (r *LLM) WithModel(model string) *LLM { + q := r.query.Select("withModel") + q = q.Arg("model", model) + + return &LLM{ + query: q, } - return string(id), nil } -func (r *InputTypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) - if err != nil { - return nil, err +// append a prompt to the llm context +func (r *LLM) WithPrompt(prompt string) *LLM { + q := r.query.Select("withPrompt") + q = q.Arg("prompt", prompt) + + return &LLM{ + query: q, } - return json.Marshal(id) } -func (r *InputTypeDef) UnmarshalJSON(bs []byte) error { - var id string - err := json.Unmarshal(bs, &id) - if err != nil { - return err + +// append the contents of a file to the llm context +func (r *LLM) WithPromptFile(file *File) *LLM { + assertNotNil("file", file) + q := r.query.Select("withPromptFile") + q = q.Arg("file", file) + + return &LLM{ + query: q, } - *r = *dag.LoadInputTypeDefFromID(InputTypeDefID(id)) - return nil } -// The name of the input object. -func (r *InputTypeDef) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil +// Add a system prompt to the LLM's environment +func (r *LLM) WithSystemPrompt(prompt string) *LLM { + q := r.query.Select("withSystemPrompt") + q = q.Arg("prompt", prompt) + + return &LLM{ + query: q, } - q := r.query.Select("name") +} - var response string +// Disable the default system prompt +func (r *LLM) WithoutDefaultSystemPrompt() *LLM { + q := r.query.Select("withoutDefaultSystemPrompt") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &LLM{ + query: q, + } } -// A definition of a custom interface defined in a Module. -type InterfaceTypeDef struct { +type LLMTokenUsage struct { query *querybuilder.Selection - description *string - id *InterfaceTypeDefID - name *string - sourceModuleName *string + cachedTokenReads *int + cachedTokenWrites *int + id *LLMTokenUsageID + inputTokens *int + outputTokens *int + totalTokens *int } -func (r *InterfaceTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *InterfaceTypeDef { - return &InterfaceTypeDef{ +func (r *LLMTokenUsage) WithGraphQLQuery(q *querybuilder.Selection) *LLMTokenUsage { + return &LLMTokenUsage{ query: q, } } -// The doc string for the interface, if any. -func (r *InterfaceTypeDef) Description(ctx context.Context) (string, error) { - if r.description != nil { - return *r.description, nil +func (r *LLMTokenUsage) CachedTokenReads(ctx context.Context) (int, error) { + if r.cachedTokenReads != nil { + return *r.cachedTokenReads, nil } - q := r.query.Select("description") + q := r.query.Select("cachedTokenReads") - var response string + var response int q = q.Bind(&response) return response, q.Execute(ctx) } -// Functions defined on this interface, if any. -func (r *InterfaceTypeDef) Functions(ctx context.Context) ([]Function, error) { - q := r.query.Select("functions") - - q = q.Select("id") - - type functions struct { - Id FunctionID +func (r *LLMTokenUsage) CachedTokenWrites(ctx context.Context) (int, error) { + if r.cachedTokenWrites != nil { + return *r.cachedTokenWrites, nil } + q := r.query.Select("cachedTokenWrites") - convert := func(fields []functions) []Function { - out := []Function{} - - for i := range fields { - val := Function{id: &fields[i].Id} - val.query = q.Root().Select("loadFunctionFromID").Arg("id", fields[i].Id) - out = append(out, val) - } - - return out - } - var response []functions + var response int q = q.Bind(&response) - - err := q.Execute(ctx) - if err != nil { - return nil, err - } - - return convert(response), nil + return response, q.Execute(ctx) } -// A unique identifier for this InterfaceTypeDef. -func (r *InterfaceTypeDef) ID(ctx context.Context) (InterfaceTypeDefID, error) { +// A unique identifier for this LLMTokenUsage. +func (r *LLMTokenUsage) ID(ctx context.Context) (LLMTokenUsageID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response InterfaceTypeDefID + var response LLMTokenUsageID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *InterfaceTypeDef) XXX_GraphQLType() string { - return "InterfaceTypeDef" +func (r *LLMTokenUsage) XXX_GraphQLType() string { + return "LLMTokenUsage" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *InterfaceTypeDef) XXX_GraphQLIDType() string { - return "InterfaceTypeDefID" +func (r *LLMTokenUsage) XXX_GraphQLIDType() string { + return "LLMTokenUsageID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *InterfaceTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *LLMTokenUsage) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -3793,44 +6435,54 @@ func (r *InterfaceTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *InterfaceTypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *LLMTokenUsage) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *InterfaceTypeDef) UnmarshalJSON(bs []byte) error { +func (r *LLMTokenUsage) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadInterfaceTypeDefFromID(InterfaceTypeDefID(id)) + *r = *dag.LoadLLMTokenUsageFromID(LLMTokenUsageID(id)) return nil } -// The name of the interface. -func (r *InterfaceTypeDef) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil +func (r *LLMTokenUsage) InputTokens(ctx context.Context) (int, error) { + if r.inputTokens != nil { + return *r.inputTokens, nil } - q := r.query.Select("name") + q := r.query.Select("inputTokens") - var response string + var response int q = q.Bind(&response) return response, q.Execute(ctx) } -// If this InterfaceTypeDef is associated with a Module, the name of the module. Unset otherwise. -func (r *InterfaceTypeDef) SourceModuleName(ctx context.Context) (string, error) { - if r.sourceModuleName != nil { - return *r.sourceModuleName, nil +func (r *LLMTokenUsage) OutputTokens(ctx context.Context) (int, error) { + if r.outputTokens != nil { + return *r.outputTokens, nil } - q := r.query.Select("sourceModuleName") + q := r.query.Select("outputTokens") - var response string + var response int + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +func (r *LLMTokenUsage) TotalTokens(ctx context.Context) (int, error) { + if r.totalTokens != nil { + return *r.totalTokens, nil + } + q := r.query.Select("totalTokens") + + var response int q = q.Bind(&response) return response, q.Execute(ctx) @@ -3884,7 +6536,7 @@ func (r *Label) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Label) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -3981,7 +6633,7 @@ func (r *ListTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *ListTypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -3997,91 +6649,6 @@ func (r *ListTypeDef) UnmarshalJSON(bs []byte) error { return nil } -// Module source that that originates from a path locally relative to an arbitrary directory. -type LocalModuleSource struct { - query *querybuilder.Selection - - id *LocalModuleSourceID - rootSubpath *string -} - -func (r *LocalModuleSource) WithGraphQLQuery(q *querybuilder.Selection) *LocalModuleSource { - return &LocalModuleSource{ - query: q, - } -} - -// The directory containing everything needed to load load and use the module. -func (r *LocalModuleSource) ContextDirectory() *Directory { - q := r.query.Select("contextDirectory") - - return &Directory{ - query: q, - } -} - -// A unique identifier for this LocalModuleSource. -func (r *LocalModuleSource) ID(ctx context.Context) (LocalModuleSourceID, error) { - if r.id != nil { - return *r.id, nil - } - q := r.query.Select("id") - - var response LocalModuleSourceID - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *LocalModuleSource) XXX_GraphQLType() string { - return "LocalModuleSource" -} - -// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *LocalModuleSource) XXX_GraphQLIDType() string { - return "LocalModuleSourceID" -} - -// XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *LocalModuleSource) XXX_GraphQLID(ctx context.Context) (string, error) { - id, err := r.ID(ctx) - if err != nil { - return "", err - } - return string(id), nil -} - -func (r *LocalModuleSource) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) - if err != nil { - return nil, err - } - return json.Marshal(id) -} -func (r *LocalModuleSource) UnmarshalJSON(bs []byte) error { - var id string - err := json.Unmarshal(bs, &id) - if err != nil { - return err - } - *r = *dag.LoadLocalModuleSourceFromID(LocalModuleSourceID(id)) - return nil -} - -// The path to the root of the module source under the context directory. This directory contains its configuration file. It also contains its source code (possibly as a subdirectory). -func (r *LocalModuleSource) RootSubpath(ctx context.Context) (string, error) { - if r.rootSubpath != nil { - return *r.rootSubpath, nil - } - q := r.query.Select("rootSubpath") - - var response string - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - // A Dagger module. type Module struct { query *querybuilder.Selection @@ -4089,8 +6656,8 @@ type Module struct { description *string id *ModuleID name *string - sdk *string serve *Void + sync *ModuleID } type WithModuleFunc func(r *Module) *Module @@ -4107,7 +6674,7 @@ func (r *Module) WithGraphQLQuery(q *querybuilder.Selection) *Module { } } -// Modules used by this module. +// The dependencies of the module. func (r *Module) Dependencies(ctx context.Context) ([]Module, error) { q := r.query.Select("dependencies") @@ -4140,28 +6707,41 @@ func (r *Module) Dependencies(ctx context.Context) ([]Module, error) { return convert(response), nil } -// The dependencies as configured by the module. -func (r *Module) DependencyConfig(ctx context.Context) ([]ModuleDependency, error) { - q := r.query.Select("dependencyConfig") +// The doc string of the module, if any +func (r *Module) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil + } + q := r.query.Select("description") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Enumerations served by this module. +func (r *Module) Enums(ctx context.Context) ([]TypeDef, error) { + q := r.query.Select("enums") q = q.Select("id") - type dependencyConfig struct { - Id ModuleDependencyID + type enums struct { + Id TypeDefID } - convert := func(fields []dependencyConfig) []ModuleDependency { - out := []ModuleDependency{} + convert := func(fields []enums) []TypeDef { + out := []TypeDef{} for i := range fields { - val := ModuleDependency{id: &fields[i].Id} - val.query = q.Root().Select("loadModuleDependencyFromID").Arg("id", fields[i].Id) + val := TypeDef{id: &fields[i].Id} + val.query = q.Root().Select("loadTypeDefFromID").Arg("id", fields[i].Id) out = append(out, val) } return out } - var response []dependencyConfig + var response []enums q = q.Bind(&response) @@ -4173,29 +6753,7 @@ func (r *Module) DependencyConfig(ctx context.Context) ([]ModuleDependency, erro return convert(response), nil } -// The doc string of the module, if any -func (r *Module) Description(ctx context.Context) (string, error) { - if r.description != nil { - return *r.description, nil - } - q := r.query.Select("description") - - var response string - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - // The generated files and directories made on top of the module source's context directory. -func (r *Module) GeneratedContextDiff() *Directory { - q := r.query.Select("generatedContextDiff") - - return &Directory{ - query: q, - } -} - -// The module source's context plus any configuration and source files created by codegen. func (r *Module) GeneratedContextDirectory() *Directory { q := r.query.Select("generatedContextDirectory") @@ -4237,7 +6795,7 @@ func (r *Module) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Module) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -4253,15 +6811,6 @@ func (r *Module) UnmarshalJSON(bs []byte) error { return nil } -// Retrieves the module with the objects loaded via its SDK. -func (r *Module) Initialize() *Module { - q := r.query.Select("initialize") - - return &Module{ - query: q, - } -} - // Interfaces served by this module. func (r *Module) Interfaces(ctx context.Context) ([]TypeDef, error) { q := r.query.Select("interfaces") @@ -4350,32 +6899,37 @@ func (r *Module) Runtime() *Container { } } -// The SDK used by this module. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation. -func (r *Module) SDK(ctx context.Context) (string, error) { - if r.sdk != nil { - return *r.sdk, nil - } +// The SDK config used by this module. +func (r *Module) SDK() *SDKConfig { q := r.query.Select("sdk") - var response string + return &SDKConfig{ + query: q, + } +} - q = q.Bind(&response) - return response, q.Execute(ctx) +// ModuleServeOpts contains options for Module.Serve +type ModuleServeOpts struct { + // Expose the dependencies of this module to the client + IncludeDependencies bool } // Serve a module's API in the current session. // // Note: this can only be called once per session. In the future, it could return a stream or service to remove the side effect. -func (r *Module) Serve(ctx context.Context) (Void, error) { +func (r *Module) Serve(ctx context.Context, opts ...ModuleServeOpts) error { if r.serve != nil { - return *r.serve, nil + return nil } q := r.query.Select("serve") + for i := len(opts) - 1; i >= 0; i-- { + // `includeDependencies` optional argument + if !querybuilder.IsZeroValue(opts[i].IncludeDependencies) { + q = q.Arg("includeDependencies", opts[i].IncludeDependencies) + } + } - var response Void - - q = q.Bind(&response) - return response, q.Execute(ctx) + return q.Execute(ctx) } // The source for the module. @@ -4387,6 +6941,19 @@ func (r *Module) Source() *ModuleSource { } } +// Forces evaluation of the module, including any loading into the engine and associated validation. +func (r *Module) Sync(ctx context.Context) (*Module, error) { + q := r.query.Select("sync") + + var id ModuleID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Module{ + query: q.Root().Select("loadModuleFromID").Arg("id", id), + }, nil +} + // Retrieves the module with the given description func (r *Module) WithDescription(description string) *Module { q := r.query.Select("withDescription") @@ -4397,6 +6964,17 @@ func (r *Module) WithDescription(description string) *Module { } } +// This module plus the given Enum type and associated values +func (r *Module) WithEnum(enum *TypeDef) *Module { + assertNotNil("enum", enum) + q := r.query.Select("withEnum") + q = q.Arg("enum", enum) + + return &Module{ + query: q, + } +} + // This module plus the given Interface type and associated functions func (r *Module) WithInterface(iface *TypeDef) *Module { assertNotNil("iface", iface) @@ -4419,56 +6997,72 @@ func (r *Module) WithObject(object *TypeDef) *Module { } } -// Retrieves the module with basic configuration loaded if present. -func (r *Module) WithSource(source *ModuleSource) *Module { - assertNotNil("source", source) - q := r.query.Select("withSource") - q = q.Arg("source", source) +// The client generated for the module. +type ModuleConfigClient struct { + query *querybuilder.Selection - return &Module{ + directory *string + generator *string + id *ModuleConfigClientID +} + +func (r *ModuleConfigClient) WithGraphQLQuery(q *querybuilder.Selection) *ModuleConfigClient { + return &ModuleConfigClient{ query: q, } } -// The configuration of dependency of a module. -type ModuleDependency struct { - query *querybuilder.Selection +// The directory the client is generated in. +func (r *ModuleConfigClient) Directory(ctx context.Context) (string, error) { + if r.directory != nil { + return *r.directory, nil + } + q := r.query.Select("directory") - id *ModuleDependencyID - name *string + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -func (r *ModuleDependency) WithGraphQLQuery(q *querybuilder.Selection) *ModuleDependency { - return &ModuleDependency{ - query: q, +// The generator to use +func (r *ModuleConfigClient) Generator(ctx context.Context) (string, error) { + if r.generator != nil { + return *r.generator, nil } + q := r.query.Select("generator") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// A unique identifier for this ModuleDependency. -func (r *ModuleDependency) ID(ctx context.Context) (ModuleDependencyID, error) { +// A unique identifier for this ModuleConfigClient. +func (r *ModuleConfigClient) ID(ctx context.Context) (ModuleConfigClientID, error) { if r.id != nil { return *r.id, nil } q := r.query.Select("id") - var response ModuleDependencyID + var response ModuleConfigClientID q = q.Bind(&response) return response, q.Execute(ctx) } // XXX_GraphQLType is an internal function. It returns the native GraphQL type name -func (r *ModuleDependency) XXX_GraphQLType() string { - return "ModuleDependency" +func (r *ModuleConfigClient) XXX_GraphQLType() string { + return "ModuleConfigClient" } // XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object -func (r *ModuleDependency) XXX_GraphQLIDType() string { - return "ModuleDependencyID" +func (r *ModuleConfigClient) XXX_GraphQLIDType() string { + return "ModuleConfigClientID" } // XXX_GraphQLID is an internal function. It returns the underlying type ID -func (r *ModuleDependency) XXX_GraphQLID(ctx context.Context) (string, error) { +func (r *ModuleConfigClient) XXX_GraphQLID(ctx context.Context) (string, error) { id, err := r.ID(ctx) if err != nil { return "", err @@ -4476,58 +7070,47 @@ func (r *ModuleDependency) XXX_GraphQLID(ctx context.Context) (string, error) { return string(id), nil } -func (r *ModuleDependency) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) +func (r *ModuleConfigClient) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) if err != nil { return nil, err } return json.Marshal(id) } -func (r *ModuleDependency) UnmarshalJSON(bs []byte) error { +func (r *ModuleConfigClient) UnmarshalJSON(bs []byte) error { var id string err := json.Unmarshal(bs, &id) if err != nil { return err } - *r = *dag.LoadModuleDependencyFromID(ModuleDependencyID(id)) + *r = *dag.LoadModuleConfigClientFromID(ModuleConfigClientID(id)) return nil } -// The name of the dependency module. -func (r *ModuleDependency) Name(ctx context.Context) (string, error) { - if r.name != nil { - return *r.name, nil - } - q := r.query.Select("name") - - var response string - - q = q.Bind(&response) - return response, q.Execute(ctx) -} - -// The source for the dependency module. -func (r *ModuleDependency) Source() *ModuleSource { - q := r.query.Select("source") - - return &ModuleSource{ - query: q, - } -} - // The source needed to load and run a module, along with any metadata about the source such as versions/urls/etc. type ModuleSource struct { query *querybuilder.Selection - asString *string - configExists *bool - id *ModuleSourceID - kind *ModuleSourceKind - moduleName *string - moduleOriginalName *string - resolveContextPathFromCaller *string - sourceRootSubpath *string - sourceSubpath *string + asString *string + cloneRef *string + commit *string + configExists *bool + digest *string + engineVersion *string + htmlRepoURL *string + htmlURL *string + id *ModuleSourceID + kind *ModuleSourceKind + localContextDirectoryPath *string + moduleName *string + moduleOriginalName *string + originalSubpath *string + pin *string + repoRootPath *string + sourceRootSubpath *string + sourceSubpath *string + sync *ModuleSourceID + version *string } type WithModuleSourceFunc func(r *ModuleSource) *ModuleSource @@ -4539,25 +7122,7 @@ func (r *ModuleSource) With(f WithModuleSourceFunc) *ModuleSource { } func (r *ModuleSource) WithGraphQLQuery(q *querybuilder.Selection) *ModuleSource { - return &ModuleSource{ - query: q, - } -} - -// If the source is a of kind git, the git source representation of it. -func (r *ModuleSource) AsGitSource() *GitModuleSource { - q := r.query.Select("asGitSource") - - return &GitModuleSource{ - query: q, - } -} - -// If the source is of kind local, the local source representation of it. -func (r *ModuleSource) AsLocalSource() *LocalModuleSource { - q := r.query.Select("asLocalSource") - - return &LocalModuleSource{ + return &ModuleSource{ query: q, } } @@ -4584,7 +7149,75 @@ func (r *ModuleSource) AsString(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// Returns whether the module source has a configuration file. +// The blueprint referenced by the module source. +func (r *ModuleSource) Blueprint() *ModuleSource { + q := r.query.Select("blueprint") + + return &ModuleSource{ + query: q, + } +} + +// The ref to clone the root of the git repo from. Only valid for git sources. +func (r *ModuleSource) CloneRef(ctx context.Context) (string, error) { + if r.cloneRef != nil { + return *r.cloneRef, nil + } + q := r.query.Select("cloneRef") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The resolved commit of the git repo this source points to. +func (r *ModuleSource) Commit(ctx context.Context) (string, error) { + if r.commit != nil { + return *r.commit, nil + } + q := r.query.Select("commit") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The clients generated for the module. +func (r *ModuleSource) ConfigClients(ctx context.Context) ([]ModuleConfigClient, error) { + q := r.query.Select("configClients") + + q = q.Select("id") + + type configClients struct { + Id ModuleConfigClientID + } + + convert := func(fields []configClients) []ModuleConfigClient { + out := []ModuleConfigClient{} + + for i := range fields { + val := ModuleConfigClient{id: &fields[i].Id} + val.query = q.Root().Select("loadModuleConfigClientFromID").Arg("id", fields[i].Id) + out = append(out, val) + } + + return out + } + var response []configClients + + q = q.Bind(&response) + + err := q.Execute(ctx) + if err != nil { + return nil, err + } + + return convert(response), nil +} + +// Whether an existing dagger.json for the module was found. func (r *ModuleSource) ConfigExists(ctx context.Context) (bool, error) { if r.configExists != nil { return *r.configExists, nil @@ -4597,7 +7230,7 @@ func (r *ModuleSource) ConfigExists(ctx context.Context) (bool, error) { return response, q.Execute(ctx) } -// The directory containing everything needed to load load and use the module. +// The full directory loaded for the module source, including the source code as a subdirectory. func (r *ModuleSource) ContextDirectory() *Directory { q := r.query.Select("contextDirectory") @@ -4606,22 +7239,22 @@ func (r *ModuleSource) ContextDirectory() *Directory { } } -// The dependencies of the module source. Includes dependencies from the configuration and any extras from withDependencies calls. -func (r *ModuleSource) Dependencies(ctx context.Context) ([]ModuleDependency, error) { +// The dependencies of the module source. +func (r *ModuleSource) Dependencies(ctx context.Context) ([]ModuleSource, error) { q := r.query.Select("dependencies") q = q.Select("id") type dependencies struct { - Id ModuleDependencyID + Id ModuleSourceID } - convert := func(fields []dependencies) []ModuleDependency { - out := []ModuleDependency{} + convert := func(fields []dependencies) []ModuleSource { + out := []ModuleSource{} for i := range fields { - val := ModuleDependency{id: &fields[i].Id} - val.query = q.Root().Select("loadModuleDependencyFromID").Arg("id", fields[i].Id) + val := ModuleSource{id: &fields[i].Id} + val.query = q.Root().Select("loadModuleSourceFromID").Arg("id", fields[i].Id) out = append(out, val) } @@ -4639,6 +7272,19 @@ func (r *ModuleSource) Dependencies(ctx context.Context) ([]ModuleDependency, er return convert(response), nil } +// A content-hash of the module source. Module sources with the same digest will output the same generated context and convert into the same module instance. +func (r *ModuleSource) Digest(ctx context.Context) (string, error) { + if r.digest != nil { + return *r.digest, nil + } + q := r.query.Select("digest") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + // The directory containing the module configuration and source code (source code may be in a subdir). func (r *ModuleSource) Directory(path string) *Directory { q := r.query.Select("directory") @@ -4649,6 +7295,54 @@ func (r *ModuleSource) Directory(path string) *Directory { } } +// The engine version of the module. +func (r *ModuleSource) EngineVersion(ctx context.Context) (string, error) { + if r.engineVersion != nil { + return *r.engineVersion, nil + } + q := r.query.Select("engineVersion") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The generated files and directories made on top of the module source's context directory. +func (r *ModuleSource) GeneratedContextDirectory() *Directory { + q := r.query.Select("generatedContextDirectory") + + return &Directory{ + query: q, + } +} + +// The URL to access the web view of the repository (e.g., GitHub, GitLab, Bitbucket). +func (r *ModuleSource) HTMLRepoURL(ctx context.Context) (string, error) { + if r.htmlRepoURL != nil { + return *r.htmlRepoURL, nil + } + q := r.query.Select("htmlRepoURL") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The URL to the source's git repo in a web browser. Only valid for git sources. +func (r *ModuleSource) HTMLURL(ctx context.Context) (string, error) { + if r.htmlURL != nil { + return *r.htmlURL, nil + } + q := r.query.Select("htmlURL") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + // A unique identifier for this ModuleSource. func (r *ModuleSource) ID(ctx context.Context) (ModuleSourceID, error) { if r.id != nil { @@ -4682,7 +7376,7 @@ func (r *ModuleSource) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *ModuleSource) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -4698,7 +7392,7 @@ func (r *ModuleSource) UnmarshalJSON(bs []byte) error { return nil } -// The kind of source (e.g. local, git, etc.) +// The kind of module source (currently local, git or dir). func (r *ModuleSource) Kind(ctx context.Context) (ModuleSourceKind, error) { if r.kind != nil { return *r.kind, nil @@ -4711,7 +7405,20 @@ func (r *ModuleSource) Kind(ctx context.Context) (ModuleSourceKind, error) { return response, q.Execute(ctx) } -// If set, the name of the module this source references, including any overrides at runtime by callers. +// The full absolute path to the context directory on the caller's host filesystem that this module source is loaded from. Only valid for local module sources. +func (r *ModuleSource) LocalContextDirectoryPath(ctx context.Context) (string, error) { + if r.localContextDirectoryPath != nil { + return *r.localContextDirectoryPath, nil + } + q := r.query.Select("localContextDirectoryPath") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The name of the module, including any setting via the withName API. func (r *ModuleSource) ModuleName(ctx context.Context) (string, error) { if r.moduleName != nil { return *r.moduleName, nil @@ -4724,7 +7431,7 @@ func (r *ModuleSource) ModuleName(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The original name of the module this source references, as defined in the module configuration. +// The original name of the module as read from the module's dagger.json (or set for the first time with the withName API). func (r *ModuleSource) ModuleOriginalName(ctx context.Context) (string, error) { if r.moduleOriginalName != nil { return *r.moduleOriginalName, nil @@ -4737,12 +7444,12 @@ func (r *ModuleSource) ModuleOriginalName(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The path to the module source's context directory on the caller's filesystem. Only valid for local sources. -func (r *ModuleSource) ResolveContextPathFromCaller(ctx context.Context) (string, error) { - if r.resolveContextPathFromCaller != nil { - return *r.resolveContextPathFromCaller, nil +// The original subpath used when instantiating this module source, relative to the context directory. +func (r *ModuleSource) OriginalSubpath(ctx context.Context) (string, error) { + if r.originalSubpath != nil { + return *r.originalSubpath, nil } - q := r.query.Select("resolveContextPathFromCaller") + q := r.query.Select("originalSubpath") var response string @@ -4750,27 +7457,42 @@ func (r *ModuleSource) ResolveContextPathFromCaller(ctx context.Context) (string return response, q.Execute(ctx) } -// Resolve the provided module source arg as a dependency relative to this module source. -func (r *ModuleSource) ResolveDependency(dep *ModuleSource) *ModuleSource { - assertNotNil("dep", dep) - q := r.query.Select("resolveDependency") - q = q.Arg("dep", dep) +// The pinned version of this module source. +func (r *ModuleSource) Pin(ctx context.Context) (string, error) { + if r.pin != nil { + return *r.pin, nil + } + q := r.query.Select("pin") - return &ModuleSource{ - query: q, + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The import path corresponding to the root of the git repo this source points to. Only valid for git sources. +func (r *ModuleSource) RepoRootPath(ctx context.Context) (string, error) { + if r.repoRootPath != nil { + return *r.repoRootPath, nil } + q := r.query.Select("repoRootPath") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Load the source from its path on the caller's filesystem, including only needed+configured files and directories. Only valid for local sources. -func (r *ModuleSource) ResolveFromCaller() *ModuleSource { - q := r.query.Select("resolveFromCaller") +// The SDK configuration of the module. +func (r *ModuleSource) SDK() *SDKConfig { + q := r.query.Select("sdk") - return &ModuleSource{ + return &SDKConfig{ query: q, } } -// The path relative to context of the root of the module source, which contains dagger.json. It also contains the module implementation source code, but that may or may not being a subdir of this root. +// The path, relative to the context directory, that contains the module's dagger.json. func (r *ModuleSource) SourceRootSubpath(ctx context.Context) (string, error) { if r.sourceRootSubpath != nil { return *r.sourceRootSubpath, nil @@ -4783,7 +7505,7 @@ func (r *ModuleSource) SourceRootSubpath(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// The path relative to context of the module implementation source code. +// The path to the directory containing the module's source code, relative to the context directory. func (r *ModuleSource) SourceSubpath(ctx context.Context) (string, error) { if r.sourceSubpath != nil { return *r.sourceSubpath, nil @@ -4796,11 +7518,48 @@ func (r *ModuleSource) SourceSubpath(ctx context.Context) (string, error) { return response, q.Execute(ctx) } -// Update the module source with a new context directory. Only valid for local sources. -func (r *ModuleSource) WithContextDirectory(dir *Directory) *ModuleSource { - assertNotNil("dir", dir) - q := r.query.Select("withContextDirectory") - q = q.Arg("dir", dir) +// Forces evaluation of the module source, including any loading into the engine and associated validation. +func (r *ModuleSource) Sync(ctx context.Context) (*ModuleSource, error) { + q := r.query.Select("sync") + + var id ModuleSourceID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &ModuleSource{ + query: q.Root().Select("loadModuleSourceFromID").Arg("id", id), + }, nil +} + +// The specified version of the git repo this source points to. +func (r *ModuleSource) Version(ctx context.Context) (string, error) { + if r.version != nil { + return *r.version, nil + } + q := r.query.Select("version") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// Set a blueprint for the module source. +func (r *ModuleSource) WithBlueprint(blueprint *ModuleSource) *ModuleSource { + assertNotNil("blueprint", blueprint) + q := r.query.Select("withBlueprint") + q = q.Arg("blueprint", blueprint) + + return &ModuleSource{ + query: q, + } +} + +// Update the module source with a new client to generate. +func (r *ModuleSource) WithClient(generator string, outputDir string) *ModuleSource { + q := r.query.Select("withClient") + q = q.Arg("generator", generator) + q = q.Arg("outputDir", outputDir) return &ModuleSource{ query: q, @@ -4808,7 +7567,7 @@ func (r *ModuleSource) WithContextDirectory(dir *Directory) *ModuleSource { } // Append the provided dependencies to the module source's dependency list. -func (r *ModuleSource) WithDependencies(dependencies []*ModuleDependency) *ModuleSource { +func (r *ModuleSource) WithDependencies(dependencies []*ModuleSource) *ModuleSource { q := r.query.Select("withDependencies") q = q.Arg("dependencies", dependencies) @@ -4817,6 +7576,26 @@ func (r *ModuleSource) WithDependencies(dependencies []*ModuleDependency) *Modul } } +// Upgrade the engine version of the module to the given value. +func (r *ModuleSource) WithEngineVersion(version string) *ModuleSource { + q := r.query.Select("withEngineVersion") + q = q.Arg("version", version) + + return &ModuleSource{ + query: q, + } +} + +// Update the module source with additional include patterns for files+directories from its context that are required for building it +func (r *ModuleSource) WithIncludes(patterns []string) *ModuleSource { + q := r.query.Select("withIncludes") + q = q.Arg("patterns", patterns) + + return &ModuleSource{ + query: q, + } +} + // Update the module source with a new name. func (r *ModuleSource) WithName(name string) *ModuleSource { q := r.query.Select("withName") @@ -4828,9 +7607,9 @@ func (r *ModuleSource) WithName(name string) *ModuleSource { } // Update the module source with a new SDK. -func (r *ModuleSource) WithSDK(sdk string) *ModuleSource { +func (r *ModuleSource) WithSDK(source string) *ModuleSource { q := r.query.Select("withSDK") - q = q.Arg("sdk", sdk) + q = q.Arg("source", source) return &ModuleSource{ query: q, @@ -4847,6 +7626,54 @@ func (r *ModuleSource) WithSourceSubpath(path string) *ModuleSource { } } +// Update the blueprint module to the latest version. +func (r *ModuleSource) WithUpdateBlueprint() *ModuleSource { + q := r.query.Select("withUpdateBlueprint") + + return &ModuleSource{ + query: q, + } +} + +// Update one or more module dependencies. +func (r *ModuleSource) WithUpdateDependencies(dependencies []string) *ModuleSource { + q := r.query.Select("withUpdateDependencies") + q = q.Arg("dependencies", dependencies) + + return &ModuleSource{ + query: q, + } +} + +// Remove the current blueprint from the module source. +func (r *ModuleSource) WithoutBlueprint() *ModuleSource { + q := r.query.Select("withoutBlueprint") + + return &ModuleSource{ + query: q, + } +} + +// Remove a client from the module source. +func (r *ModuleSource) WithoutClient(path string) *ModuleSource { + q := r.query.Select("withoutClient") + q = q.Arg("path", path) + + return &ModuleSource{ + query: q, + } +} + +// Remove the provided dependencies from the module source's dependency list. +func (r *ModuleSource) WithoutDependencies(dependencies []string) *ModuleSource { + q := r.query.Select("withoutDependencies") + q = q.Arg("dependencies", dependencies) + + return &ModuleSource{ + query: q, + } +} + // A definition of a custom object defined in a Module. type ObjectTypeDef struct { query *querybuilder.Selection @@ -4984,7 +7811,7 @@ func (r *ObjectTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *ObjectTypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -5013,6 +7840,15 @@ func (r *ObjectTypeDef) Name(ctx context.Context) (string, error) { return response, q.Execute(ctx) } +// The location of this object declaration. +func (r *ObjectTypeDef) SourceMap() *SourceMap { + q := r.query.Select("sourceMap") + + return &SourceMap{ + query: q, + } +} + // If this ObjectTypeDef is associated with a Module, the name of the module. Unset otherwise. func (r *ObjectTypeDef) SourceModuleName(ctx context.Context) (string, error) { if r.sourceModuleName != nil { @@ -5102,7 +7938,7 @@ func (r *Port) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Port) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -5144,15 +7980,6 @@ func (r *Port) Protocol(ctx context.Context) (NetworkProtocol, error) { return response, q.Execute(ctx) } -type WithClientFunc func(r *Client) *Client - -// With calls the provided function with current Client. -// -// This is useful for reusability and readability by not breaking the calling chain. -func (r *Client) With(f WithClientFunc) *Client { - return f(r) -} - func (r *Client) WithGraphQLQuery(q *querybuilder.Selection) *Client { return &Client{ query: q, @@ -5160,29 +7987,6 @@ func (r *Client) WithGraphQLQuery(q *querybuilder.Selection) *Client { } } -// Retrieves a content-addressed blob. -func (r *Client) Blob(digest string, size int, mediaType string, uncompressed string) *Directory { - q := r.query.Select("blob") - q = q.Arg("digest", digest) - q = q.Arg("size", size) - q = q.Arg("mediaType", mediaType) - q = q.Arg("uncompressed", uncompressed) - - return &Directory{ - query: q, - } -} - -// Retrieves a container builtin to the engine. -func (r *Client) BuiltinContainer(digest string) *Container { - q := r.query.Select("builtinContainer") - q = q.Arg("digest", digest) - - return &Container{ - query: q, - } -} - // Constructs a cache volume for a given cache key. func (r *Client) CacheVolume(key string) *CacheVolume { q := r.query.Select("cacheVolume") @@ -5193,35 +7997,27 @@ func (r *Client) CacheVolume(key string) *CacheVolume { } } -// Checks if the current Dagger Engine is compatible with an SDK's required version. -func (r *Client) CheckVersionCompatibility(ctx context.Context, version string) (bool, error) { - q := r.query.Select("checkVersionCompatibility") - q = q.Arg("version", version) - - var response bool +// Dagger Cloud configuration and state +func (r *Client) Cloud() *Cloud { + q := r.query.Select("cloud") - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Cloud{ + query: q, + } } // ContainerOpts contains options for Client.Container type ContainerOpts struct { - // DEPRECATED: Use `loadContainerFromID` instead. - ID ContainerID - // Platform to initialize the container with. + // Platform to initialize the container with. Defaults to the native platform of the current engine Platform Platform } -// Creates a scratch container. +// Creates a scratch container, with no image or metadata. // -// Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host. +// To pull an image, follow up with the "from" function. func (r *Client) Container(opts ...ContainerOpts) *Container { q := r.query.Select("container") for i := len(opts) - 1; i >= 0; i-- { - // `id` optional argument - if !querybuilder.IsZeroValue(opts[i].ID) { - q = q.Arg("id", opts[i].ID) - } // `platform` optional argument if !querybuilder.IsZeroValue(opts[i].Platform) { q = q.Arg("platform", opts[i].Platform) @@ -5296,31 +8092,73 @@ func (r *Client) DefaultPlatform(ctx context.Context) (Platform, error) { return response, q.Execute(ctx) } -// DirectoryOpts contains options for Client.Directory -type DirectoryOpts struct { - // DEPRECATED: Use `loadDirectoryFromID` isntead. - ID DirectoryID -} - // Creates an empty directory. -func (r *Client) Directory(opts ...DirectoryOpts) *Directory { +func (r *Client) Directory() *Directory { q := r.query.Select("directory") + + return &Directory{ + query: q, + } +} + +// EnvOpts contains options for Client.Env +type EnvOpts struct { + // Give the environment the same privileges as the caller: core API including host access, current module, and dependencies + Privileged bool + // Allow new outputs to be declared and saved in the environment + Writable bool +} + +// Initialize a new environment +// +// Experimental: Environments are not yet stabilized +func (r *Client) Env(opts ...EnvOpts) *Env { + q := r.query.Select("env") for i := len(opts) - 1; i >= 0; i-- { - // `id` optional argument - if !querybuilder.IsZeroValue(opts[i].ID) { - q = q.Arg("id", opts[i].ID) + // `privileged` optional argument + if !querybuilder.IsZeroValue(opts[i].Privileged) { + q = q.Arg("privileged", opts[i].Privileged) + } + // `writable` optional argument + if !querybuilder.IsZeroValue(opts[i].Writable) { + q = q.Arg("writable", opts[i].Writable) } } - return &Directory{ + return &Env{ + query: q, + } +} + +// Create a new error. +func (r *Client) Error(message string) *Error { + q := r.query.Select("error") + q = q.Arg("message", message) + + return &Error{ query: q, } } -// Deprecated: Use LoadFileFromID instead. -func (r *Client) File(id FileID) *File { +// FileOpts contains options for Client.File +type FileOpts struct { + // Permissions of the new file. Example: 0600 + // + // Default: 420 + Permissions int +} + +// Creates a file with the specified contents. +func (r *Client) File(name string, contents string, opts ...FileOpts) *File { q := r.query.Select("file") - q = q.Arg("id", id) + for i := len(opts) - 1; i >= 0; i-- { + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + } + q = q.Arg("name", name) + q = q.Arg("contents", contents) return &File{ query: q, @@ -5352,14 +8190,22 @@ func (r *Client) GeneratedCode(code *Directory) *GeneratedCode { // GitOpts contains options for Client.Git type GitOpts struct { - // Set to true to keep .git directory. + // DEPRECATED: Set to true to keep .git directory. + // + // Default: true KeepGitDir bool - // A service which must be started before the repo is fetched. - ExperimentalServiceHost *Service // Set SSH known hosts SSHKnownHosts string // Set SSH auth socket SSHAuthSocket *Socket + // Username used to populate the password during basic HTTP Authorization + HTTPAuthUsername string + // Secret used to populate the password during basic HTTP Authorization + HTTPAuthToken *Secret + // Secret used to populate the Authorization HTTP header + HTTPAuthHeader *Secret + // A service which must be started before the repo is fetched. + ExperimentalServiceHost *Service } // Queries a Git repository. @@ -5370,10 +8216,6 @@ func (r *Client) Git(url string, opts ...GitOpts) *GitRepository { if !querybuilder.IsZeroValue(opts[i].KeepGitDir) { q = q.Arg("keepGitDir", opts[i].KeepGitDir) } - // `experimentalServiceHost` optional argument - if !querybuilder.IsZeroValue(opts[i].ExperimentalServiceHost) { - q = q.Arg("experimentalServiceHost", opts[i].ExperimentalServiceHost) - } // `sshKnownHosts` optional argument if !querybuilder.IsZeroValue(opts[i].SSHKnownHosts) { q = q.Arg("sshKnownHosts", opts[i].SSHKnownHosts) @@ -5382,6 +8224,22 @@ func (r *Client) Git(url string, opts ...GitOpts) *GitRepository { if !querybuilder.IsZeroValue(opts[i].SSHAuthSocket) { q = q.Arg("sshAuthSocket", opts[i].SSHAuthSocket) } + // `httpAuthUsername` optional argument + if !querybuilder.IsZeroValue(opts[i].HTTPAuthUsername) { + q = q.Arg("httpAuthUsername", opts[i].HTTPAuthUsername) + } + // `httpAuthToken` optional argument + if !querybuilder.IsZeroValue(opts[i].HTTPAuthToken) { + q = q.Arg("httpAuthToken", opts[i].HTTPAuthToken) + } + // `httpAuthHeader` optional argument + if !querybuilder.IsZeroValue(opts[i].HTTPAuthHeader) { + q = q.Arg("httpAuthHeader", opts[i].HTTPAuthHeader) + } + // `experimentalServiceHost` optional argument + if !querybuilder.IsZeroValue(opts[i].ExperimentalServiceHost) { + q = q.Arg("experimentalServiceHost", opts[i].ExperimentalServiceHost) + } } q = q.Arg("url", url) @@ -5392,6 +8250,12 @@ func (r *Client) Git(url string, opts ...GitOpts) *GitRepository { // HTTPOpts contains options for Client.HTTP type HTTPOpts struct { + // File name to use for the file. Defaults to the last part of the URL. + Name string + // Permissions to set on the file. + Permissions int + // Secret used to populate the Authorization HTTP header + AuthHeader *Secret // A service which must be started before the URL is fetched. ExperimentalServiceHost *Service } @@ -5400,6 +8264,18 @@ type HTTPOpts struct { func (r *Client) HTTP(url string, opts ...HTTPOpts) *File { q := r.query.Select("http") for i := len(opts) - 1; i >= 0; i-- { + // `name` optional argument + if !querybuilder.IsZeroValue(opts[i].Name) { + q = q.Arg("name", opts[i].Name) + } + // `permissions` optional argument + if !querybuilder.IsZeroValue(opts[i].Permissions) { + q = q.Arg("permissions", opts[i].Permissions) + } + // `authHeader` optional argument + if !querybuilder.IsZeroValue(opts[i].AuthHeader) { + q = q.Arg("authHeader", opts[i].AuthHeader) + } // `experimentalServiceHost` optional argument if !querybuilder.IsZeroValue(opts[i].ExperimentalServiceHost) { q = q.Arg("experimentalServiceHost", opts[i].ExperimentalServiceHost) @@ -5412,6 +8288,45 @@ func (r *Client) HTTP(url string, opts ...HTTPOpts) *File { } } +// LLMOpts contains options for Client.LLM +type LLMOpts struct { + // Model to use + Model string + // Cap the number of API calls for this LLM + MaxAPICalls int +} + +// Initialize a Large Language Model (LLM) +// +// Experimental: LLM support is not yet stabilized +func (r *Client) LLM(opts ...LLMOpts) *LLM { + q := r.query.Select("llm") + for i := len(opts) - 1; i >= 0; i-- { + // `model` optional argument + if !querybuilder.IsZeroValue(opts[i].Model) { + q = q.Arg("model", opts[i].Model) + } + // `maxAPICalls` optional argument + if !querybuilder.IsZeroValue(opts[i].MaxAPICalls) { + q = q.Arg("maxAPICalls", opts[i].MaxAPICalls) + } + } + + return &LLM{ + query: q, + } +} + +// Load a Binding from its ID. +func (r *Client) LoadBindingFromID(id BindingID) *Binding { + q := r.query.Select("loadBindingFromID") + q = q.Arg("id", id) + + return &Binding{ + query: q, + } +} + // Load a CacheVolume from its ID. func (r *Client) LoadCacheVolumeFromID(id CacheVolumeID) *CacheVolume { q := r.query.Select("loadCacheVolumeFromID") @@ -5422,6 +8337,16 @@ func (r *Client) LoadCacheVolumeFromID(id CacheVolumeID) *CacheVolume { } } +// Load a Cloud from its ID. +func (r *Client) LoadCloudFromID(id CloudID) *Cloud { + q := r.query.Select("loadCloudFromID") + q = q.Arg("id", id) + + return &Cloud{ + query: q, + } +} + // Load a Container from its ID. func (r *Client) LoadContainerFromID(id ContainerID) *Container { q := r.query.Select("loadContainerFromID") @@ -5452,6 +8377,36 @@ func (r *Client) LoadDirectoryFromID(id DirectoryID) *Directory { } } +// Load a EnumTypeDef from its ID. +func (r *Client) LoadEnumTypeDefFromID(id EnumTypeDefID) *EnumTypeDef { + q := r.query.Select("loadEnumTypeDefFromID") + q = q.Arg("id", id) + + return &EnumTypeDef{ + query: q, + } +} + +// Load a EnumValueTypeDef from its ID. +func (r *Client) LoadEnumValueTypeDefFromID(id EnumValueTypeDefID) *EnumValueTypeDef { + q := r.query.Select("loadEnumValueTypeDefFromID") + q = q.Arg("id", id) + + return &EnumValueTypeDef{ + query: q, + } +} + +// Load a Env from its ID. +func (r *Client) LoadEnvFromID(id EnvID) *Env { + q := r.query.Select("loadEnvFromID") + q = q.Arg("id", id) + + return &Env{ + query: q, + } +} + // Load a EnvVariable from its ID. func (r *Client) LoadEnvVariableFromID(id EnvVariableID) *EnvVariable { q := r.query.Select("loadEnvVariableFromID") @@ -5462,6 +8417,26 @@ func (r *Client) LoadEnvVariableFromID(id EnvVariableID) *EnvVariable { } } +// Load a Error from its ID. +func (r *Client) LoadErrorFromID(id ErrorID) *Error { + q := r.query.Select("loadErrorFromID") + q = q.Arg("id", id) + + return &Error{ + query: q, + } +} + +// Load a ErrorValue from its ID. +func (r *Client) LoadErrorValueFromID(id ErrorValueID) *ErrorValue { + q := r.query.Select("loadErrorValueFromID") + q = q.Arg("id", id) + + return &ErrorValue{ + query: q, + } +} + // Load a FieldTypeDef from its ID. func (r *Client) LoadFieldTypeDefFromID(id FieldTypeDefID) *FieldTypeDef { q := r.query.Select("loadFieldTypeDefFromID") @@ -5532,16 +8507,6 @@ func (r *Client) LoadGeneratedCodeFromID(id GeneratedCodeID) *GeneratedCode { } } -// Load a GitModuleSource from its ID. -func (r *Client) LoadGitModuleSourceFromID(id GitModuleSourceID) *GitModuleSource { - q := r.query.Select("loadGitModuleSourceFromID") - q = q.Arg("id", id) - - return &GitModuleSource{ - query: q, - } -} - // Load a GitRef from its ID. func (r *Client) LoadGitRefFromID(id GitRefID) *GitRef { q := r.query.Select("loadGitRefFromID") @@ -5582,6 +8547,26 @@ func (r *Client) LoadInterfaceTypeDefFromID(id InterfaceTypeDefID) *InterfaceTyp } } +// Load a LLM from its ID. +func (r *Client) LoadLLMFromID(id LLMID) *LLM { + q := r.query.Select("loadLLMFromID") + q = q.Arg("id", id) + + return &LLM{ + query: q, + } +} + +// Load a LLMTokenUsage from its ID. +func (r *Client) LoadLLMTokenUsageFromID(id LLMTokenUsageID) *LLMTokenUsage { + q := r.query.Select("loadLLMTokenUsageFromID") + q = q.Arg("id", id) + + return &LLMTokenUsage{ + query: q, + } +} + // Load a Label from its ID. func (r *Client) LoadLabelFromID(id LabelID) *Label { q := r.query.Select("loadLabelFromID") @@ -5602,22 +8587,12 @@ func (r *Client) LoadListTypeDefFromID(id ListTypeDefID) *ListTypeDef { } } -// Load a LocalModuleSource from its ID. -func (r *Client) LoadLocalModuleSourceFromID(id LocalModuleSourceID) *LocalModuleSource { - q := r.query.Select("loadLocalModuleSourceFromID") - q = q.Arg("id", id) - - return &LocalModuleSource{ - query: q, - } -} - -// Load a ModuleDependency from its ID. -func (r *Client) LoadModuleDependencyFromID(id ModuleDependencyID) *ModuleDependency { - q := r.query.Select("loadModuleDependencyFromID") +// Load a ModuleConfigClient from its ID. +func (r *Client) LoadModuleConfigClientFromID(id ModuleConfigClientID) *ModuleConfigClient { + q := r.query.Select("loadModuleConfigClientFromID") q = q.Arg("id", id) - return &ModuleDependency{ + return &ModuleConfigClient{ query: q, } } @@ -5662,6 +8637,26 @@ func (r *Client) LoadPortFromID(id PortID) *Port { } } +// Load a SDKConfig from its ID. +func (r *Client) LoadSDKConfigFromID(id SDKConfigID) *SDKConfig { + q := r.query.Select("loadSDKConfigFromID") + q = q.Arg("id", id) + + return &SDKConfig{ + query: q, + } +} + +// Load a ScalarTypeDef from its ID. +func (r *Client) LoadScalarTypeDefFromID(id ScalarTypeDefID) *ScalarTypeDef { + q := r.query.Select("loadScalarTypeDefFromID") + q = q.Arg("id", id) + + return &ScalarTypeDef{ + query: q, + } +} + // Load a Secret from its ID. func (r *Client) LoadSecretFromID(id SecretID) *Secret { q := r.query.Select("loadSecretFromID") @@ -5692,6 +8687,16 @@ func (r *Client) LoadSocketFromID(id SocketID) *Socket { } } +// Load a SourceMap from its ID. +func (r *Client) LoadSourceMapFromID(id SourceMapID) *SourceMap { + q := r.query.Select("loadSourceMapFromID") + q = q.Arg("id", id) + + return &SourceMap{ + query: q, + } +} + // Load a Terminal from its ID. func (r *Client) LoadTerminalFromID(id TerminalID) *Terminal { q := r.query.Select("loadTerminalFromID") @@ -5712,142 +8717,303 @@ func (r *Client) LoadTypeDefFromID(id TypeDefID) *TypeDef { } } -// Create a new module. -func (r *Client) Module() *Module { - q := r.query.Select("module") - - return &Module{ +// Create a new module. +func (r *Client) Module() *Module { + q := r.query.Select("module") + + return &Module{ + query: q, + } +} + +// ModuleSourceOpts contains options for Client.ModuleSource +type ModuleSourceOpts struct { + // The pinned version of the module source + RefPin string + // If true, do not attempt to find dagger.json in a parent directory of the provided path. Only relevant for local module sources. + DisableFindUp bool + // If true, do not error out if the provided ref string is a local path and does not exist yet. Useful when initializing new modules in directories that don't exist yet. + AllowNotExists bool + // If set, error out if the ref string is not of the provided requireKind. + RequireKind ModuleSourceKind +} + +// Create a new module source instance from a source ref string +func (r *Client) ModuleSource(refString string, opts ...ModuleSourceOpts) *ModuleSource { + q := r.query.Select("moduleSource") + for i := len(opts) - 1; i >= 0; i-- { + // `refPin` optional argument + if !querybuilder.IsZeroValue(opts[i].RefPin) { + q = q.Arg("refPin", opts[i].RefPin) + } + // `disableFindUp` optional argument + if !querybuilder.IsZeroValue(opts[i].DisableFindUp) { + q = q.Arg("disableFindUp", opts[i].DisableFindUp) + } + // `allowNotExists` optional argument + if !querybuilder.IsZeroValue(opts[i].AllowNotExists) { + q = q.Arg("allowNotExists", opts[i].AllowNotExists) + } + // `requireKind` optional argument + if !querybuilder.IsZeroValue(opts[i].RequireKind) { + q = q.Arg("requireKind", opts[i].RequireKind) + } + } + q = q.Arg("refString", refString) + + return &ModuleSource{ + query: q, + } +} + +// SecretOpts contains options for Client.Secret +type SecretOpts struct { + // If set, the given string will be used as the cache key for this secret. This means that any secrets with the same cache key will be considered equivalent in terms of cache lookups, even if they have different URIs or plaintext values. + // + // For example, two secrets with the same cache key provided as secret env vars to other wise equivalent containers will result in the container withExecs hitting the cache for each other. + // + // If not set, the cache key for the secret will be derived from its plaintext value as looked up when the secret is constructed. + CacheKey string +} + +// Creates a new secret. +func (r *Client) Secret(uri string, opts ...SecretOpts) *Secret { + q := r.query.Select("secret") + for i := len(opts) - 1; i >= 0; i-- { + // `cacheKey` optional argument + if !querybuilder.IsZeroValue(opts[i].CacheKey) { + q = q.Arg("cacheKey", opts[i].CacheKey) + } + } + q = q.Arg("uri", uri) + + return &Secret{ + query: q, + } +} + +// Sets a secret given a user defined name to its plaintext and returns the secret. +// +// The plaintext value is limited to a size of 128000 bytes. +func (r *Client) SetSecret(name string, plaintext string) *Secret { + q := r.query.Select("setSecret") + q = q.Arg("name", name) + q = q.Arg("plaintext", plaintext) + + return &Secret{ + query: q, + } +} + +// Creates source map metadata. +func (r *Client) SourceMap(filename string, line int, column int) *SourceMap { + q := r.query.Select("sourceMap") + q = q.Arg("filename", filename) + q = q.Arg("line", line) + q = q.Arg("column", column) + + return &SourceMap{ + query: q, + } +} + +// Create a new TypeDef. +func (r *Client) TypeDef() *TypeDef { + q := r.query.Select("typeDef") + + return &TypeDef{ + query: q, + } +} + +// Get the current Dagger Engine version. +func (r *Client) Version(ctx context.Context) (string, error) { + q := r.query.Select("version") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The SDK config of the module. +type SDKConfig struct { + query *querybuilder.Selection + + id *SDKConfigID + source *string +} + +func (r *SDKConfig) WithGraphQLQuery(q *querybuilder.Selection) *SDKConfig { + return &SDKConfig{ + query: q, + } +} + +// A unique identifier for this SDKConfig. +func (r *SDKConfig) ID(ctx context.Context) (SDKConfigID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response SDKConfigID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *SDKConfig) XXX_GraphQLType() string { + return "SDKConfig" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *SDKConfig) XXX_GraphQLIDType() string { + return "SDKConfigID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *SDKConfig) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *SDKConfig) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *SDKConfig) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadSDKConfigFromID(SDKConfigID(id)) + return nil +} + +// Source of the SDK. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation. +func (r *SDKConfig) Source(ctx context.Context) (string, error) { + if r.source != nil { + return *r.source, nil + } + q := r.query.Select("source") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A definition of a custom scalar defined in a Module. +type ScalarTypeDef struct { + query *querybuilder.Selection + + description *string + id *ScalarTypeDefID + name *string + sourceModuleName *string +} + +func (r *ScalarTypeDef) WithGraphQLQuery(q *querybuilder.Selection) *ScalarTypeDef { + return &ScalarTypeDef{ query: q, } } -// ModuleDependencyOpts contains options for Client.ModuleDependency -type ModuleDependencyOpts struct { - // If set, the name to use for the dependency. Otherwise, once installed to a parent module, the name of the dependency module will be used by default. - Name string -} - -// Create a new module dependency configuration from a module source and name -func (r *Client) ModuleDependency(source *ModuleSource, opts ...ModuleDependencyOpts) *ModuleDependency { - assertNotNil("source", source) - q := r.query.Select("moduleDependency") - for i := len(opts) - 1; i >= 0; i-- { - // `name` optional argument - if !querybuilder.IsZeroValue(opts[i].Name) { - q = q.Arg("name", opts[i].Name) - } +// A doc string for the scalar, if any. +func (r *ScalarTypeDef) Description(ctx context.Context) (string, error) { + if r.description != nil { + return *r.description, nil } - q = q.Arg("source", source) + q := r.query.Select("description") - return &ModuleDependency{ - query: q, - } -} + var response string -// ModuleSourceOpts contains options for Client.ModuleSource -type ModuleSourceOpts struct { - // If true, enforce that the source is a stable version for source kinds that support versioning. - Stable bool + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Create a new module source instance from a source ref string. -func (r *Client) ModuleSource(refString string, opts ...ModuleSourceOpts) *ModuleSource { - q := r.query.Select("moduleSource") - for i := len(opts) - 1; i >= 0; i-- { - // `stable` optional argument - if !querybuilder.IsZeroValue(opts[i].Stable) { - q = q.Arg("stable", opts[i].Stable) - } +// A unique identifier for this ScalarTypeDef. +func (r *ScalarTypeDef) ID(ctx context.Context) (ScalarTypeDefID, error) { + if r.id != nil { + return *r.id, nil } - q = q.Arg("refString", refString) + q := r.query.Select("id") - return &ModuleSource{ - query: q, - } + var response ScalarTypeDefID + + q = q.Bind(&response) + return response, q.Execute(ctx) } -// PipelineOpts contains options for Client.Pipeline -type PipelineOpts struct { - // Description of the sub-pipeline. - Description string - // Labels to apply to the sub-pipeline. - Labels []PipelineLabel +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *ScalarTypeDef) XXX_GraphQLType() string { + return "ScalarTypeDef" } -// Creates a named sub-pipeline. -func (r *Client) Pipeline(name string, opts ...PipelineOpts) *Client { - q := r.query.Select("pipeline") - for i := len(opts) - 1; i >= 0; i-- { - // `description` optional argument - if !querybuilder.IsZeroValue(opts[i].Description) { - q = q.Arg("description", opts[i].Description) - } - // `labels` optional argument - if !querybuilder.IsZeroValue(opts[i].Labels) { - q = q.Arg("labels", opts[i].Labels) - } - } - q = q.Arg("name", name) +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *ScalarTypeDef) XXX_GraphQLIDType() string { + return "ScalarTypeDefID" +} - return &Client{ - query: q, - client: r.client, +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *ScalarTypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err } + return string(id), nil } -// SecretOpts contains options for Client.Secret -type SecretOpts struct { - Accessor string +func (r *ScalarTypeDef) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) } - -// Reference a secret by name. -func (r *Client) Secret(name string, opts ...SecretOpts) *Secret { - q := r.query.Select("secret") - for i := len(opts) - 1; i >= 0; i-- { - // `accessor` optional argument - if !querybuilder.IsZeroValue(opts[i].Accessor) { - q = q.Arg("accessor", opts[i].Accessor) - } +func (r *ScalarTypeDef) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err } - q = q.Arg("name", name) + *r = *dag.LoadScalarTypeDefFromID(ScalarTypeDefID(id)) + return nil +} - return &Secret{ - query: q, +// The name of the scalar. +func (r *ScalarTypeDef) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil } -} + q := r.query.Select("name") -// Sets a secret given a user defined name to its plaintext and returns the secret. -// -// The plaintext value is limited to a size of 128000 bytes. -func (r *Client) SetSecret(name string, plaintext string) *Secret { - q := r.query.Select("setSecret") - q = q.Arg("name", name) - q = q.Arg("plaintext", plaintext) + var response string - return &Secret{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } -// Loads a socket by its ID. -// -// Deprecated: Use LoadSocketFromID instead. -func (r *Client) Socket(id SocketID) *Socket { - q := r.query.Select("socket") - q = q.Arg("id", id) - - return &Socket{ - query: q, +// If this ScalarTypeDef is associated with a Module, the name of the module. Unset otherwise. +func (r *ScalarTypeDef) SourceModuleName(ctx context.Context) (string, error) { + if r.sourceModuleName != nil { + return *r.sourceModuleName, nil } -} + q := r.query.Select("sourceModuleName") -// Create a new TypeDef. -func (r *Client) TypeDef() *TypeDef { - q := r.query.Select("typeDef") + var response string - return &TypeDef{ - query: q, - } + q = q.Bind(&response) + return response, q.Execute(ctx) } // A reference to a secret value, which can be handled more safely than the value itself. @@ -5855,7 +9021,9 @@ type Secret struct { query *querybuilder.Selection id *SecretID + name *string plaintext *string + uri *string } func (r *Secret) WithGraphQLQuery(q *querybuilder.Selection) *Secret { @@ -5897,7 +9065,7 @@ func (r *Secret) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Secret) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -5913,6 +9081,19 @@ func (r *Secret) UnmarshalJSON(bs []byte) error { return nil } +// The name of this secret. +func (r *Secret) Name(ctx context.Context) (string, error) { + if r.name != nil { + return *r.name, nil + } + q := r.query.Select("name") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + // The value of this secret. func (r *Secret) Plaintext(ctx context.Context) (string, error) { if r.plaintext != nil { @@ -5926,6 +9107,19 @@ func (r *Secret) Plaintext(ctx context.Context) (string, error) { return response, q.Execute(ctx) } +// The URI of this secret. +func (r *Secret) URI(ctx context.Context) (string, error) { + if r.uri != nil { + return *r.uri, nil + } + q := r.query.Select("uri") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + // A content-addressed service providing TCP connectivity. type Service struct { query *querybuilder.Selection @@ -5937,6 +9131,14 @@ type Service struct { stop *ServiceID up *Void } +type WithServiceFunc func(r *Service) *Service + +// With calls the provided function with current Service. +// +// This is useful for reusability and readability by not breaking the calling chain. +func (r *Service) With(f WithServiceFunc) *Service { + return f(r) +} func (r *Service) WithGraphQLQuery(q *querybuilder.Selection) *Service { return &Service{ @@ -6025,7 +9227,7 @@ func (r *Service) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Service) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -6080,7 +9282,13 @@ func (r *Service) Ports(ctx context.Context) ([]Port, error) { func (r *Service) Start(ctx context.Context) (*Service, error) { q := r.query.Select("start") - return r, q.Execute(ctx) + var id ServiceID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Service{ + query: q.Root().Select("loadServiceFromID").Arg("id", id), + }, nil } // ServiceStopOpts contains options for Service.Stop @@ -6099,7 +9307,13 @@ func (r *Service) Stop(ctx context.Context, opts ...ServiceStopOpts) (*Service, } } - return r, q.Execute(ctx) + var id ServiceID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Service{ + query: q.Root().Select("loadServiceFromID").Arg("id", id), + }, nil } // ServiceUpOpts contains options for Service.Up @@ -6113,9 +9327,9 @@ type ServiceUpOpts struct { } // Creates a tunnel that forwards traffic from the caller's network to this service. -func (r *Service) Up(ctx context.Context, opts ...ServiceUpOpts) (Void, error) { +func (r *Service) Up(ctx context.Context, opts ...ServiceUpOpts) error { if r.up != nil { - return *r.up, nil + return nil } q := r.query.Select("up") for i := len(opts) - 1; i >= 0; i-- { @@ -6129,10 +9343,17 @@ func (r *Service) Up(ctx context.Context, opts ...ServiceUpOpts) (Void, error) { } } - var response Void + return q.Execute(ctx) +} + +// Configures a hostname which can be used by clients within the session to reach this container. +func (r *Service) WithHostname(hostname string) *Service { + q := r.query.Select("withHostname") + q = q.Arg("hostname", hostname) - q = q.Bind(&response) - return response, q.Execute(ctx) + return &Service{ + query: q, + } } // A Unix or TCP/IP socket that can be mounted into a container. @@ -6181,7 +9402,7 @@ func (r *Socket) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Socket) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -6197,12 +9418,144 @@ func (r *Socket) UnmarshalJSON(bs []byte) error { return nil } +// Source location information. +type SourceMap struct { + query *querybuilder.Selection + + column *int + filename *string + id *SourceMapID + line *int + module *string + url *string +} + +func (r *SourceMap) WithGraphQLQuery(q *querybuilder.Selection) *SourceMap { + return &SourceMap{ + query: q, + } +} + +// The column number within the line. +func (r *SourceMap) Column(ctx context.Context) (int, error) { + if r.column != nil { + return *r.column, nil + } + q := r.query.Select("column") + + var response int + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The filename from the module source. +func (r *SourceMap) Filename(ctx context.Context) (string, error) { + if r.filename != nil { + return *r.filename, nil + } + q := r.query.Select("filename") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// A unique identifier for this SourceMap. +func (r *SourceMap) ID(ctx context.Context) (SourceMapID, error) { + if r.id != nil { + return *r.id, nil + } + q := r.query.Select("id") + + var response SourceMapID + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// XXX_GraphQLType is an internal function. It returns the native GraphQL type name +func (r *SourceMap) XXX_GraphQLType() string { + return "SourceMap" +} + +// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object +func (r *SourceMap) XXX_GraphQLIDType() string { + return "SourceMapID" +} + +// XXX_GraphQLID is an internal function. It returns the underlying type ID +func (r *SourceMap) XXX_GraphQLID(ctx context.Context) (string, error) { + id, err := r.ID(ctx) + if err != nil { + return "", err + } + return string(id), nil +} + +func (r *SourceMap) MarshalJSON() ([]byte, error) { + id, err := r.ID(marshalCtx) + if err != nil { + return nil, err + } + return json.Marshal(id) +} +func (r *SourceMap) UnmarshalJSON(bs []byte) error { + var id string + err := json.Unmarshal(bs, &id) + if err != nil { + return err + } + *r = *dag.LoadSourceMapFromID(SourceMapID(id)) + return nil +} + +// The line number within the filename. +func (r *SourceMap) Line(ctx context.Context) (int, error) { + if r.line != nil { + return *r.line, nil + } + q := r.query.Select("line") + + var response int + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The module dependency this was declared in. +func (r *SourceMap) Module(ctx context.Context) (string, error) { + if r.module != nil { + return *r.module, nil + } + q := r.query.Select("module") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + +// The URL to the file, if any. This can be used to link to the source map in the browser. +func (r *SourceMap) URL(ctx context.Context) (string, error) { + if r.url != nil { + return *r.url, nil + } + q := r.query.Select("url") + + var response string + + q = q.Bind(&response) + return response, q.Execute(ctx) +} + // An interactive terminal that clients can connect to. type Terminal struct { query *querybuilder.Selection - id *TerminalID - websocketEndpoint *string + id *TerminalID + sync *TerminalID } func (r *Terminal) WithGraphQLQuery(q *querybuilder.Selection) *Terminal { @@ -6244,7 +9597,7 @@ func (r *Terminal) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *Terminal) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -6260,17 +9613,19 @@ func (r *Terminal) UnmarshalJSON(bs []byte) error { return nil } -// An http endpoint at which this terminal can be connected to over a websocket. -func (r *Terminal) WebsocketEndpoint(ctx context.Context) (string, error) { - if r.websocketEndpoint != nil { - return *r.websocketEndpoint, nil - } - q := r.query.Select("websocketEndpoint") - - var response string +// Forces evaluation of the pipeline in the engine. +// +// It doesn't run the default command if no exec has been set. +func (r *Terminal) Sync(ctx context.Context) (*Terminal, error) { + q := r.query.Select("sync") - q = q.Bind(&response) - return response, q.Execute(ctx) + var id TerminalID + if err := q.Bind(&id).Execute(ctx); err != nil { + return nil, err + } + return &Terminal{ + query: q.Root().Select("loadTerminalFromID").Arg("id", id), + }, nil } // A definition of a parameter or return type in a Module. @@ -6296,6 +9651,15 @@ func (r *TypeDef) WithGraphQLQuery(q *querybuilder.Selection) *TypeDef { } } +// If kind is ENUM, the enum-specific type definition. If kind is not ENUM, this will be null. +func (r *TypeDef) AsEnum() *EnumTypeDef { + q := r.query.Select("asEnum") + + return &EnumTypeDef{ + query: q, + } +} + // If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null. func (r *TypeDef) AsInput() *InputTypeDef { q := r.query.Select("asInput") @@ -6332,6 +9696,15 @@ func (r *TypeDef) AsObject() *ObjectTypeDef { } } +// If kind is SCALAR, the scalar-specific type definition. If kind is not SCALAR, this will be null. +func (r *TypeDef) AsScalar() *ScalarTypeDef { + q := r.query.Select("asScalar") + + return &ScalarTypeDef{ + query: q, + } +} + // A unique identifier for this TypeDef. func (r *TypeDef) ID(ctx context.Context) (TypeDefID, error) { if r.id != nil { @@ -6365,7 +9738,7 @@ func (r *TypeDef) XXX_GraphQLID(ctx context.Context) (string, error) { } func (r *TypeDef) MarshalJSON() ([]byte, error) { - id, err := r.ID(context.Background()) + id, err := r.ID(marshalCtx) if err != nil { return nil, err } @@ -6418,10 +9791,106 @@ func (r *TypeDef) WithConstructor(function *Function) *TypeDef { } } +// TypeDefWithEnumOpts contains options for TypeDef.WithEnum +type TypeDefWithEnumOpts struct { + // A doc string for the enum, if any + Description string + // The source map for the enum definition. + SourceMap *SourceMap +} + +// Returns a TypeDef of kind Enum with the provided name. +// +// Note that an enum's values may be omitted if the intent is only to refer to an enum. This is how functions are able to return their own, or any other circular reference. +func (r *TypeDef) WithEnum(name string, opts ...TypeDefWithEnumOpts) *TypeDef { + q := r.query.Select("withEnum") + for i := len(opts) - 1; i >= 0; i-- { + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } + } + q = q.Arg("name", name) + + return &TypeDef{ + query: q, + } +} + +// TypeDefWithEnumMemberOpts contains options for TypeDef.WithEnumMember +type TypeDefWithEnumMemberOpts struct { + // The value of the member in the enum + Value string + // A doc string for the member, if any + Description string + // The source map for the enum member definition. + SourceMap *SourceMap +} + +// Adds a static value for an Enum TypeDef, failing if the type is not an enum. +func (r *TypeDef) WithEnumMember(name string, opts ...TypeDefWithEnumMemberOpts) *TypeDef { + q := r.query.Select("withEnumMember") + for i := len(opts) - 1; i >= 0; i-- { + // `value` optional argument + if !querybuilder.IsZeroValue(opts[i].Value) { + q = q.Arg("value", opts[i].Value) + } + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } + } + q = q.Arg("name", name) + + return &TypeDef{ + query: q, + } +} + +// TypeDefWithEnumValueOpts contains options for TypeDef.WithEnumValue +type TypeDefWithEnumValueOpts struct { + // A doc string for the value, if any + Description string + // The source map for the enum value definition. + SourceMap *SourceMap +} + +// Adds a static value for an Enum TypeDef, failing if the type is not an enum. +// +// Deprecated: Use WithEnumMember instead +func (r *TypeDef) WithEnumValue(value string, opts ...TypeDefWithEnumValueOpts) *TypeDef { + q := r.query.Select("withEnumValue") + for i := len(opts) - 1; i >= 0; i-- { + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } + } + q = q.Arg("value", value) + + return &TypeDef{ + query: q, + } +} + // TypeDefWithFieldOpts contains options for TypeDef.WithField type TypeDefWithFieldOpts struct { // A doc string for the field, if any Description string + // The source map for the field definition. + SourceMap *SourceMap } // Adds a static field for an Object TypeDef, failing if the type is not an object. @@ -6433,6 +9902,10 @@ func (r *TypeDef) WithField(name string, typeDef *TypeDef, opts ...TypeDefWithFi if !querybuilder.IsZeroValue(opts[i].Description) { q = q.Arg("description", opts[i].Description) } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } } q = q.Arg("name", name) q = q.Arg("typeDef", typeDef) @@ -6456,6 +9929,8 @@ func (r *TypeDef) WithFunction(function *Function) *TypeDef { // TypeDefWithInterfaceOpts contains options for TypeDef.WithInterface type TypeDefWithInterfaceOpts struct { Description string + + SourceMap *SourceMap } // Returns a TypeDef of kind Interface with the provided name. @@ -6466,6 +9941,10 @@ func (r *TypeDef) WithInterface(name string, opts ...TypeDefWithInterfaceOpts) * if !querybuilder.IsZeroValue(opts[i].Description) { q = q.Arg("description", opts[i].Description) } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } } q = q.Arg("name", name) @@ -6498,6 +9977,8 @@ func (r *TypeDef) WithListOf(elementType *TypeDef) *TypeDef { // TypeDefWithObjectOpts contains options for TypeDef.WithObject type TypeDefWithObjectOpts struct { Description string + + SourceMap *SourceMap } // Returns a TypeDef of kind Object with the provided name. @@ -6510,6 +9991,10 @@ func (r *TypeDef) WithObject(name string, opts ...TypeDefWithObjectOpts) *TypeDe if !querybuilder.IsZeroValue(opts[i].Description) { q = q.Arg("description", opts[i].Description) } + // `sourceMap` optional argument + if !querybuilder.IsZeroValue(opts[i].SourceMap) { + q = q.Arg("sourceMap", opts[i].SourceMap) + } } q = q.Arg("name", name) @@ -6528,101 +10013,657 @@ func (r *TypeDef) WithOptional(optional bool) *TypeDef { } } +// TypeDefWithScalarOpts contains options for TypeDef.WithScalar +type TypeDefWithScalarOpts struct { + Description string +} + +// Returns a TypeDef of kind Scalar with the provided name. +func (r *TypeDef) WithScalar(name string, opts ...TypeDefWithScalarOpts) *TypeDef { + q := r.query.Select("withScalar") + for i := len(opts) - 1; i >= 0; i-- { + // `description` optional argument + if !querybuilder.IsZeroValue(opts[i].Description) { + q = q.Arg("description", opts[i].Description) + } + } + q = q.Arg("name", name) + + return &TypeDef{ + query: q, + } +} + +// Sharing mode of the cache volume. type CacheSharingMode string func (CacheSharingMode) IsEnum() {} +func (v CacheSharingMode) Name() string { + switch v { + case CacheSharingModeShared: + return "SHARED" + case CacheSharingModePrivate: + return "PRIVATE" + case CacheSharingModeLocked: + return "LOCKED" + default: + return "" + } +} + +func (v CacheSharingMode) Value() string { + return string(v) +} + +func (v *CacheSharingMode) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *CacheSharingMode) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "LOCKED": + *v = CacheSharingModeLocked + case "PRIVATE": + *v = CacheSharingModePrivate + case "SHARED": + *v = CacheSharingModeShared + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + const ( - // Shares the cache volume amongst many build pipelines, but will serialize the writes - Locked CacheSharingMode = "LOCKED" + // Shares the cache volume amongst many build pipelines + CacheSharingModeShared CacheSharingMode = "SHARED" // Keeps a cache volume for a single build pipeline - Private CacheSharingMode = "PRIVATE" + CacheSharingModePrivate CacheSharingMode = "PRIVATE" - // Shares the cache volume amongst many build pipelines - Shared CacheSharingMode = "SHARED" + // Shares the cache volume amongst many build pipelines, but will serialize the writes + CacheSharingModeLocked CacheSharingMode = "LOCKED" +) + +// File type. +type ExistsType string + +func (ExistsType) IsEnum() {} + +func (v ExistsType) Name() string { + switch v { + case ExistsTypeRegularType: + return "REGULAR_TYPE" + case ExistsTypeDirectoryType: + return "DIRECTORY_TYPE" + case ExistsTypeSymlinkType: + return "SYMLINK_TYPE" + default: + return "" + } +} + +func (v ExistsType) Value() string { + return string(v) +} + +func (v *ExistsType) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *ExistsType) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "DIRECTORY_TYPE": + *v = ExistsTypeDirectoryType + case "REGULAR_TYPE": + *v = ExistsTypeRegularType + case "SYMLINK_TYPE": + *v = ExistsTypeSymlinkType + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + +const ( + // Tests path is a regular file + ExistsTypeRegularType ExistsType = "REGULAR_TYPE" + + // Tests path is a directory + ExistsTypeDirectoryType ExistsType = "DIRECTORY_TYPE" + + // Tests path is a symlink + ExistsTypeSymlinkType ExistsType = "SYMLINK_TYPE" ) +// Compression algorithm to use for image layers. type ImageLayerCompression string func (ImageLayerCompression) IsEnum() {} +func (v ImageLayerCompression) Name() string { + switch v { + case ImageLayerCompressionGzip: + return "Gzip" + case ImageLayerCompressionZstd: + return "Zstd" + case ImageLayerCompressionEstarGz: + return "EStarGZ" + case ImageLayerCompressionUncompressed: + return "Uncompressed" + default: + return "" + } +} + +func (v ImageLayerCompression) Value() string { + return string(v) +} + +func (v *ImageLayerCompression) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *ImageLayerCompression) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "EStarGZ": + *v = ImageLayerCompressionEstarGz + case "ESTARGZ": + *v = ImageLayerCompressionEstargz + case "Gzip": + *v = ImageLayerCompressionGzip + case "Uncompressed": + *v = ImageLayerCompressionUncompressed + case "Zstd": + *v = ImageLayerCompressionZstd + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + const ( - Estargz ImageLayerCompression = "EStarGZ" + ImageLayerCompressionGzip ImageLayerCompression = "Gzip" - Gzip ImageLayerCompression = "Gzip" + ImageLayerCompressionZstd ImageLayerCompression = "Zstd" - Uncompressed ImageLayerCompression = "Uncompressed" + ImageLayerCompressionEstarGz ImageLayerCompression = "EStarGZ" + ImageLayerCompressionEstargz ImageLayerCompression = ImageLayerCompressionEstarGz - Zstd ImageLayerCompression = "Zstd" + ImageLayerCompressionUncompressed ImageLayerCompression = "Uncompressed" ) +// Mediatypes to use in published or exported image metadata. type ImageMediaTypes string func (ImageMediaTypes) IsEnum() {} +func (v ImageMediaTypes) Name() string { + switch v { + case ImageMediaTypesOcimediaTypes: + return "OCIMediaTypes" + case ImageMediaTypesDockerMediaTypes: + return "DockerMediaTypes" + default: + return "" + } +} + +func (v ImageMediaTypes) Value() string { + return string(v) +} + +func (v *ImageMediaTypes) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *ImageMediaTypes) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "DOCKER": + *v = ImageMediaTypesDocker + case "DockerMediaTypes": + *v = ImageMediaTypesDockerMediaTypes + case "OCI": + *v = ImageMediaTypesOci + case "OCIMediaTypes": + *v = ImageMediaTypesOcimediaTypes + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + const ( - Dockermediatypes ImageMediaTypes = "DockerMediaTypes" + ImageMediaTypesOcimediaTypes ImageMediaTypes = "OCIMediaTypes" + ImageMediaTypesOci ImageMediaTypes = ImageMediaTypesOcimediaTypes - Ocimediatypes ImageMediaTypes = "OCIMediaTypes" + ImageMediaTypesDockerMediaTypes ImageMediaTypes = "DockerMediaTypes" + ImageMediaTypesDocker ImageMediaTypes = ImageMediaTypesDockerMediaTypes ) +// The kind of module source. type ModuleSourceKind string func (ModuleSourceKind) IsEnum() {} +func (v ModuleSourceKind) Name() string { + switch v { + case ModuleSourceKindLocalSource: + return "LOCAL_SOURCE" + case ModuleSourceKindGitSource: + return "GIT_SOURCE" + case ModuleSourceKindDirSource: + return "DIR_SOURCE" + default: + return "" + } +} + +func (v ModuleSourceKind) Value() string { + return string(v) +} + +func (v *ModuleSourceKind) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *ModuleSourceKind) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "DIR": + *v = ModuleSourceKindDir + case "DIR_SOURCE": + *v = ModuleSourceKindDirSource + case "GIT": + *v = ModuleSourceKindGit + case "GIT_SOURCE": + *v = ModuleSourceKindGitSource + case "LOCAL": + *v = ModuleSourceKindLocal + case "LOCAL_SOURCE": + *v = ModuleSourceKindLocalSource + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + const ( - GitSource ModuleSourceKind = "GIT_SOURCE" + ModuleSourceKindLocalSource ModuleSourceKind = "LOCAL_SOURCE" + ModuleSourceKindLocal ModuleSourceKind = ModuleSourceKindLocalSource + + ModuleSourceKindGitSource ModuleSourceKind = "GIT_SOURCE" + ModuleSourceKindGit ModuleSourceKind = ModuleSourceKindGitSource - LocalSource ModuleSourceKind = "LOCAL_SOURCE" + ModuleSourceKindDirSource ModuleSourceKind = "DIR_SOURCE" + ModuleSourceKindDir ModuleSourceKind = ModuleSourceKindDirSource ) +// Transport layer network protocol associated to a port. type NetworkProtocol string func (NetworkProtocol) IsEnum() {} +func (v NetworkProtocol) Name() string { + switch v { + case NetworkProtocolTcp: + return "TCP" + case NetworkProtocolUdp: + return "UDP" + default: + return "" + } +} + +func (v NetworkProtocol) Value() string { + return string(v) +} + +func (v *NetworkProtocol) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *NetworkProtocol) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "TCP": + *v = NetworkProtocolTcp + case "UDP": + *v = NetworkProtocolUdp + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + +const ( + NetworkProtocolTcp NetworkProtocol = "TCP" + + NetworkProtocolUdp NetworkProtocol = "UDP" +) + +// Expected return type of an execution +type ReturnType string + +func (ReturnType) IsEnum() {} + +func (v ReturnType) Name() string { + switch v { + case ReturnTypeSuccess: + return "SUCCESS" + case ReturnTypeFailure: + return "FAILURE" + case ReturnTypeAny: + return "ANY" + default: + return "" + } +} + +func (v ReturnType) Value() string { + return string(v) +} + +func (v *ReturnType) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *ReturnType) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "ANY": + *v = ReturnTypeAny + case "FAILURE": + *v = ReturnTypeFailure + case "SUCCESS": + *v = ReturnTypeSuccess + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} + const ( - Tcp NetworkProtocol = "TCP" + // A successful execution (exit code 0) + ReturnTypeSuccess ReturnType = "SUCCESS" - Udp NetworkProtocol = "UDP" + // A failed execution (exit codes 1-127) + ReturnTypeFailure ReturnType = "FAILURE" + + // Any execution (exit codes 0-127) + ReturnTypeAny ReturnType = "ANY" ) +// Distinguishes the different kinds of TypeDefs. type TypeDefKind string func (TypeDefKind) IsEnum() {} -const ( - // A boolean value. - BooleanKind TypeDefKind = "BOOLEAN_KIND" +func (v TypeDefKind) Name() string { + switch v { + case TypeDefKindStringKind: + return "STRING_KIND" + case TypeDefKindIntegerKind: + return "INTEGER_KIND" + case TypeDefKindFloatKind: + return "FLOAT_KIND" + case TypeDefKindBooleanKind: + return "BOOLEAN_KIND" + case TypeDefKindScalarKind: + return "SCALAR_KIND" + case TypeDefKindListKind: + return "LIST_KIND" + case TypeDefKindObjectKind: + return "OBJECT_KIND" + case TypeDefKindInterfaceKind: + return "INTERFACE_KIND" + case TypeDefKindInputKind: + return "INPUT_KIND" + case TypeDefKindVoidKind: + return "VOID_KIND" + case TypeDefKindEnumKind: + return "ENUM_KIND" + default: + return "" + } +} + +func (v TypeDefKind) Value() string { + return string(v) +} + +func (v *TypeDefKind) MarshalJSON() ([]byte, error) { + if *v == "" { + return []byte(`""`), nil + } + name := v.Name() + if name == "" { + return nil, fmt.Errorf("invalid enum value %q", *v) + } + return json.Marshal(name) +} + +func (v *TypeDefKind) UnmarshalJSON(dt []byte) error { + var s string + if err := json.Unmarshal(dt, &s); err != nil { + return err + } + switch s { + case "": + *v = "" + case "BOOLEAN": + *v = TypeDefKindBoolean + case "BOOLEAN_KIND": + *v = TypeDefKindBooleanKind + case "ENUM": + *v = TypeDefKindEnum + case "ENUM_KIND": + *v = TypeDefKindEnumKind + case "FLOAT": + *v = TypeDefKindFloat + case "FLOAT_KIND": + *v = TypeDefKindFloatKind + case "INPUT": + *v = TypeDefKindInput + case "INPUT_KIND": + *v = TypeDefKindInputKind + case "INTEGER": + *v = TypeDefKindInteger + case "INTEGER_KIND": + *v = TypeDefKindIntegerKind + case "INTERFACE": + *v = TypeDefKindInterface + case "INTERFACE_KIND": + *v = TypeDefKindInterfaceKind + case "LIST": + *v = TypeDefKindList + case "LIST_KIND": + *v = TypeDefKindListKind + case "OBJECT": + *v = TypeDefKindObject + case "OBJECT_KIND": + *v = TypeDefKindObjectKind + case "SCALAR": + *v = TypeDefKindScalar + case "SCALAR_KIND": + *v = TypeDefKindScalarKind + case "STRING": + *v = TypeDefKindString + case "STRING_KIND": + *v = TypeDefKindStringKind + case "VOID": + *v = TypeDefKindVoid + case "VOID_KIND": + *v = TypeDefKindVoidKind + default: + return fmt.Errorf("invalid enum value %q", s) + } + return nil +} - // A graphql input type, used only when representing the core API via TypeDefs. - InputKind TypeDefKind = "INPUT_KIND" +const ( + // A string value. + TypeDefKindStringKind TypeDefKind = "STRING_KIND" + // A string value. + TypeDefKindString TypeDefKind = TypeDefKindStringKind // An integer value. - IntegerKind TypeDefKind = "INTEGER_KIND" + TypeDefKindIntegerKind TypeDefKind = "INTEGER_KIND" + // An integer value. + TypeDefKindInteger TypeDefKind = TypeDefKindIntegerKind - // A named type of functions that can be matched+implemented by other objects+interfaces. - // - // Always paired with an InterfaceTypeDef. - InterfaceKind TypeDefKind = "INTERFACE_KIND" + // A float value. + TypeDefKindFloatKind TypeDefKind = "FLOAT_KIND" + // A float value. + TypeDefKindFloat TypeDefKind = TypeDefKindFloatKind - // A list of values all having the same type. + // A boolean value. + TypeDefKindBooleanKind TypeDefKind = "BOOLEAN_KIND" + // A boolean value. + TypeDefKindBoolean TypeDefKind = TypeDefKindBooleanKind + + // A scalar value of any basic kind. + TypeDefKindScalarKind TypeDefKind = "SCALAR_KIND" + // A scalar value of any basic kind. + TypeDefKindScalar TypeDefKind = TypeDefKindScalarKind + + // Always paired with a ListTypeDef. // + // A list of values all having the same type. + TypeDefKindListKind TypeDefKind = "LIST_KIND" // Always paired with a ListTypeDef. - ListKind TypeDefKind = "LIST_KIND" + // + // A list of values all having the same type. + TypeDefKindList TypeDefKind = TypeDefKindListKind - // A named type defined in the GraphQL schema, with fields and functions. + // Always paired with an ObjectTypeDef. // + // A named type defined in the GraphQL schema, with fields and functions. + TypeDefKindObjectKind TypeDefKind = "OBJECT_KIND" // Always paired with an ObjectTypeDef. - ObjectKind TypeDefKind = "OBJECT_KIND" + // + // A named type defined in the GraphQL schema, with fields and functions. + TypeDefKindObject TypeDefKind = TypeDefKindObjectKind - // A string value. - StringKind TypeDefKind = "STRING_KIND" + // Always paired with an InterfaceTypeDef. + // + // A named type of functions that can be matched+implemented by other objects+interfaces. + TypeDefKindInterfaceKind TypeDefKind = "INTERFACE_KIND" + // Always paired with an InterfaceTypeDef. + // + // A named type of functions that can be matched+implemented by other objects+interfaces. + TypeDefKindInterface TypeDefKind = TypeDefKindInterfaceKind + + // A graphql input type, used only when representing the core API via TypeDefs. + TypeDefKindInputKind TypeDefKind = "INPUT_KIND" + // A graphql input type, used only when representing the core API via TypeDefs. + TypeDefKindInput TypeDefKind = TypeDefKindInputKind // A special kind used to signify that no value is returned. // // This is used for functions that have no return value. The outer TypeDef specifying this Kind is always Optional, as the Void is never actually represented. - VoidKind TypeDefKind = "VOID_KIND" + TypeDefKindVoidKind TypeDefKind = "VOID_KIND" + // A special kind used to signify that no value is returned. + // + // This is used for functions that have no return value. The outer TypeDef specifying this Kind is always Optional, as the Void is never actually represented. + TypeDefKindVoid TypeDefKind = TypeDefKindVoidKind + + // A GraphQL enum type and its values + // + // Always paired with an EnumTypeDef. + TypeDefKindEnumKind TypeDefKind = "ENUM_KIND" + // A GraphQL enum type and its values + // + // Always paired with an EnumTypeDef. + TypeDefKindEnum TypeDefKind = TypeDefKindEnumKind ) type Client struct { @@ -6674,6 +10715,13 @@ func getClientParams() (graphql.Client, *querybuilder.Selection) { httpClient := &http.Client{ Transport: roundTripperFunc(func(r *http.Request) (*http.Response, error) { r.SetBasicAuth(sessionToken, "") + + // detect $TRACEPARENT set by 'dagger run' + r = r.WithContext(fallbackSpanContext(r.Context())) + + // propagate span context via headers (i.e. for Dagger-in-Dagger) + telemetry.Propagator.Inject(r.Context(), propagation.HeaderCarrier(r.Header)) + return dialTransport.RoundTrip(r) }), } @@ -6682,6 +10730,13 @@ func getClientParams() (graphql.Client, *querybuilder.Selection) { return gqlClient, querybuilder.Query() } +func fallbackSpanContext(ctx context.Context) context.Context { + if trace.SpanContextFromContext(ctx).IsValid() { + return ctx + } + return telemetry.Propagator.Extract(ctx, telemetry.NewEnvCarrier(true)) +} + // TODO: pollutes namespace, move to non internal package in dagger.io/dagger type roundTripperFunc func(*http.Request) (*http.Response, error) diff --git a/redis/redis.go b/redis/redis.go index 560cdfc..51d5516 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -8,11 +8,17 @@ package main +import ( + "redis/internal/dagger" +) + type Redis struct { - Port int - Version string - Password *Secret - Cache bool + Port int + Version string + Password *dagger.Secret + Cache bool + CacheDataPath string + Image string } func New( @@ -31,18 +37,32 @@ func New( // The password to use for the Redis server. // //+optional - password *Secret, + password *dagger.Secret, // Enable data persistency by mounting a cache volume. // //+optional //+default=false - cache bool, + cache bool, + + // If cache is enabled define the path where the cache is set. + // + //+optional + //+default="/data/ + cacheDataPath string, + + // The image of the redis server to use. + // + //+optional + //+default="redis" + image string, ) *Redis { return &Redis{ - Port: port, - Version: version, - Password: password, - Cache: cache, + Port: port, + Version: version, + Password: password, + Cache: cache, + CacheDataPath: cacheDataPath, + Image: image, } } diff --git a/redis/server.go b/redis/server.go index aad6136..b559a40 100644 --- a/redis/server.go +++ b/redis/server.go @@ -2,18 +2,19 @@ package main import ( "fmt" + "redis/internal/dagger" "strconv" ) // Server returns a new container running Redis a redis Server. -func (r *Redis) Server() (*Container, error) { +func (r *Redis) Server() (*dagger.Container, error) { ctr := dag. Container(). - From(fmt.Sprintf("bitnami/redis:%s", r.Version)). + From(fmt.Sprintf("%s:%s", r.Image, r.Version)). WithUser("root") - if r.Cache { - ctr = ctr.WithMountedCache("/bitnami/redis/data", dag.CacheVolume("redis-data")) + if r.Cache { + ctr = ctr.WithMountedCache(r.CacheDataPath, dag.CacheVolume("redis-data")) } if r.Password != nil {