From 496a687bc34f7c58cc86df60c183be741b0b8a9c Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 30 Jan 2023 22:21:16 +0100 Subject: [PATCH] add fields --- Cargo.lock | 5 +- Cargo.toml | 1 + crates/dagger-codegen/Cargo.toml | 1 - crates/dagger-codegen/src/codegen.rs | 4 +- .../src/handlers/enumeration.rs | 2 +- crates/dagger-codegen/src/handlers/fields.rs | 99 +- crates/dagger-codegen/src/handlers/input.rs | 8 +- .../src/handlers/input_field.rs | 2 +- crates/dagger-codegen/src/handlers/mod.rs | 4 +- crates/dagger-codegen/src/handlers/object.rs | 14 +- crates/dagger-codegen/src/handlers/scalar.rs | 2 +- .../dagger-codegen/src/handlers/type_ref.rs | 2 +- crates/dagger-codegen/src/handlers/utility.rs | 30 +- crates/dagger-codegen/src/predicates.rs | 16 +- crates/dagger-core/Cargo.toml | 1 + crates/dagger-core/src/introspection.rs | 299 ++++ crates/dagger-core/src/lib.rs | 2 + crates/dagger-sdk/src/gen.rs | 1269 +++++++++-------- src/schema.rs | 2 +- src/session.rs | 4 +- 20 files changed, 1133 insertions(+), 634 deletions(-) create mode 100644 crates/dagger-core/src/introspection.rs diff --git a/Cargo.lock b/Cargo.lock index 1dea011..c5c0a6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,6 @@ dependencies = [ "dagger-core", "eyre", "genco", - "graphql-introspection-query", "itertools", "pretty_assertions", "serde", @@ -200,6 +199,9 @@ dependencies = [ [[package]] name = "dagger-core" version = "0.1.0" +dependencies = [ + "serde", +] [[package]] name = "dagger-rs" @@ -207,6 +209,7 @@ version = "0.1.2" dependencies = [ "clap", "dagger-codegen", + "dagger-core", "dirs", "eyre", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 418bf96..86f77e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = ["crates/dagger-codegen", "crates/dagger-sdk", "crates/dagger-core"] [dependencies] dagger-codegen = { path = "crates/dagger-codegen" } +dagger-core = { path = "crates/dagger-core" } clap = "4.1.4" dirs = "4.0.0" diff --git a/crates/dagger-codegen/Cargo.toml b/crates/dagger-codegen/Cargo.toml index b5e0531..dc25151 100644 --- a/crates/dagger-codegen/Cargo.toml +++ b/crates/dagger-codegen/Cargo.toml @@ -11,7 +11,6 @@ dagger-core = { path = "../dagger-core" } eyre = "0.6.8" genco = "0.17.3" -graphql-introspection-query = "0.2.0" itertools = "0.10.5" pretty_assertions = "1.3.0" serde = { version = "1.0.152", features = ["derive"] } diff --git a/crates/dagger-codegen/src/codegen.rs b/crates/dagger-codegen/src/codegen.rs index 4e1947a..e701c78 100644 --- a/crates/dagger-codegen/src/codegen.rs +++ b/crates/dagger-codegen/src/codegen.rs @@ -3,10 +3,8 @@ use std::{ sync::Arc, }; +use dagger_core::introspection::{FullType, IntrospectionResponse, Schema}; use genco::{fmt, prelude::rust, prelude::*, quote}; -use graphql_introspection_query::introspection_response::{ - FullType, IntrospectionResponse, Schema, -}; use crate::handlers::{ enumeration::Enumeration, input::Input, object::Object, scalar::Scalar, DynHandler, Handlers, diff --git a/crates/dagger-codegen/src/handlers/enumeration.rs b/crates/dagger-codegen/src/handlers/enumeration.rs index deb777b..ee2a7b8 100644 --- a/crates/dagger-codegen/src/handlers/enumeration.rs +++ b/crates/dagger-codegen/src/handlers/enumeration.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::FullType; use genco::{prelude::rust, quote}; -use graphql_introspection_query::introspection_response::FullType; use crate::predicates::is_enum_type; diff --git a/crates/dagger-codegen/src/handlers/fields.rs b/crates/dagger-codegen/src/handlers/fields.rs index 42b3342..0136235 100644 --- a/crates/dagger-codegen/src/handlers/fields.rs +++ b/crates/dagger-codegen/src/handlers/fields.rs @@ -1,10 +1,10 @@ use convert_case::{Case, Casing}; +use dagger_core::introspection::{FullTypeFields, FullTypeFieldsArgs}; use genco::{prelude::rust, quote}; -use graphql_introspection_query::introspection_response::FullTypeFields; use super::{ - type_ref, - utility::{render_description, render_description_from_field}, + type_ref::{self, render_type_ref}, + utility::{render_description_from_field, render_description_from_input_value}, }; pub fn render_fields(fields: &Vec) -> eyre::Result> { @@ -13,13 +13,38 @@ pub fn render_fields(fields: &Vec) -> eyre::Result render_args(a), + None => None, + }; - collected_fields.push(quote! { - $(if description.is_some() => $description) - pub fn $name(&self) -> $output { + let mut tkns = rust::Tokens::new(); + if let Some(desc) = &description { + tkns.append(desc); + tkns.push() + } + + if let Some(args) = args.as_ref() { + if let Some(desc) = args.description.as_ref() { + tkns.append("/// # Arguments"); + tkns.push(); + tkns.append("///"); + tkns.push(); + tkns.append(desc); + tkns.push(); + } + } + + tkns.append(quote! { + pub fn $name( + &self, + $(if let Some(args) = args.as_ref() => $(&args.args)) + ) -> $output { todo!() } - }) + }); + + collected_fields.push(tkns); } Ok(Some(quote! { @@ -27,6 +52,66 @@ pub fn render_fields(fields: &Vec) -> eyre::Result, + type_: rust::Tokens, +} + +struct CollectedArgs { + description: Option, + args: rust::Tokens, +} + +fn render_args(args: &[Option]) -> Option { + let mut collected_args: Vec = vec![]; + + for arg in args { + if let Some(arg) = arg.as_ref().map(|a| &a.input_value) { + let name = arg.name.clone(); + let description = render_description_from_input_value(&arg, &name); + let t = render_type_ref(&arg.type_).unwrap(); + + collected_args.push(Arg { + name, + description, + type_: t, + }) + } + } + + if collected_args.len() > 0 { + let mut collected_arg = CollectedArgs { + description: Some(rust::Tokens::new()), + args: rust::Tokens::new(), + }; + + for arg in collected_args { + if let Some(desc) = arg.description { + if let Some(inner_desc) = collected_arg.description.as_mut() { + inner_desc.append(desc); + inner_desc.push(); + } + } + + collected_arg.args.append(quote! { + $(arg.name.to_case(Case::Snake)): $(arg.type_), + }); + collected_arg.args.push(); + } + + if let Some(desc) = collected_arg.description.as_ref() { + if desc.is_empty() { + collected_arg.description = None; + } + } + + Some(collected_arg) + } else { + None + } +} + pub fn render_field_output(field: &FullTypeFields) -> eyre::Result { let inner = &field.type_.as_ref().unwrap(); type_ref::render_type_ref(&inner.type_ref) diff --git a/crates/dagger-codegen/src/handlers/input.rs b/crates/dagger-codegen/src/handlers/input.rs index 07e7877..63e9054 100644 --- a/crates/dagger-codegen/src/handlers/input.rs +++ b/crates/dagger-codegen/src/handlers/input.rs @@ -1,6 +1,6 @@ +use dagger_core::introspection::FullType; use genco::prelude::rust; use genco::prelude::*; -use graphql_introspection_query::introspection_response::FullType; use crate::predicates::is_input_object_type; @@ -42,7 +42,7 @@ impl Handler for Input { #[cfg(test)] mod tests { - use graphql_introspection_query::introspection_response::{ + use dagger_core::introspection::{ FullType, FullTypeInputFields, InputValue, TypeRef, __TypeKind, }; use pretty_assertions::assert_eq; @@ -101,9 +101,9 @@ mod tests { let expected = r#"use dagger_core::Input; pub struct BuildArg { - pub name: Option + pub name: Option, - pub value: Option + pub value: Option, } impl Input for BuildArg {} diff --git a/crates/dagger-codegen/src/handlers/input_field.rs b/crates/dagger-codegen/src/handlers/input_field.rs index d7b49e9..2bd7ccd 100644 --- a/crates/dagger-codegen/src/handlers/input_field.rs +++ b/crates/dagger-codegen/src/handlers/input_field.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::FullTypeInputFields; use genco::{prelude::rust, quote}; -use graphql_introspection_query::introspection_response::FullTypeInputFields; use super::type_ref; diff --git a/crates/dagger-codegen/src/handlers/mod.rs b/crates/dagger-codegen/src/handlers/mod.rs index 8da7a02..a584e87 100644 --- a/crates/dagger-codegen/src/handlers/mod.rs +++ b/crates/dagger-codegen/src/handlers/mod.rs @@ -9,9 +9,9 @@ mod utility; use std::sync::Arc; +use dagger_core::introspection::FullType; use genco::prelude::rust::Tokens; use genco::prelude::*; -use graphql_introspection_query::introspection_response::FullType; pub trait Handler { fn predicate(&self, _t: &FullType) -> bool { @@ -55,7 +55,7 @@ pub type Handlers = Vec; #[cfg(test)] mod tests { - use graphql_introspection_query::introspection_response::FullType; + use dagger_core::introspection::FullType; use pretty_assertions::assert_eq; use super::Handler; diff --git a/crates/dagger-codegen/src/handlers/object.rs b/crates/dagger-codegen/src/handlers/object.rs index a24c917..0c88fd5 100644 --- a/crates/dagger-codegen/src/handlers/object.rs +++ b/crates/dagger-codegen/src/handlers/object.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::FullType; use genco::{prelude::rust, quote}; -use graphql_introspection_query::introspection_response::FullType; use crate::predicates::is_object_type; @@ -50,7 +50,7 @@ impl Handler for Object { #[cfg(test)] mod tests { - use graphql_introspection_query::introspection_response::{ + use dagger_core::introspection::{ FullType, FullTypeFields, FullTypeFieldsType, TypeRef, __TypeKind, }; use pretty_assertions::assert_eq; @@ -92,8 +92,14 @@ mod tests { /// A directory whose contents persists across sessions -pub struct CacheVolume { - pub id: Option +pub struct CacheVolume {} + +impl CacheVolume { + pub fn id( + &self, + ) -> Option { + todo!() + } } impl Input for CacheVolume {} diff --git a/crates/dagger-codegen/src/handlers/scalar.rs b/crates/dagger-codegen/src/handlers/scalar.rs index 7138e39..e8d7b2f 100644 --- a/crates/dagger-codegen/src/handlers/scalar.rs +++ b/crates/dagger-codegen/src/handlers/scalar.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::FullType; use genco::{prelude::rust, quote}; -use graphql_introspection_query::introspection_response::FullType; use crate::predicates::is_custom_scalar_type; diff --git a/crates/dagger-codegen/src/handlers/type_ref.rs b/crates/dagger-codegen/src/handlers/type_ref.rs index 92eb6fe..3cc5a8f 100644 --- a/crates/dagger-codegen/src/handlers/type_ref.rs +++ b/crates/dagger-codegen/src/handlers/type_ref.rs @@ -1,6 +1,6 @@ +use dagger_core::introspection::TypeRef; use genco::prelude::rust; use genco::prelude::*; -use graphql_introspection_query::introspection_response::TypeRef; use crate::predicates::{ is_custom_scalar_type_ref, is_list_type, is_required_type_ref, is_scalar_type_ref, diff --git a/crates/dagger-codegen/src/handlers/utility.rs b/crates/dagger-codegen/src/handlers/utility.rs index 0d5798b..008a21c 100644 --- a/crates/dagger-codegen/src/handlers/utility.rs +++ b/crates/dagger-codegen/src/handlers/utility.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::{FullType, FullTypeFields, InputValue}; use genco::{prelude::*, quote}; -use graphql_introspection_query::introspection_response::{FullType, FullTypeFields}; pub fn render_description(t: &FullType) -> Option { if let Some(description) = t.description.as_ref() { @@ -26,3 +26,31 @@ pub fn render_description_from_field(t: &FullTypeFields) -> Option None } + +pub fn render_description_from_input_value(t: &InputValue, name: &String) -> Option { + if let Some(description) = t.description.as_ref() { + if description == "" { + return None; + } + let lines = description.split('\n').collect::>(); + let mut output = rust::Tokens::new(); + + if let Some(line) = lines.first() { + output.append(quote! { + $(format!("/// * `{name}` - {line}")) + }); + output.push(); + } + + for line in lines { + output.append(quote! { + $(format!("/// {line}")) + }); + output.push(); + } + + return Some(output); + } + + None +} diff --git a/crates/dagger-codegen/src/predicates.rs b/crates/dagger-codegen/src/predicates.rs index 24747e6..9ee9016 100644 --- a/crates/dagger-codegen/src/predicates.rs +++ b/crates/dagger-codegen/src/predicates.rs @@ -1,32 +1,30 @@ -use graphql_introspection_query::introspection_response::{ - self, FullType, FullTypeInputFields, TypeRef, __TypeKind, -}; +use dagger_core::introspection::{FullType, FullTypeInputFields, TypeRef, __TypeKind}; use crate::models::Scalars; pub fn is_scalar_type(t: &FullType) -> bool { - if let Some(introspection_response::__TypeKind::SCALAR) = t.kind { + if let Some(__TypeKind::SCALAR) = t.kind { return true; } false } pub fn is_scalar_type_ref(t: &TypeRef) -> bool { - if let Some(introspection_response::__TypeKind::SCALAR) = t.kind { + if let Some(__TypeKind::SCALAR) = t.kind { return true; } false } pub fn is_enum_type(t: &FullType) -> bool { - if let Some(introspection_response::__TypeKind::ENUM) = t.kind { + if let Some(__TypeKind::ENUM) = t.kind { return true; } false } pub fn is_input_object_type(t: &FullType) -> bool { - if let Some(introspection_response::__TypeKind::INPUT_OBJECT) = t.kind { + if let Some(__TypeKind::INPUT_OBJECT) = t.kind { return true; } false @@ -49,14 +47,14 @@ pub fn is_required_type_ref(t: &TypeRef) -> bool { } pub fn is_list_type(t: &TypeRef) -> bool { - if let Some(introspection_response::__TypeKind::LIST) = t.kind { + if let Some(__TypeKind::LIST) = t.kind { return true; } false } pub fn is_object_type(t: &FullType) -> bool { - if let Some(introspection_response::__TypeKind::OBJECT) = t.kind { + if let Some(__TypeKind::OBJECT) = t.kind { return true; } false diff --git a/crates/dagger-core/Cargo.toml b/crates/dagger-core/Cargo.toml index 16edae4..164bc45 100644 --- a/crates/dagger-core/Cargo.toml +++ b/crates/dagger-core/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0.152", features = ["derive"] } diff --git a/crates/dagger-core/src/introspection.rs b/crates/dagger-core/src/introspection.rs new file mode 100644 index 0000000..3ae0d03 --- /dev/null +++ b/crates/dagger-core/src/introspection.rs @@ -0,0 +1,299 @@ +#![allow(non_camel_case_types)] + +use serde::{Deserialize, Deserializer, Serialize}; + +#[derive(Clone, Debug)] +pub enum __DirectiveLocation { + QUERY, + MUTATION, + SUBSCRIPTION, + FIELD, + FRAGMENT_DEFINITION, + FRAGMENT_SPREAD, + INLINE_FRAGMENT, + SCHEMA, + SCALAR, + OBJECT, + FIELD_DEFINITION, + ARGUMENT_DEFINITION, + INTERFACE, + UNION, + ENUM, + ENUM_VALUE, + INPUT_OBJECT, + INPUT_FIELD_DEFINITION, + Other(String), +} + +impl Serialize for __DirectiveLocation { + fn serialize(&self, ser: S) -> Result { + ser.serialize_str(match *self { + __DirectiveLocation::QUERY => "QUERY", + __DirectiveLocation::MUTATION => "MUTATION", + __DirectiveLocation::SUBSCRIPTION => "SUBSCRIPTION", + __DirectiveLocation::FIELD => "FIELD", + __DirectiveLocation::FRAGMENT_DEFINITION => "FRAGMENT_DEFINITION", + __DirectiveLocation::FRAGMENT_SPREAD => "FRAGMENT_SPREAD", + __DirectiveLocation::INLINE_FRAGMENT => "INLINE_FRAGMENT", + __DirectiveLocation::SCHEMA => "SCHEMA", + __DirectiveLocation::SCALAR => "SCALAR", + __DirectiveLocation::OBJECT => "OBJECT", + __DirectiveLocation::FIELD_DEFINITION => "FIELD_DEFINITION", + __DirectiveLocation::ARGUMENT_DEFINITION => "ARGUMENT_DEFINITION", + __DirectiveLocation::INTERFACE => "INTERFACE", + __DirectiveLocation::UNION => "UNION", + __DirectiveLocation::ENUM => "ENUM", + __DirectiveLocation::ENUM_VALUE => "ENUM_VALUE", + __DirectiveLocation::INPUT_OBJECT => "INPUT_OBJECT", + __DirectiveLocation::INPUT_FIELD_DEFINITION => "INPUT_FIELD_DEFINITION", + __DirectiveLocation::Other(ref s) => s.as_str(), + }) + } +} + +impl<'de> Deserialize<'de> for __DirectiveLocation { + fn deserialize>(deserializer: D) -> Result { + let s = <&'de str>::deserialize(deserializer)?; + match s { + "QUERY" => Ok(__DirectiveLocation::QUERY), + "MUTATION" => Ok(__DirectiveLocation::MUTATION), + "SUBSCRIPTION" => Ok(__DirectiveLocation::SUBSCRIPTION), + "FIELD" => Ok(__DirectiveLocation::FIELD), + "FRAGMENT_DEFINITION" => Ok(__DirectiveLocation::FRAGMENT_DEFINITION), + "FRAGMENT_SPREAD" => Ok(__DirectiveLocation::FRAGMENT_SPREAD), + "INLINE_FRAGMENT" => Ok(__DirectiveLocation::INLINE_FRAGMENT), + "SCHEMA" => Ok(__DirectiveLocation::SCHEMA), + "SCALAR" => Ok(__DirectiveLocation::SCALAR), + "OBJECT" => Ok(__DirectiveLocation::OBJECT), + "FIELD_DEFINITION" => Ok(__DirectiveLocation::FIELD_DEFINITION), + "ARGUMENT_DEFINITION" => Ok(__DirectiveLocation::ARGUMENT_DEFINITION), + "INTERFACE" => Ok(__DirectiveLocation::INTERFACE), + "UNION" => Ok(__DirectiveLocation::UNION), + "ENUM" => Ok(__DirectiveLocation::ENUM), + "ENUM_VALUE" => Ok(__DirectiveLocation::ENUM_VALUE), + "INPUT_OBJECT" => Ok(__DirectiveLocation::INPUT_OBJECT), + "INPUT_FIELD_DEFINITION" => Ok(__DirectiveLocation::INPUT_FIELD_DEFINITION), + _ => Ok(__DirectiveLocation::Other(s.to_string())), + } + } +} + +#[derive(Clone, Debug, PartialEq)] +pub enum __TypeKind { + SCALAR, + OBJECT, + INTERFACE, + UNION, + ENUM, + INPUT_OBJECT, + LIST, + NON_NULL, + Other(String), +} + +impl Serialize for __TypeKind { + fn serialize(&self, ser: S) -> Result { + ser.serialize_str(match *self { + __TypeKind::SCALAR => "SCALAR", + __TypeKind::OBJECT => "OBJECT", + __TypeKind::INTERFACE => "INTERFACE", + __TypeKind::UNION => "UNION", + __TypeKind::ENUM => "ENUM", + __TypeKind::INPUT_OBJECT => "INPUT_OBJECT", + __TypeKind::LIST => "LIST", + __TypeKind::NON_NULL => "NON_NULL", + __TypeKind::Other(ref s) => s.as_str(), + }) + } +} + +impl<'de> Deserialize<'de> for __TypeKind { + fn deserialize>(deserializer: D) -> Result { + let s = <&'de str>::deserialize(deserializer)?; + match s { + "SCALAR" => Ok(__TypeKind::SCALAR), + "OBJECT" => Ok(__TypeKind::OBJECT), + "INTERFACE" => Ok(__TypeKind::INTERFACE), + "UNION" => Ok(__TypeKind::UNION), + "ENUM" => Ok(__TypeKind::ENUM), + "INPUT_OBJECT" => Ok(__TypeKind::INPUT_OBJECT), + "LIST" => Ok(__TypeKind::LIST), + "NON_NULL" => Ok(__TypeKind::NON_NULL), + _ => Ok(__TypeKind::Other(s.to_string())), + } + } +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullType { + pub kind: Option<__TypeKind>, + pub name: Option, + pub description: Option, + pub fields: Option>, + pub input_fields: Option>, + pub interfaces: Option>, + pub enum_values: Option>, + pub possible_types: Option>, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeFieldsArgs { + #[serde(flatten)] + pub input_value: InputValue, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeFieldsType { + #[serde(flatten)] + pub type_ref: TypeRef, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeFields { + pub name: Option, + pub description: Option, + pub args: Option>>, + #[serde(rename = "type")] + pub type_: Option, + pub is_deprecated: Option, + pub deprecation_reason: Option, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeInputFields { + #[serde(flatten)] + pub input_value: InputValue, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeInterfaces { + #[serde(flatten)] + pub type_ref: TypeRef, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypeEnumValues { + pub name: Option, + pub description: Option, + pub is_deprecated: Option, + pub deprecation_reason: Option, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FullTypePossibleTypes { + #[serde(flatten)] + pub type_ref: TypeRef, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct InputValue { + pub name: String, + pub description: Option, + #[serde(rename = "type")] + pub type_: InputValueType, + pub default_value: Option, +} + +type InputValueType = TypeRef; + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TypeRef { + pub kind: Option<__TypeKind>, + pub name: Option, + pub of_type: Option>, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaQueryType { + pub name: Option, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaMutationType { + pub name: Option, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaSubscriptionType { + pub name: Option, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaTypes { + #[serde(flatten)] + pub full_type: FullType, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaDirectivesArgs { + #[serde(flatten)] + input_value: InputValue, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SchemaDirectives { + pub name: Option, + pub description: Option, + pub locations: Option>>, + pub args: Option>>, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Schema { + pub query_type: Option, + pub mutation_type: Option, + pub subscription_type: Option, + pub types: Option>>, + directives: Option>>, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct SchemaContainer { + #[serde(rename = "__schema")] + pub schema: Option, +} + +#[derive(Deserialize, Debug)] +pub struct FullResponse { + data: T, +} + +#[derive(Debug, Deserialize)] +#[serde(untagged)] +pub enum IntrospectionResponse { + FullResponse(FullResponse), + Schema(SchemaContainer), +} + +impl IntrospectionResponse { + pub fn as_schema(&self) -> &SchemaContainer { + match self { + IntrospectionResponse::FullResponse(full_response) => &full_response.data, + IntrospectionResponse::Schema(schema) => schema, + } + } + + pub fn into_schema(self) -> SchemaContainer { + match self { + IntrospectionResponse::FullResponse(full_response) => full_response.data, + IntrospectionResponse::Schema(schema) => schema, + } + } +} diff --git a/crates/dagger-core/src/lib.rs b/crates/dagger-core/src/lib.rs index 5b4452c..3fb5af1 100644 --- a/crates/dagger-core/src/lib.rs +++ b/crates/dagger-core/src/lib.rs @@ -1,3 +1,5 @@ +pub mod introspection; + pub struct Scalar(String); pub struct Boolean(bool); diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index c6bc0af..47aa9eb 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -2,6 +2,15 @@ use dagger_core::{Boolean, Input, Int, Scalar}; // code generated by dagger. DO NOT EDIT. +/// A file identifier. +pub struct FileID(Scalar); + +/// A content-addressed directory identifier. +pub struct DirectoryID(Scalar); + +/// A global cache volume identifier. +pub struct CacheID(Scalar); + /// The platform config OS and architecture in a Container. /// The format is [os]/[platform]/[version] (e.g. darwin/arm64/v7, windows/amd64, linux/arm64). pub struct Platform(Scalar); @@ -9,22 +18,13 @@ pub struct Platform(Scalar); /// A unique identifier for a secret. pub struct SecretID(Scalar); -/// A global cache volume identifier. -pub struct CacheID(Scalar); - /// A content-addressed socket identifier. pub struct SocketID(Scalar); /// A unique container identifier. Null designates an empty container (scratch). pub struct ContainerID(Scalar); -/// A file identifier. -pub struct FileID(Scalar); - -/// A content-addressed directory identifier. -pub struct DirectoryID(Scalar); - -/// +/// pub struct BuildArg { pub name: Option, @@ -33,42 +33,73 @@ pub struct BuildArg { impl Input for BuildArg {} +/// A file. +pub struct File {} + +impl File { + /// Retrieves the contents of the file. + pub fn contents(&self) -> Option { + todo!() + } + + /// Writes the file to a file path on the host. + pub fn export(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves the content-addressed identifier of the file. + pub fn id(&self) -> Option { + todo!() + } + + /// Retrieves a secret referencing the contents of this file. + pub fn secret(&self) -> Option { + todo!() + } + + /// Gets the size of the file, in bytes. + pub fn size(&self) -> Option { + todo!() + } + + /// Retrieves this file with its created/modified timestamps set to the given time, in seconds from the Unix epoch. + pub fn with_timestamps(&self, timestamp: Option) -> Option { + todo!() + } +} + +impl Input for File {} + /// A set of scripts and/or extensions pub struct Project {} impl Project { - -/// extensions in this project + /// extensions in this project pub fn extensions(&self) -> Vec> { todo!() } - -/// Code files generated by the SDKs in the project + /// Code files generated by the SDKs in the project pub fn generated_code(&self) -> Option { todo!() } - -/// install the project's schema + /// install the project's schema pub fn install(&self) -> Option { todo!() } - -/// name of the project + /// name of the project pub fn name(&self) -> Option { todo!() } - -/// schema provided by the project + /// schema provided by the project pub fn schema(&self) -> String { todo!() } - -/// sdk used to generate code for and/or execute this project + /// sdk used to generate code for and/or execute this project pub fn sdk(&self) -> String { todo!() } @@ -76,86 +107,31 @@ impl Project { impl Input for Project {} -/// Information about the host execution environment. -pub struct Host {} - -impl Host { - -/// Accesses a directory on the host. - pub fn directory(&self) -> Option { - todo!() - } - - -/// Accesses an environment variable on the host. - pub fn env_variable(&self) -> HostVariable { - todo!() - } - - -/// Accesses a Unix socket on the host. - pub fn unix_socket(&self) -> Option { - todo!() - } - - -/// Retrieves the current working directory on the host. - pub fn workdir(&self) -> Option { - todo!() - } -} - -impl Input for Host {} - -/// An environment variable on the host environment. -pub struct HostVariable {} - -impl HostVariable { - -/// A secret referencing the value of this variable. - pub fn secret(&self) -> Option { - todo!() - } - - -/// The value of this variable. - pub fn value(&self) -> Option { - todo!() - } -} - -impl Input for HostVariable {} - /// A git repository. pub struct GitRepository {} impl GitRepository { - -/// Returns details on one branch. - pub fn branch(&self) -> Option { + /// Returns details on one branch. + pub fn branch(&self, name: Option) -> Option { todo!() } - -/// Lists of branches on the repository. + /// Lists of branches on the repository. pub fn branches(&self) -> Option>> { todo!() } - -/// Returns details on one commit. - pub fn commit(&self) -> Option { + /// Returns details on one commit. + pub fn commit(&self, id: Option) -> Option { todo!() } - -/// Returns details on one tag. - pub fn tag(&self) -> Option { + /// Returns details on one tag. + pub fn tag(&self, name: Option) -> Option { todo!() } - -/// Lists of tags on the repository. + /// Lists of tags on the repository. pub fn tags(&self) -> Option>> { todo!() } @@ -163,414 +139,52 @@ impl GitRepository { impl Input for GitRepository {} -/// A directory. -pub struct Directory {} +/// Information about the host execution environment. +pub struct Host {} -impl Directory { - -/// Gets the difference between this directory and an another directory. - pub fn diff(&self) -> Option { +impl Host { + /// Accesses a directory on the host. + pub fn directory( + &self, + path: Option, + exclude: Vec>, + include: Vec>, + ) -> Option { todo!() } - -/// Retrieves a directory at the given path. - pub fn directory(&self) -> Option { + /// Accesses an environment variable on the host. + pub fn env_variable(&self, name: Option) -> HostVariable { todo!() } - -/// Builds a new Docker container from this directory. - pub fn docker_build(&self) -> Option { + /// Accesses a Unix socket on the host. + pub fn unix_socket(&self, path: Option) -> Option { todo!() } - -/// Returns a list of files and directories at the given path. - pub fn entries(&self) -> Option>> { - todo!() - } - - -/// Writes the contents of the directory to a path on the host. - pub fn export(&self) -> Option { - todo!() - } - - -/// Retrieves a file at the given path. - pub fn file(&self) -> Option { - todo!() - } - - -/// The content-addressed identifier of the directory. - pub fn id(&self) -> Option { - todo!() - } - - -/// load a project's metadata - pub fn load_project(&self) -> Option { - todo!() - } - - -/// Creates a named sub-pipeline. - pub fn pipeline(&self) -> Option { - todo!() - } - - -/// Retrieves this directory plus a directory written at the given path. - pub fn with_directory(&self) -> Option { - todo!() - } - - -/// Retrieves this directory plus the contents of the given file copied to the given path. - pub fn with_file(&self) -> Option { - todo!() - } - - -/// Retrieves this directory plus a new directory created at the given path. - pub fn with_new_directory(&self) -> Option { - todo!() - } - - -/// Retrieves this directory plus a new file written at the given path. - pub fn with_new_file(&self) -> Option { - todo!() - } - - -/// Retrieves this directory with all file/dir timestamps set to the given time, in seconds from the Unix epoch. - pub fn with_timestamps(&self) -> Option { - todo!() - } - - -/// Retrieves this directory with the directory at the given path removed. - pub fn without_directory(&self) -> Option { - todo!() - } - - -/// Retrieves this directory with the file at the given path removed. - pub fn without_file(&self) -> Option { + /// Retrieves the current working directory on the host. + pub fn workdir( + &self, + exclude: Vec>, + include: Vec>, + ) -> Option { todo!() } } -impl Input for Directory {} - -/// An OCI-compatible container, also known as a docker container. -pub struct Container {} - -impl Container { - -/// Initializes this container from a Dockerfile build, using the context, a dockerfile file path and some additional buildArgs. - pub fn build(&self) -> Option { - todo!() - } - - -/// Retrieves default arguments for future commands. - pub fn default_args(&self) -> Vec> { - todo!() - } - - -/// Retrieves a directory at the given path. Mounts are included. - pub fn directory(&self) -> Option { - todo!() - } - - -/// Retrieves entrypoint to be prepended to the arguments of all commands. - pub fn entrypoint(&self) -> Vec> { - todo!() - } - - -/// Retrieves the value of the specified environment variable. - pub fn env_variable(&self) -> String { - todo!() - } - - -/// Retrieves the list of environment variables passed to commands. - pub fn env_variables(&self) -> Option>> { - todo!() - } - - -/// Retrieves this container after executing the specified command inside it. - pub fn exec(&self) -> Option { - todo!() - } - - -/// Exit code of the last executed command. Zero means success. -/// Null if no command has been executed. - pub fn exit_code(&self) -> Int { - todo!() - } - - -/// Writes the container as an OCI tarball to the destination file path on the host for the specified platformVariants. -/// Return true on success. - pub fn export(&self) -> Option { - todo!() - } - - -/// Retrieves a file at the given path. Mounts are included. - pub fn file(&self) -> Option { - todo!() - } - - -/// Initializes this container from the base image published at the given address. - pub fn from(&self) -> Option { - todo!() - } - - -/// Retrieves this container's root filesystem. Mounts are not included. - pub fn fs(&self) -> Option { - todo!() - } - - -/// A unique identifier for this container. - pub fn id(&self) -> Option { - todo!() - } - - -/// Retrieves the value of the specified label. - pub fn label(&self) -> String { - todo!() - } - - -/// Retrieves the list of labels passed to container. - pub fn labels(&self) -> Option>> { - todo!() - } - - -/// Retrieves the list of paths where a directory is mounted. - pub fn mounts(&self) -> Option>> { - todo!() - } - - -/// Creates a named sub-pipeline - pub fn pipeline(&self) -> Option { - todo!() - } - - -/// The platform this container executes and publishes as. - pub fn platform(&self) -> Option { - todo!() - } - - -/// Publishes this container as a new image to the specified address, for the platformVariants, returning a fully qualified ref. - pub fn publish(&self) -> Option { - todo!() - } - - -/// Retrieves this container's root filesystem. Mounts are not included. - pub fn rootfs(&self) -> Option { - todo!() - } - - -/// The error stream of the last executed command. -/// Null if no command has been executed. - pub fn stderr(&self) -> String { - todo!() - } - - -/// The output stream of the last executed command. -/// Null if no command has been executed. - pub fn stdout(&self) -> String { - todo!() - } - - -/// Retrieves the user to be set for all commands. - pub fn user(&self) -> String { - todo!() - } - - -/// Configures default arguments for future commands. - pub fn with_default_args(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a directory written at the given path. - pub fn with_directory(&self) -> Option { - todo!() - } - - -/// Retrieves this container but with a different command entrypoint. - pub fn with_entrypoint(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus the given environment variable. - pub fn with_env_variable(&self) -> Option { - todo!() - } - - -/// Retrieves this container after executing the specified command inside it. - pub fn with_exec(&self) -> Option { - todo!() - } - - -/// Initializes this container from this DirectoryID. - pub fn with_fs(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus the contents of the given file copied to the given path. - pub fn with_file(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus the given label. - pub fn with_label(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a cache volume mounted at the given path. - pub fn with_mounted_cache(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a directory mounted at the given path. - pub fn with_mounted_directory(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a file mounted at the given path. - pub fn with_mounted_file(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a secret mounted into a file at the given path. - pub fn with_mounted_secret(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a temporary directory mounted at the given path. - pub fn with_mounted_temp(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a new file written at the given path. - pub fn with_new_file(&self) -> Option { - todo!() - } - - -/// Initializes this container from this DirectoryID. - pub fn with_rootfs(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus an env variable containing the given secret. - pub fn with_secret_variable(&self) -> Option { - todo!() - } - - -/// Retrieves this container plus a socket forwarded to the given Unix socket path. - pub fn with_unix_socket(&self) -> Option { - todo!() - } - - -/// Retrieves this containers with a different command user. - pub fn with_user(&self) -> Option { - todo!() - } - - -/// Retrieves this container with a different working directory. - pub fn with_workdir(&self) -> Option { - todo!() - } - - -/// Retrieves this container minus the given environment variable. - pub fn without_env_variable(&self) -> Option { - todo!() - } - - -/// Retrieves this container minus the given environment label. - pub fn without_label(&self) -> Option { - todo!() - } - - -/// Retrieves this container after unmounting everything at the given path. - pub fn without_mount(&self) -> Option { - todo!() - } - - -/// Retrieves this container with a previously added Unix socket removed. - pub fn without_unix_socket(&self) -> Option { - todo!() - } - - -/// Retrieves the working directory for all commands. - pub fn workdir(&self) -> String { - todo!() - } -} - -impl Input for Container {} +impl Input for Host {} /// A simple key value object that represents a label. pub struct Label {} impl Label { - -/// The label name. + /// The label name. pub fn name(&self) -> Option { todo!() } - -/// The label value. + /// The label value. pub fn value(&self) -> Option { todo!() } @@ -578,31 +192,16 @@ impl Label { impl Input for Label {} -/// -pub struct Socket {} - -impl Socket { - -/// The content-addressed identifier of the socket. - pub fn id(&self) -> Option { - todo!() - } -} - -impl Input for Socket {} - /// A reference to a secret value, which can be handled more safely than the value itself. pub struct Secret {} impl Secret { - -/// The identifier for this secret. + /// The identifier for this secret. pub fn id(&self) -> Option { todo!() } - -/// The value of this secret. + /// The value of this secret. pub fn plaintext(&self) -> Option { todo!() } @@ -610,12 +209,390 @@ impl Secret { impl Input for Secret {} +/// An OCI-compatible container, also known as a docker container. +pub struct Container {} + +impl Container { + /// Initializes this container from a Dockerfile build, using the context, a dockerfile file path and some additional buildArgs. + /// # Arguments + /// + /// * `context` - Directory context used by the Dockerfile. + /// Directory context used by the Dockerfile. + /// * `dockerfile` - Path to the Dockerfile to use. + /// Path to the Dockerfile to use. + /// Defaults to './Dockerfile'. + /// * `buildArgs` - Additional build arguments. + /// Additional build arguments. + /// * `target` - Target build stage to build. + /// Target build stage to build. + pub fn build( + &self, + context: Option, + dockerfile: String, + build_args: Vec>, + target: String, + ) -> Option { + todo!() + } + + /// Retrieves default arguments for future commands. + pub fn default_args(&self) -> Vec> { + todo!() + } + + /// Retrieves a directory at the given path. Mounts are included. + pub fn directory(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves entrypoint to be prepended to the arguments of all commands. + pub fn entrypoint(&self) -> Vec> { + todo!() + } + + /// Retrieves the value of the specified environment variable. + pub fn env_variable(&self, name: Option) -> String { + todo!() + } + + /// Retrieves the list of environment variables passed to commands. + pub fn env_variables(&self) -> Option>> { + todo!() + } + + /// Retrieves this container after executing the specified command inside it. + /// # Arguments + /// + /// * `args` - Command to run instead of the container's default command. + /// Command to run instead of the container's default command. + /// * `stdin` - Content to write to the command's standard input before closing. + /// Content to write to the command's standard input before closing. + /// * `redirectStdout` - Redirect the command's standard output to a file in the container. + /// Redirect the command's standard output to a file in the container. + /// * `redirectStderr` - Redirect the command's standard error to a file in the container. + /// Redirect the command's standard error to a file in the container. + /// * `experimentalPrivilegedNesting` - Provide dagger access to the executed command. + /// Provide 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. + pub fn exec( + &self, + args: Vec>, + stdin: String, + redirect_stdout: String, + redirect_stderr: String, + experimental_privileged_nesting: Boolean, + ) -> Option { + todo!() + } + + /// Exit code of the last executed command. Zero means success. + /// Null if no command has been executed. + pub fn exit_code(&self) -> Int { + todo!() + } + + /// Writes the container as an OCI tarball to the destination file path on the host for the specified platformVariants. + /// Return true on success. + /// # Arguments + /// + /// * `path` - Host's destination path. + /// Host's destination path. + /// Path can be relative to the engine's workdir or absolute. + /// * `platformVariants` - Identifiers for other platform specific containers. + /// Identifiers for other platform specific containers. + /// Used for multi-platform image. + pub fn export( + &self, + path: Option, + platform_variants: Vec>, + ) -> Option { + todo!() + } + + /// Retrieves a file at the given path. Mounts are included. + pub fn file(&self, path: Option) -> Option { + todo!() + } + + /// Initializes this container from the base image published at the given address. + /// # Arguments + /// + /// * `address` - Image's address from its registry. + /// Image's address from its registry. + /// Formatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main). + pub fn from(&self, address: Option) -> Option { + todo!() + } + + /// Retrieves this container's root filesystem. Mounts are not included. + pub fn fs(&self) -> Option { + todo!() + } + + /// A unique identifier for this container. + pub fn id(&self) -> Option { + todo!() + } + + /// Retrieves the value of the specified label. + pub fn label(&self, name: Option) -> String { + todo!() + } + + /// Retrieves the list of labels passed to container. + pub fn labels(&self) -> Option>> { + todo!() + } + + /// Retrieves the list of paths where a directory is mounted. + pub fn mounts(&self) -> Option>> { + todo!() + } + + /// Creates a named sub-pipeline + pub fn pipeline(&self, name: Option, description: String) -> Option { + todo!() + } + + /// The platform this container executes and publishes as. + pub fn platform(&self) -> Option { + todo!() + } + + /// Publishes this container as a new image to the specified address, for the platformVariants, returning a fully qualified ref. + /// # Arguments + /// + /// * `address` - Registry's address to publish the image to. + /// Registry's address to publish the image to. + /// Formatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main). + /// * `platformVariants` - Identifiers for other platform specific containers. + /// Identifiers for other platform specific containers. + /// Used for multi-platform image. + pub fn publish( + &self, + address: Option, + platform_variants: Vec>, + ) -> Option { + todo!() + } + + /// Retrieves this container's root filesystem. Mounts are not included. + pub fn rootfs(&self) -> Option { + todo!() + } + + /// The error stream of the last executed command. + /// Null if no command has been executed. + pub fn stderr(&self) -> String { + todo!() + } + + /// The output stream of the last executed command. + /// Null if no command has been executed. + pub fn stdout(&self) -> String { + todo!() + } + + /// Retrieves the user to be set for all commands. + pub fn user(&self) -> String { + todo!() + } + + /// Configures default arguments for future commands. + pub fn with_default_args(&self, args: Vec>) -> Option { + todo!() + } + + /// Retrieves this container plus a directory written at the given path. + pub fn with_directory( + &self, + path: Option, + directory: Option, + exclude: Vec>, + include: Vec>, + ) -> Option { + todo!() + } + + /// Retrieves this container but with a different command entrypoint. + pub fn with_entrypoint(&self, args: Option>>) -> Option { + todo!() + } + + /// Retrieves this container plus the given environment variable. + pub fn with_env_variable( + &self, + name: Option, + value: Option, + ) -> Option { + todo!() + } + + /// Retrieves this container after executing the specified command inside it. + /// # Arguments + /// + /// * `args` - Command to run instead of the container's default command. + /// Command to run instead of the container's default command. + /// * `stdin` - Content to write to the command's standard input before closing. + /// Content to write to the command's standard input before closing. + /// * `redirectStdout` - Redirect the command's standard output to a file in the container. + /// Redirect the command's standard output to a file in the container. + /// * `redirectStderr` - Redirect the command's standard error to a file in the container. + /// Redirect the command's standard error to a file in the container. + /// * `experimentalPrivilegedNesting` - Provide dagger access to the executed command. + /// Provide 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. + pub fn with_exec( + &self, + args: Option>>, + stdin: String, + redirect_stdout: String, + redirect_stderr: String, + experimental_privileged_nesting: Boolean, + ) -> Option { + todo!() + } + + /// Initializes this container from this DirectoryID. + pub fn with_fs(&self, id: Option) -> Option { + todo!() + } + + /// Retrieves this container plus the contents of the given file copied to the given path. + pub fn with_file( + &self, + path: Option, + source: Option, + permissions: Int, + ) -> Option { + todo!() + } + + /// Retrieves this container plus the given label. + pub fn with_label(&self, name: Option, value: Option) -> Option { + todo!() + } + + /// Retrieves this container plus a cache volume mounted at the given path. + pub fn with_mounted_cache( + &self, + path: Option, + cache: Option, + source: DirectoryID, + ) -> Option { + todo!() + } + + /// Retrieves this container plus a directory mounted at the given path. + pub fn with_mounted_directory( + &self, + path: Option, + source: Option, + ) -> Option { + todo!() + } + + /// Retrieves this container plus a file mounted at the given path. + pub fn with_mounted_file( + &self, + path: Option, + source: Option, + ) -> Option { + todo!() + } + + /// Retrieves this container plus a secret mounted into a file at the given path. + pub fn with_mounted_secret( + &self, + path: Option, + source: Option, + ) -> Option { + todo!() + } + + /// Retrieves this container plus a temporary directory mounted at the given path. + pub fn with_mounted_temp(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves this container plus a new file written at the given path. + pub fn with_new_file( + &self, + path: Option, + contents: String, + permissions: Int, + ) -> Option { + todo!() + } + + /// Initializes this container from this DirectoryID. + pub fn with_rootfs(&self, id: Option) -> Option { + todo!() + } + + /// Retrieves this container plus an env variable containing the given secret. + pub fn with_secret_variable( + &self, + name: Option, + secret: Option, + ) -> Option { + todo!() + } + + /// Retrieves this container plus a socket forwarded to the given Unix socket path. + pub fn with_unix_socket( + &self, + path: Option, + source: Option, + ) -> Option { + todo!() + } + + /// Retrieves this containers with a different command user. + pub fn with_user(&self, name: Option) -> Option { + todo!() + } + + /// Retrieves this container with a different working directory. + pub fn with_workdir(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves this container minus the given environment variable. + pub fn without_env_variable(&self, name: Option) -> Option { + todo!() + } + + /// Retrieves this container minus the given environment label. + pub fn without_label(&self, name: Option) -> Option { + todo!() + } + + /// Retrieves this container after unmounting everything at the given path. + pub fn without_mount(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves this container with a previously added Unix socket removed. + pub fn without_unix_socket(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves the working directory for all commands. + pub fn workdir(&self) -> String { + todo!() + } +} + +impl Input for Container {} + /// A directory whose contents persist across runs. pub struct CacheVolume {} impl CacheVolume { - -/// + /// pub fn id(&self) -> Option { todo!() } @@ -623,164 +600,266 @@ impl CacheVolume { impl Input for CacheVolume {} -/// -pub struct Query {} +/// A git ref (tag, branch or commit). +pub struct GitRef {} -impl Query { - -/// Constructs a cache volume for a given cache key. - pub fn cache_volume(&self) -> Option { +impl GitRef { + /// The digest of the current value of this ref. + pub fn digest(&self) -> Option { todo!() } - -/// Loads a container from ID. -/// Null ID returns an empty container (scratch). -/// Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host. - pub fn container(&self) -> Option { + /// The filesystem tree at this ref. + pub fn tree(&self, ssh_known_hosts: String, ssh_auth_socket: SocketID) -> Option { + todo!() + } +} + +impl Input for GitRef {} + +/// +pub struct Socket {} + +impl Socket { + /// The content-addressed identifier of the socket. + pub fn id(&self) -> Option { + todo!() + } +} + +impl Input for Socket {} + +/// A directory. +pub struct Directory {} + +impl Directory { + /// Gets the difference between this directory and an another directory. + pub fn diff(&self, other: Option) -> Option { todo!() } - -/// The default platform of the builder. - pub fn default_platform(&self) -> Option { + /// Retrieves a directory at the given path. + pub fn directory(&self, path: Option) -> Option { todo!() } - -/// Load a directory by ID. No argument produces an empty directory. - pub fn directory(&self) -> Option { + /// Builds a new Docker container from this directory. + /// # Arguments + /// + /// * `dockerfile` - Path to the Dockerfile to use. + /// Path to the Dockerfile to use. + /// Defaults to './Dockerfile'. + /// * `platform` - The platform to build. + /// The platform to build. + /// * `buildArgs` - Additional build arguments. + /// Additional build arguments. + /// * `target` - Target build stage to build. + /// Target build stage to build. + pub fn docker_build( + &self, + dockerfile: String, + platform: Platform, + build_args: Vec>, + target: String, + ) -> Option { todo!() } - -/// Loads a file by ID. - pub fn file(&self) -> File { + /// Returns a list of files and directories at the given path. + pub fn entries(&self, path: String) -> Option>> { todo!() } - -/// Queries a git repository. - pub fn git(&self) -> Option { + /// Writes the contents of the directory to a path on the host. + pub fn export(&self, path: Option) -> Option { todo!() } - -/// Queries the host environment. - pub fn host(&self) -> Option { + /// Retrieves a file at the given path. + pub fn file(&self, path: Option) -> Option { todo!() } - -/// Returns a file containing an http remote url content. - pub fn http(&self) -> Option { + /// The content-addressed identifier of the directory. + pub fn id(&self) -> Option { todo!() } - -/// Creates a named sub-pipeline - pub fn pipeline(&self) -> Option { + /// load a project's metadata + pub fn load_project(&self, config_path: Option) -> Option { todo!() } - -/// Look up a project by name - pub fn project(&self) -> Option { + /// Creates a named sub-pipeline. + pub fn pipeline(&self, name: Option, description: String) -> Option { todo!() } - -/// Loads a secret from its ID. + /// Retrieves this directory plus a directory written at the given path. + /// # Arguments + /// + /// * `exclude` - Exclude artifacts that match the given pattern. + /// Exclude artifacts that match the given pattern. + /// (e.g. ["node_modules/", ".git*"]). + /// * `include` - Include only artifacts that match the given pattern. + /// Include only artifacts that match the given pattern. + /// (e.g. ["app/", "package.*"]). + pub fn with_directory( + &self, + path: Option, + directory: Option, + exclude: Vec>, + include: Vec>, + ) -> Option { + todo!() + } + + /// Retrieves this directory plus the contents of the given file copied to the given path. + pub fn with_file( + &self, + path: Option, + source: Option, + permissions: Int, + ) -> Option { + todo!() + } + + /// Retrieves this directory plus a new directory created at the given path. + pub fn with_new_directory(&self, path: Option, permissions: Int) -> Option { + todo!() + } + + /// Retrieves this directory plus a new file written at the given path. + pub fn with_new_file( + &self, + path: Option, + contents: Option, + permissions: Int, + ) -> Option { + todo!() + } + + /// Retrieves this directory with all file/dir timestamps set to the given time, in seconds from the Unix epoch. + pub fn with_timestamps(&self, timestamp: Option) -> Option { + todo!() + } + + /// Retrieves this directory with the directory at the given path removed. + pub fn without_directory(&self, path: Option) -> Option { + todo!() + } + + /// Retrieves this directory with the file at the given path removed. + pub fn without_file(&self, path: Option) -> Option { + todo!() + } +} + +impl Input for Directory {} + +/// An environment variable on the host environment. +pub struct HostVariable {} + +impl HostVariable { + /// A secret referencing the value of this variable. pub fn secret(&self) -> Option { todo!() } - -/// Loads a socket by its ID. - pub fn socket(&self) -> Option { + /// The value of this variable. + pub fn value(&self) -> Option { + todo!() + } +} + +impl Input for HostVariable {} + +/// +pub struct Query {} + +impl Query { + /// Constructs a cache volume for a given cache key. + /// # Arguments + /// + /// * `key` - A string identifier to target this cache volume (e.g. "myapp-cache"). + /// A string identifier to target this cache volume (e.g. "myapp-cache"). + pub fn cache_volume(&self, key: Option) -> Option { + todo!() + } + + /// Loads a container from ID. + /// Null ID returns an empty container (scratch). + /// Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host. + pub fn container(&self, id: ContainerID, platform: Platform) -> Option { + todo!() + } + + /// The default platform of the builder. + pub fn default_platform(&self) -> Option { + todo!() + } + + /// Load a directory by ID. No argument produces an empty directory. + pub fn directory(&self, id: DirectoryID) -> Option { + todo!() + } + + /// Loads a file by ID. + pub fn file(&self, id: Option) -> File { + todo!() + } + + /// Queries a git repository. + pub fn git(&self, url: Option, keep_git_dir: Boolean) -> Option { + todo!() + } + + /// Queries the host environment. + pub fn host(&self) -> Option { + todo!() + } + + /// Returns a file containing an http remote url content. + pub fn http(&self, url: Option) -> Option { + todo!() + } + + /// Creates a named sub-pipeline + pub fn pipeline(&self, name: Option, description: String) -> Option { + todo!() + } + + /// Look up a project by name + pub fn project(&self, name: Option) -> Option { + todo!() + } + + /// Loads a secret from its ID. + pub fn secret(&self, id: Option) -> Option { + todo!() + } + + /// Loads a socket by its ID. + pub fn socket(&self, id: SocketID) -> Option { todo!() } } impl Input for Query {} -/// A file. -pub struct File {} - -impl File { - -/// Retrieves the contents of the file. - pub fn contents(&self) -> Option { - todo!() - } - - -/// Writes the file to a file path on the host. - pub fn export(&self) -> Option { - todo!() - } - - -/// Retrieves the content-addressed identifier of the file. - pub fn id(&self) -> Option { - todo!() - } - - -/// Retrieves a secret referencing the contents of this file. - pub fn secret(&self) -> Option { - todo!() - } - - -/// Gets the size of the file, in bytes. - pub fn size(&self) -> Option { - todo!() - } - - -/// Retrieves this file with its created/modified timestamps set to the given time, in seconds from the Unix epoch. - pub fn with_timestamps(&self) -> Option { - todo!() - } -} - -impl Input for File {} - /// A simple key value object that represents an environment variable. pub struct EnvVariable {} impl EnvVariable { - -/// The environment variable name. + /// The environment variable name. pub fn name(&self) -> Option { todo!() } - -/// The environment variable value. + /// The environment variable value. pub fn value(&self) -> Option { todo!() } } impl Input for EnvVariable {} - -/// A git ref (tag, branch or commit). -pub struct GitRef {} - -impl GitRef { - -/// The digest of the current value of this ref. - pub fn digest(&self) -> Option { - todo!() - } - - -/// The filesystem tree at this ref. - pub fn tree(&self) -> Option { - todo!() - } -} - -impl Input for GitRef {} diff --git a/src/schema.rs b/src/schema.rs index bc88db1..801e2b8 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,4 +1,4 @@ -use graphql_introspection_query::introspection_response::IntrospectionResponse; +use dagger_core::introspection::IntrospectionResponse; use crate::{config::Config, engine::Engine, session::Session}; diff --git a/src/session.rs b/src/session.rs index 046c064..f4b3e6f 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,5 +1,5 @@ +use dagger_core::introspection::{self, IntrospectionResponse}; use graphql_client::GraphQLQuery; -use graphql_introspection_query::introspection_response::IntrospectionResponse; use reqwest::{ blocking::{Client, RequestBuilder}, header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE}, @@ -65,7 +65,7 @@ impl Session { return Err(eyre::anyhow!(error_message)); } - let json: IntrospectionResponse = res.json()?; + let json: introspection::IntrospectionResponse = res.json()?; Ok(json) }