Compare commits

..

3 Commits

Author SHA1 Message Date
986a64cbc7 feat(sdk): re-export through lib.rs
this means that you can now use dagger_sdk::connect() instead of
dagger_sdk::client::connect();
2023-02-19 15:24:37 +01:00
2695a10f24 feat(sdk): with return result instead of unwrap 2023-02-19 15:18:25 +01:00
05e1b8bd30 feat(core,sdk): remove unnecessary option returns 2023-02-19 15:00:00 +01:00
26 changed files with 631 additions and 1226 deletions

View File

@@ -5,32 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.9 (2023-02-19)
### New Features
- <csr-id-19ed6c267f779b72430422c463ceed553f6fc618/> re-export through lib.rs
this means that you can now use dagger_sdk::connect() instead of
dagger_sdk::client::connect();
### Commit Statistics
<csr-read-only-do-not-edit/>
- 1 commit contributed to the release.
- 1 commit was understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- re-export through lib.rs ([`19ed6c2`](https://github.com/kjuulh/dagger-rs/commit/19ed6c267f779b72430422c463ceed553f6fc618))
</details>
## v0.2.8 (2023-02-19) ## v0.2.8 (2023-02-19)
### New Features ### New Features

113
Cargo.lock generated
View File

@@ -114,7 +114,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
"dagger-sdk 0.2.2", "dagger-sdk 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"eyre", "eyre",
] ]
@@ -245,7 +245,7 @@ dependencies = [
[[package]] [[package]]
name = "dagger-codegen" name = "dagger-codegen"
version = "0.2.3" version = "0.2.2"
dependencies = [ dependencies = [
"convert_case", "convert_case",
"dagger-core 0.2.2", "dagger-core 0.2.2",
@@ -305,7 +305,7 @@ dependencies = [
[[package]] [[package]]
name = "dagger-rs" name = "dagger-rs"
version = "0.2.9" version = "0.2.8"
dependencies = [ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
@@ -328,6 +328,23 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "dagger-sdk"
version = "0.2.2"
dependencies = [
"base64",
"dagger-core 0.2.2",
"eyre",
"futures",
"genco",
"gql_client",
"pretty_assertions",
"rand",
"serde",
"serde_json",
"tokio",
]
[[package]] [[package]]
name = "dagger-sdk" name = "dagger-sdk"
version = "0.2.2" version = "0.2.2"
@@ -346,90 +363,6 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "dagger-sdk"
version = "0.2.4"
dependencies = [
"base64",
"dagger-core 0.2.2",
"derive_builder",
"eyre",
"futures",
"genco",
"gql_client",
"pretty_assertions",
"rand",
"serde",
"serde_json",
"tokio",
]
[[package]]
name = "darling"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "derive_builder"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
dependencies = [
"derive_builder_macro",
]
[[package]]
name = "derive_builder_core"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "derive_builder_macro"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
dependencies = [
"derive_builder_core",
"syn",
]
[[package]] [[package]]
name = "diff" name = "diff"
version = "0.1.13" version = "0.1.13"
@@ -906,12 +839,6 @@ dependencies = [
"tokio-native-tls", "tokio-native-tls",
] ]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-rs" name = "dagger-rs"
version = "0.2.9" version = "0.2.8"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"
@@ -19,7 +19,7 @@ members = [
] ]
[dependencies] [dependencies]
dagger-codegen = { path = "crates/dagger-codegen", version = "^0.2.3" } dagger-codegen = { path = "crates/dagger-codegen", version = "^0.2.2" }
dagger-core = { path = "crates/dagger-core", version = "^0.2.2" } dagger-core = { path = "crates/dagger-core", version = "^0.2.2" }
clap = "4.1.6" clap = "4.1.6"

View File

@@ -22,7 +22,7 @@ See [dagger-sdk](./crates/dagger-sdk/README.md)
- [x] Deserializer for nested response (bind) - [x] Deserializer for nested response (bind)
- [x] Add codegen to hook into querier - [x] Add codegen to hook into querier
- [x] fix build / release cycle - [x] fix build / release cycle
- [x] general api stabilisation - [ ] general api stabilisation
- [x] document usage - [x] document usage
- [ ] make async variant - [ ] make async variant

View File

@@ -28,7 +28,7 @@ fn main() -> eyre::Result<()> {
} }
} }
fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { fn release(client: Arc<Query>, subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
let src_dir = client.host().directory( let src_dir = client.host().directory(
".".into(), ".".into(),
Some(HostDirectoryOpts { Some(HostDirectoryOpts {

View File

@@ -5,32 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.3 (2023-02-19)
### New Features
- <csr-id-de063eae858eb3335d2558a57ee6a88689635200/> with return result instead of unwrap
- <csr-id-5d667369900a47d3a6015cd3814c240bc5c54436/> remove unnecessary option returns
### Commit Statistics
<csr-read-only-do-not-edit/>
- 2 commits contributed to the release.
- 2 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- with return result instead of unwrap ([`de063ea`](https://github.com/kjuulh/dagger-rs/commit/de063eae858eb3335d2558a57ee6a88689635200))
- remove unnecessary option returns ([`5d66736`](https://github.com/kjuulh/dagger-rs/commit/5d667369900a47d3a6015cd3814c240bc5c54436))
</details>
## v0.2.2 (2023-02-19) ## v0.2.2 (2023-02-19)
### New Features ### New Features
@@ -41,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/> <csr-read-only-do-not-edit/>
- 2 commits contributed to the release. - 1 commit contributed to the release.
- 1 commit was understood as [conventional](https://www.conventionalcommits.org). - 1 commit was understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages - 0 issues like '(#ID)' were seen in commit messages
@@ -52,7 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary> <details><summary>view details</summary>
* **Uncategorized** * **Uncategorized**
- Release dagger-core v0.2.2, dagger-codegen v0.2.2, dagger-rs v0.2.8 ([`1638f15`](https://github.com/kjuulh/dagger-rs/commit/1638f15fba9d16512e8452f87b908d6dce417cd9))
- update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438)) - update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438))
</details> </details>

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-codegen" name = "dagger-codegen"
version = "0.2.3" version = "0.2.2"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"

View File

@@ -6,8 +6,8 @@ use eyre::ContextCompat;
use crate::utility::OptionExt; use crate::utility::OptionExt;
pub trait FormatTypeFuncs { pub trait FormatTypeFuncs {
fn format_kind_list(&self, representation: &str, input: bool, immutable: bool) -> String; fn format_kind_list(&self, representation: &str) -> String;
fn format_kind_scalar_string(&self, representation: &str, input: bool) -> String; fn format_kind_scalar_string(&self, representation: &str) -> String;
fn format_kind_scalar_int(&self, representation: &str) -> String; fn format_kind_scalar_int(&self, representation: &str) -> String;
fn format_kind_scalar_float(&self, representation: &str) -> String; fn format_kind_scalar_float(&self, representation: &str) -> String;
fn format_kind_scalar_boolean(&self, representation: &str) -> String; fn format_kind_scalar_boolean(&self, representation: &str) -> String;
@@ -36,18 +36,14 @@ impl CommonFunctions {
} }
pub fn format_input_type(&self, t: &TypeRef) -> String { pub fn format_input_type(&self, t: &TypeRef) -> String {
self.format_type(t, true, false) self.format_type(t, true)
} }
pub fn format_output_type(&self, t: &TypeRef) -> String { pub fn format_output_type(&self, t: &TypeRef) -> String {
self.format_type(t, false, false) self.format_type(t, false)
} }
pub fn format_immutable_input_type(&self, t: &TypeRef) -> String { fn format_type(&self, t: &TypeRef, input: bool) -> String {
self.format_type(t, true, true)
}
fn format_type(&self, t: &TypeRef, input: bool, immutable: bool) -> String {
let mut representation = String::new(); let mut representation = String::new();
let mut r = Some(t.clone()); let mut r = Some(t.clone());
while r.is_some() { while r.is_some() {
@@ -61,14 +57,9 @@ impl CommonFunctions {
Scalar::Float => self Scalar::Float => self
.format_type_funcs .format_type_funcs
.format_kind_scalar_float(&mut representation), .format_kind_scalar_float(&mut representation),
Scalar::String => { Scalar::String => self
if immutable { .format_type_funcs
"&'a str".into() .format_kind_scalar_string(&mut representation),
} else {
self.format_type_funcs
.format_kind_scalar_string(&mut representation, input)
}
}
Scalar::Boolean => self Scalar::Boolean => self
.format_type_funcs .format_type_funcs
.format_kind_scalar_boolean(&mut representation), .format_kind_scalar_boolean(&mut representation),
@@ -96,15 +87,12 @@ impl CommonFunctions {
.as_ref() .as_ref()
.map(|t| t.clone()) .map(|t| t.clone())
.map(|t| *t) .map(|t| *t)
.map(|t| self.format_type(&t, input, immutable)) .map(|t| self.format_type(&t, input))
.context("could not get inner type of list") .context("could not get inner type of list")
.unwrap(); .unwrap();
representation = self.format_type_funcs.format_kind_list( representation =
&mut inner_type, self.format_type_funcs.format_kind_list(&mut inner_type);
input,
immutable,
);
return representation; return representation;
} }

View File

@@ -5,17 +5,13 @@ use super::functions::format_name;
pub struct FormatTypeFunc; pub struct FormatTypeFunc;
impl FormatTypeFuncs for FormatTypeFunc { impl FormatTypeFuncs for FormatTypeFunc {
fn format_kind_list(&self, representation: &str, _input: bool, _immutable: bool) -> String { fn format_kind_list(&self, representation: &str) -> String {
format!("Vec<{}>", representation) format!("Vec<{}>", representation)
} }
fn format_kind_scalar_string(&self, representation: &str, input: bool) -> String { fn format_kind_scalar_string(&self, representation: &str) -> String {
let mut rep = representation.to_string(); let mut rep = representation.to_string();
if input { rep.push_str("String");
rep.push_str("impl Into<String>");
} else {
rep.push_str("String");
}
rep rep
} }

View File

@@ -5,8 +5,8 @@ use genco::quote;
use genco::tokens::quoted; use genco::tokens::quoted;
use crate::functions::{ use crate::functions::{
type_field_has_optional, type_ref_is_list, type_ref_is_list_of_objects, type_ref_is_object, type_field_has_optional, type_ref_is_list_of_objects, type_ref_is_object, type_ref_is_optional,
type_ref_is_optional, type_ref_is_scalar, CommonFunctions, Scalar, CommonFunctions,
}; };
use crate::utility::OptionExt; use crate::utility::OptionExt;
@@ -39,44 +39,18 @@ pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
.pipe(|t| &t.type_ref) .pipe(|t| &t.type_ref)
.pipe(|t| render_output_type(funcs, t)); .pipe(|t| render_output_type(funcs, t));
if let Some((args, true)) = args { Some(quote! {
let required_args = format_required_function_args(funcs, field); $(signature)(
Some(quote! { $(args)
$(&signature)( ) -> $(output_type) {
$(required_args) let mut query = self.selection.select($(quoted(field.name.as_ref())));
) -> $(output_type.as_ref()) {
let mut query = self.selection.select($(quoted(field.name.as_ref())));
$(render_required_args(funcs, field)) $(render_required_args(funcs, field))
$(render_optional_args(funcs, field))
$(render_execution(funcs, field)) $(render_execution(funcs, field))
} }
})
$(&signature)_opts(
$args
) -> $(output_type) {
let mut query = self.selection.select($(quoted(field.name.as_ref())));
$(render_required_args(funcs, field))
$(render_optional_args(funcs, field))
$(render_execution(funcs, field))
}
})
} else {
Some(quote! {
$(signature)(
$(if let Some((args, _)) = args => $args)
) -> $(output_type) {
let mut query = self.selection.select($(quoted(field.name.as_ref())));
$(render_required_args(funcs, field))
$(render_optional_args(funcs, field))
$(render_execution(funcs, field))
}
})
}
} }
fn render_required_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> { fn render_required_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
@@ -92,40 +66,6 @@ fn render_required_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Opt
let n = format_struct_name(&s.input_value.name); let n = format_struct_name(&s.input_value.name);
let name = &s.input_value.name; let name = &s.input_value.name;
if type_ref_is_scalar(&s.input_value.type_) {
if let Scalar::String =
Scalar::from(&*s.input_value.type_.of_type.as_ref().unwrap().clone())
{
return Some(quote! {
query = query.arg($(quoted(name)), $(&n).into());
});
}
}
if type_ref_is_list(&s.input_value.type_) {
let inner = *s
.input_value
.type_
.of_type
.as_ref()
.unwrap()
.clone()
.of_type
.as_ref()
.unwrap()
.clone();
println!("type: {:?}", inner);
if type_ref_is_scalar(&inner) {
if let Scalar::String =
Scalar::from(&*inner.of_type.as_ref().unwrap().clone())
{
return Some(quote! {
query = query.arg($(quoted(name)), $(&n).into_iter().map(|i| i.into()).collect::<Vec<String>>());
});
}
}
}
Some(quote! { Some(quote! {
query = query.arg($(quoted(name)), $(n)); query = query.arg($(quoted(name)), $(n));
}) })
@@ -171,7 +111,9 @@ fn render_optional_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Opt
} }
let required_args = quote! { let required_args = quote! {
$(for arg in args join ($['\r']) => $arg) if let Some(opts) = opts {
$(for arg in args join ($['\r']) => $arg)
}
}; };
Some(required_args) Some(required_args)
@@ -239,10 +181,7 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
} }
} }
fn format_function_args( fn format_function_args(funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
funcs: &CommonFunctions,
field: &FullTypeFields,
) -> Option<(rust::Tokens, bool)> {
if let Some(args) = field.args.as_ref() { if let Some(args) = field.args.as_ref() {
let args = args let args = args
.into_iter() .into_iter()
@@ -268,51 +207,14 @@ fn format_function_args(
}; };
if type_field_has_optional(field) { if type_field_has_optional(field) {
Some(( Some(quote! {
quote! { $(required_args)
$(required_args) opts: Option<$(field_options_struct_name(field))>
opts: $(field_options_struct_name(field)) })
},
true,
))
} else { } else {
Some((required_args, false)) Some(required_args)
} }
} else { } else {
None None
} }
} }
fn format_required_function_args(
funcs: &CommonFunctions,
field: &FullTypeFields,
) -> Option<rust::Tokens> {
if let Some(args) = field.args.as_ref() {
let args = args
.into_iter()
.map(|a| {
a.as_ref().and_then(|s| {
if type_ref_is_optional(&s.input_value.type_) {
return None;
}
let t = funcs.format_input_type(&s.input_value.type_);
let n = format_struct_name(&s.input_value.name);
Some(quote! {
$(n): $(t),
})
})
})
.flatten()
.collect::<Vec<_>>();
let required_args = quote! {
&self,
$(for arg in args join ($['\r']) => $arg)
};
Some(required_args)
} else {
None
}
}

View File

@@ -28,7 +28,7 @@ pub fn render_enum(t: &FullType) -> eyre::Result<rust::Tokens> {
let serialize = rust::import("serde", "Serialize"); let serialize = rust::import("serde", "Serialize");
Ok(quote! { Ok(quote! {
#[derive($serialize, Clone, PartialEq, Debug)] #[derive($serialize)]
pub enum $(t.name.as_ref()) { pub enum $(t.name.as_ref()) {
$(render_enum_values(t)) $(render_enum_values(t))
} }

View File

@@ -9,7 +9,7 @@ pub fn render_input(funcs: &CommonFunctions, t: &FullType) -> eyre::Result<rust:
let deserialize = rust::import("serde", "Deserialize"); let deserialize = rust::import("serde", "Deserialize");
let serialize = rust::import("serde", "Serialize"); let serialize = rust::import("serde", "Serialize");
Ok(quote! { Ok(quote! {
#[derive($serialize, $deserialize, Debug, PartialEq, Clone)] #[derive($serialize, $deserialize)]
pub struct $(format_name(t.name.as_ref().unwrap())) { pub struct $(format_name(t.name.as_ref().unwrap())) {
$(render_input_fields(funcs, t.input_fields.as_ref().unwrap_or(&Vec::new()) )) $(render_input_fields(funcs, t.input_fields.as_ref().unwrap_or(&Vec::new()) ))
} }
@@ -33,6 +33,6 @@ pub fn render_input_fields(
pub fn render_input_field(funcs: &CommonFunctions, field: &FullTypeInputFields) -> rust::Tokens { pub fn render_input_field(funcs: &CommonFunctions, field: &FullTypeInputFields) -> rust::Tokens {
quote! { quote! {
pub $(format_struct_name(&field.input_value.name)): $(funcs.format_output_type(&field.input_value.type_)), pub $(format_struct_name(&field.input_value.name)): $(funcs.format_input_type(&field.input_value.type_)),
} }
} }

View File

@@ -1,7 +1,6 @@
use dagger_core::introspection::{FullType, FullTypeFields, FullTypeFieldsArgs}; use dagger_core::introspection::{FullType, FullTypeFields, FullTypeFieldsArgs};
use genco::prelude::rust; use genco::prelude::rust;
use genco::quote; use genco::quote;
use itertools::Itertools;
use crate::functions::{type_ref_is_optional, CommonFunctions}; use crate::functions::{type_ref_is_optional, CommonFunctions};
use crate::rust::functions::{ use crate::rust::functions::{
@@ -62,15 +61,9 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
.pipe(|t| render_optional_field_args(funcs, t)) .pipe(|t| render_optional_field_args(funcs, t))
.flatten(); .flatten();
let builder = rust::import("derive_builder", "Builder"); if let Some(fields) = fields {
let _phantom_data = rust::import("std::marker", "PhantomData");
if let Some((fields, contains_lifetime)) = fields {
Some(quote! { Some(quote! {
#[derive($builder, Debug, PartialEq)] pub struct $output_type {
pub struct $output_type$(if contains_lifetime => <'a>) {
//#[builder(default, setter(skip))]
//pub marker: $(phantom_data)<&'a ()>,
$fields $fields
} }
}) })
@@ -82,28 +75,19 @@ fn render_optional_arg(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
fn render_optional_field_args( fn render_optional_field_args(
funcs: &CommonFunctions, funcs: &CommonFunctions,
args: &Vec<&FullTypeFieldsArgs>, args: &Vec<&FullTypeFieldsArgs>,
) -> Option<(rust::Tokens, bool)> { ) -> Option<rust::Tokens> {
if args.len() == 0 { if args.len() == 0 {
return None; return None;
} }
let mut contains_lifetime = false;
let rendered_args = args.into_iter().map(|a| &a.input_value).map(|a| { let rendered_args = args.into_iter().map(|a| &a.input_value).map(|a| {
let type_ = funcs.format_immutable_input_type(&a.type_);
if type_.contains("str") {
contains_lifetime = true;
}
quote! { quote! {
#[builder(setter(into, strip_option))] pub $(format_struct_name(&a.name)): Option<$(funcs.format_output_type(&a.type_))>,
pub $(format_struct_name(&a.name)): Option<$(type_)>,
} }
}); });
Some(( Some(quote! {
quote! { $(for arg in rendered_args join ($['\r']) => $arg)
$(for arg in rendered_args join ($['\r']) => $arg) })
},
contains_lifetime,
))
} }
fn render_functions(funcs: &CommonFunctions, fields: &Vec<FullTypeFields>) -> Option<rust::Tokens> { fn render_functions(funcs: &CommonFunctions, fields: &Vec<FullTypeFields>) -> Option<rust::Tokens> {

View File

@@ -10,7 +10,7 @@ pub fn render_scalar(t: &FullType) -> eyre::Result<rust::Tokens> {
let serialize = rust::import("serde", "Serialize"); let serialize = rust::import("serde", "Serialize");
Ok(quote! { Ok(quote! {
#[derive($serialize, $deserialize, PartialEq, Debug, Clone)] #[derive($serialize, $deserialize)]
pub struct $(t.name.pipe(|n|format_name(n)))(String); pub struct $(t.name.pipe(|n|format_name(n)))(String);
}) })
} }

View File

@@ -5,61 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v0.2.4 (2023-02-19)
### Bug Fixes
- <csr-id-7d04ab1240e497e7804fed23a378d28c78f50a0a/> readme dagger-rs -> dagger-sdk
### Commit Statistics
<csr-read-only-do-not-edit/>
- 1 commit contributed to the release.
- 1 commit was understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- readme dagger-rs -> dagger-sdk ([`7d04ab1`](https://github.com/kjuulh/dagger-rs/commit/7d04ab1240e497e7804fed23a378d28c78f50a0a))
</details>
## v0.2.3 (2023-02-19)
### New Features
- <csr-id-19ed6c267f779b72430422c463ceed553f6fc618/> re-export through lib.rs
this means that you can now use dagger_sdk::connect() instead of
dagger_sdk::client::connect();
- <csr-id-de063eae858eb3335d2558a57ee6a88689635200/> with return result instead of unwrap
- <csr-id-5d667369900a47d3a6015cd3814c240bc5c54436/> remove unnecessary option returns
### Commit Statistics
<csr-read-only-do-not-edit/>
- 4 commits contributed to the release.
- 3 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages
### Commit Details
<csr-read-only-do-not-edit/>
<details><summary>view details</summary>
* **Uncategorized**
- Release dagger-sdk v0.2.3, dagger-codegen v0.2.3, dagger-rs v0.2.9 ([`9235030`](https://github.com/kjuulh/dagger-rs/commit/92350306b3f0da40b4fc6dcaffcd90b891e83f70))
- re-export through lib.rs ([`19ed6c2`](https://github.com/kjuulh/dagger-rs/commit/19ed6c267f779b72430422c463ceed553f6fc618))
- with return result instead of unwrap ([`de063ea`](https://github.com/kjuulh/dagger-rs/commit/de063eae858eb3335d2558a57ee6a88689635200))
- remove unnecessary option returns ([`5d66736`](https://github.com/kjuulh/dagger-rs/commit/5d667369900a47d3a6015cd3814c240bc5c54436))
</details>
## v0.2.2 (2023-02-19) ## v0.2.2 (2023-02-19)
### New Features ### New Features
@@ -74,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/> <csr-read-only-do-not-edit/>
- 4 commits contributed to the release. - 3 commits contributed to the release.
- 2 commits were understood as [conventional](https://www.conventionalcommits.org). - 2 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' were seen in commit messages - 0 issues like '(#ID)' were seen in commit messages
@@ -85,7 +30,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary> <details><summary>view details</summary>
* **Uncategorized** * **Uncategorized**
- Release dagger-sdk v0.2.2 ([`e921ba1`](https://github.com/kjuulh/dagger-rs/commit/e921ba13638987ccf5beaa48c4be9be5fd879bd0))
- Release dagger-core v0.2.2, dagger-codegen v0.2.2, dagger-rs v0.2.8 ([`1638f15`](https://github.com/kjuulh/dagger-rs/commit/1638f15fba9d16512e8452f87b908d6dce417cd9)) - Release dagger-core v0.2.2, dagger-codegen v0.2.2, dagger-rs v0.2.8 ([`1638f15`](https://github.com/kjuulh/dagger-rs/commit/1638f15fba9d16512e8452f87b908d6dce417cd9))
- fixed fmt errors ([`10bc6f3`](https://github.com/kjuulh/dagger-rs/commit/10bc6f3846b65cc82c2fb343d8cfe921784bef1b)) - fixed fmt errors ([`10bc6f3`](https://github.com/kjuulh/dagger-rs/commit/10bc6f3846b65cc82c2fb343d8cfe921784bef1b))
- update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438)) - update to dagger v0.3.12 ([`6e5f407`](https://github.com/kjuulh/dagger-rs/commit/6e5f4074329ab0462445b31d4153f8497c483438))

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dagger-sdk" name = "dagger-sdk"
version = "0.2.4" version = "0.2.2"
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
license-file = "LICENSE.MIT" license-file = "LICENSE.MIT"
@@ -11,18 +11,17 @@ publish = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
dagger-core = { path = "../dagger-core", version = "^0.2.2" }
base64 = "0.21.0" base64 = "0.21.0"
dagger-core = { path = "../dagger-core", version = "^0.2.2" }
eyre = "0.6.8" eyre = "0.6.8"
futures = "0.3.26" futures = "0.3.26"
genco = "0.17.3"
gql_client = "1.0.7" gql_client = "1.0.7"
pretty_assertions = "1.3.0"
serde = { version = "1.0.152", features = ["derive"] } serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93" serde_json = "1.0.93"
tokio = { version = "1.25.0", features = ["full"] } tokio = { version = "1.25.0", features = ["full"] }
derive_builder = "0.12.0"
[dev-dependencies] [dev-dependencies]
pretty_assertions = "1.3.0"
rand = "0.8.5" rand = "0.8.5"
genco = "0.17.3"

View File

@@ -1,4 +1,4 @@
# dagger-sdk # dagger-rs
A dagger sdk written in rust for rust. A dagger sdk written in rust for rust.
@@ -19,20 +19,20 @@ The examples match the folder name in each directory in examples
Simply install like: Simply install like:
```bash ```bash
cargo add dagger-sdk cargo install dagger-sdk
``` ```
### Usage ### Usage
```rust ```rust
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::client::connect()?;
let version = client let version = client
.container(None) .container(None)
.from("golang:1.19".into()) .from("golang:1.19".into())
.with_exec(vec!["go".into(), "version".into()], None) .with_exec(vec!["go".into(), "version".into()], None)
.stdout()?; .stdout();
println!("Hello from Dagger and {}", version.trim()); println!("Hello from Dagger and {}", version.trim());

View File

@@ -3,32 +3,40 @@ use dagger_sdk::HostDirectoryOpts;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory(
"examples/build-the-application/app", "examples/build-the-application/app".into(),
HostDirectoryOpts { Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules".into(), "ci/".into()]), exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None, include: None,
}, }),
); );
let source = client let source = client
.container() .container(None)
.from("node:16") .from("node:16".into())
.with_mounted_directory("/src", host_source_dir.id()?); .with_mounted_directory("/src".into(), host_source_dir.id()?);
let runner = source let runner = source
.with_workdir("/src") .with_workdir("/src".into())
.with_exec(vec!["npm", "install"]); .with_exec(vec!["npm".into(), "install".into()], None);
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]); let test = runner.with_exec(
vec![
"npm".into(),
"test".into(),
"--".into(),
"--watchAll=false".into(),
],
None,
);
let build_dir = test let build_dir = test
.with_exec(vec!["npm", "run", "build"]) .with_exec(vec!["npm".into(), "run".into(), "build".into()], None)
.directory("./build"); .directory("./build".into());
let _ = build_dir.export("./build"); let _ = build_dir.export("./build".into());
let entries = build_dir.entries(); let entries = build_dir.entries(None);
println!("build dir contents: \n {:?}", entries); println!("build dir contents: \n {:?}", entries);

View File

@@ -1,40 +1,53 @@
use dagger_sdk::HostDirectoryOpts;
use rand::Rng; use rand::Rng;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory(
"./examples/caching/app", "./examples/caching/app".into(),
dagger_sdk::HostDirectoryOptsBuilder::default() Some(HostDirectoryOpts {
.exclude(vec!["node_modules", "ci/"]) exclude: Some(vec!["node_modules".into(), "ci/".into()]),
.build()?, include: None,
}),
); );
let node_cache = client.cache_volume("node").id()?; let node_cache = client.cache_volume("node".into()).id()?;
let source = client let source = client
.container() .container(None)
.from("node:16") .from("node:16".into())
.with_mounted_directory("/src", host_source_dir.id()?) .with_mounted_directory("/src".into(), host_source_dir.id()?)
.with_mounted_cache("/src/node_modules", node_cache); .with_mounted_cache("/src/node_modules".into(), node_cache, None);
let runner = source let runner = source
.with_workdir("/src") .with_workdir("/src".into())
.with_exec(vec!["npm", "install"]); .with_exec(vec!["npm".into(), "install".into()], None);
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]); let test = runner.with_exec(
vec![
"npm".into(),
"test".into(),
"--".into(),
"--watchAll=false".into(),
],
None,
);
let build_dir = test let build_dir = test
.with_exec(vec!["npm", "run", "build"]) .with_exec(vec!["npm".into(), "run".into(), "build".into()], None)
.directory("./build"); .directory("./build".into());
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let ref_ = client let ref_ = client
.container() .container(None)
.from("nginx") .from("nginx".into())
.with_directory("/usr/share/nginx/html", build_dir.id()?) .with_directory("/usr/share/nginx/html".into(), build_dir.id()?, None)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?; .publish(
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
None,
)?;
println!("published image to: {}", ref_); println!("published image to: {}", ref_);

View File

@@ -7,12 +7,15 @@ fn main() -> eyre::Result<()> {
let context_dir = client let context_dir = client
.host() .host()
.directory("./examples/existing-dockerfile/app"); .directory("./examples/existing-dockerfile/app".into(), None);
let ref_ = client let ref_ = client
.container() .container(None)
.build(context_dir.id()?) .build(context_dir.id()?, None)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?; .publish(
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
None,
)?;
println!("published image to: {}", ref_); println!("published image to: {}", ref_);

View File

@@ -2,9 +2,9 @@ fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let version = client let version = client
.container() .container(None)
.from("golang:1.19") .from("golang:1.19".into())
.with_exec(vec!["go", "version".into()]) .with_exec(vec!["go".into(), "version".into()], None)
.stdout()?; .stdout()?;
println!("Hello from Dagger and {}", version.trim()); println!("Hello from Dagger and {}", version.trim());

View File

@@ -4,36 +4,47 @@ use rand::Rng;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory(
"examples/publish-the-application/app", "examples/publish-the-application/app".into(),
HostDirectoryOpts { Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]), exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None, include: None,
}, }),
); );
let source = client let source = client
.container() .container(None)
.from("node:16") .from("node:16".into())
.with_mounted_directory("/src", host_source_dir.id()?); .with_mounted_directory("/src".into(), host_source_dir.id()?);
let runner = source let runner = source
.with_workdir("/src") .with_workdir("/src".into())
.with_exec(vec!["npm", "install"]); .with_exec(vec!["npm".into(), "install".into()], None);
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]); let test = runner.with_exec(
vec![
"npm".into(),
"test".into(),
"--".into(),
"--watchAll=false".into(),
],
None,
);
let build_dir = test let build_dir = test
.with_exec(vec!["npm", "run", "build"]) .with_exec(vec!["npm".into(), "run".into(), "build".into()], None)
.directory("./build"); .directory("./build".into());
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let ref_ = client let ref_ = client
.container() .container(None)
.from("nginx") .from("nginx".into())
.with_directory("/usr/share/nginx/html", build_dir.id()?) .with_directory("/usr/share/nginx/html".into(), build_dir.id()?, None)
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?; .publish(
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
None,
)?;
println!("published image to: {}", ref_); println!("published image to: {}", ref_);

View File

@@ -5,40 +5,52 @@ fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let output = "examples/publish-the-application/app/build"; let output = "examples/publish-the-application/app/build";
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory(
"examples/publish-the-application/app", "examples/publish-the-application/app".into(),
HostDirectoryOpts { Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]), exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None, include: None,
}, }),
); );
let source = client let source = client
.container() .container(None)
.from("node:16") .from("node:16".into())
.with_mounted_directory("/src", host_source_dir.id()?); .with_mounted_directory("/src".into(), host_source_dir.id()?);
let runner = source let runner = source
.with_workdir("/src") .with_workdir("/src".into())
.with_exec(vec!["npm", "install"]); .with_exec(vec!["npm".into(), "install".into()], None);
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]); let test = runner.with_exec(
vec![
"npm".into(),
"test".into(),
"--".into(),
"--watchAll=false".into(),
],
None,
);
let _ = test let _ = test
.with_exec(vec!["npm", "run", "build"]) .with_exec(vec!["npm".into(), "run".into(), "build".into()], None)
.directory("./build") .directory("./build".into())
.export(output); .export(output.into());
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let ref_ = client let ref_ = client
.container() .container(None)
.from("nginx") .from("nginx".into())
.with_directory( .with_directory(
"/usr/share/nginx/html", "/usr/share/nginx/html".into(),
client.host().directory(output).id()?, client.host().directory(output.into(), None).id()?,
None,
) )
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?; .publish(
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
None,
)?;
println!("published image to: {}", ref_); println!("published image to: {}", ref_);

View File

@@ -3,25 +3,33 @@ use dagger_sdk::HostDirectoryOpts;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect()?; let client = dagger_sdk::connect()?;
let host_source_dir = client.host().directory_opts( let host_source_dir = client.host().directory(
"examples/test-the-application/app", "examples/test-the-application/app".into(),
HostDirectoryOpts { Some(HostDirectoryOpts {
exclude: Some(vec!["node_modules", "ci/"]), exclude: Some(vec!["node_modules".into(), "ci/".into()]),
include: None, include: None,
}, }),
); );
let source = client let source = client
.container() .container(None)
.from("node:16") .from("node:16".into())
.with_mounted_directory("/src", host_source_dir.id()?); .with_mounted_directory("/src".into(), host_source_dir.id()?);
let runner = source let runner = source
.with_workdir("/src") .with_workdir("/src".into())
.with_exec(vec!["npm", "install"]); .with_exec(vec!["npm".into(), "install".into()], None);
let out = runner let out = runner
.with_exec(vec!["npm", "test", "--", "--watchAll=false"]) .with_exec(
vec![
"npm".into(),
"test".into(),
"--".into(),
"--watchAll=false".into(),
],
None,
)
.stderr()?; .stderr()?;
println!("{}", out); println!("{}", out);

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,19 @@
use dagger_sdk::{connect, ContainerExecOptsBuilder}; use dagger_sdk::{connect, ContainerExecOpts};
#[test] #[test]
fn test_example_container() { fn test_example_container() {
let client = connect().unwrap(); let client = connect().unwrap();
let alpine = client.container().from("alpine:3.16.2"); let alpine = client.container(None).from("alpine:3.16.2".into());
let out = alpine let out = alpine
.exec_opts( .exec(Some(ContainerExecOpts {
ContainerExecOptsBuilder::default() args: Some(vec!["cat".into(), "/etc/alpine-release".into()]),
.args(vec!["cat", "/etc/alpine-release"]) stdin: None,
.build() redirect_stdout: None,
.unwrap(), redirect_stderr: None,
) experimental_privileged_nesting: None,
}))
.stdout() .stdout()
.unwrap(); .unwrap();