with proper optional types

This commit is contained in:
Kasper Juul Hermansen 2023-02-01 15:27:44 +01:00
parent 8549cfc3a7
commit f4a812a7d2
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
3 changed files with 337 additions and 342 deletions

View File

@ -11,15 +11,6 @@ pub fn render_type_ref(inner: &TypeRef) -> eyre::Result<rust::Tokens> {
return t.clone().of_type.map(|t| *t); return t.clone().of_type.map(|t| *t);
}; };
if !is_required_type_ref(inner) {
if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?;
return Ok(quote! {
Option<$inner_field>
});
}
}
if is_list_type(&inner) { if is_list_type(&inner) {
if let Some(inner_of_type) = extract_of_type(inner) { if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?; let inner_field = render_type_ref(&inner_of_type)?;
@ -58,6 +49,15 @@ pub fn render_type_ref(inner: &TypeRef) -> eyre::Result<rust::Tokens> {
}); });
} }
if !is_required_type_ref(inner) {
if let Some(inner_of_type) = extract_of_type(inner) {
let inner_field = render_type_ref(&inner_of_type)?;
return Ok(quote! {
Option<$inner_field>
});
}
}
if let Some(inner_type) = inner.of_type.as_ref() { if let Some(inner_type) = inner.of_type.as_ref() {
return render_type_ref(&inner_type); return render_type_ref(&inner_type);
} }

View File

@ -32,8 +32,8 @@ pub fn is_input_object_type(t: &FullType) -> bool {
pub fn is_required_type(t: &FullTypeInputFields) -> bool { pub fn is_required_type(t: &FullTypeInputFields) -> bool {
match t.input_value.type_.kind { match t.input_value.type_.kind {
Some(__TypeKind::NON_NULL) => return false, Some(__TypeKind::NON_NULL) => return true,
Some(_) => return true, Some(_) => return false,
_ => return false, _ => return false,
} }
} }
@ -42,7 +42,7 @@ pub fn is_required_type_ref(t: &TypeRef) -> bool {
match t.kind { match t.kind {
Some(__TypeKind::NON_NULL) => return true, Some(__TypeKind::NON_NULL) => return true,
Some(_) => return false, Some(_) => return false,
_ => return true, _ => return false,
} }
} }

View File

@ -2,164 +2,37 @@ use dagger_core::{Boolean, Input, Int, Scalar};
// code generated by dagger. DO NOT EDIT. // code generated by dagger. DO NOT EDIT.
/// A content-addressed socket identifier.
pub struct SocketID(Scalar);
/// A unique identifier for a secret.
pub struct SecretID(Scalar);
/// A unique container identifier. Null designates an empty container (scratch).
pub struct ContainerID(Scalar);
/// A content-addressed directory identifier. /// A content-addressed directory identifier.
pub struct DirectoryID(Scalar); pub struct DirectoryID(Scalar);
/// A global cache volume identifier.
pub struct CacheID(Scalar);
/// The platform config OS and architecture in a Container. /// The platform config OS and architecture in a Container.
/// The format is [os]/[platform]/[version] (e.g. darwin/arm64/v7, windows/amd64, linux/arm64). /// The format is [os]/[platform]/[version] (e.g. darwin/arm64/v7, windows/amd64, linux/arm64).
pub struct Platform(Scalar); pub struct Platform(Scalar);
/// A global cache volume identifier.
pub struct CacheID(Scalar);
/// A file identifier. /// A file identifier.
pub struct FileID(Scalar); pub struct FileID(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 unique identifier for a secret.
pub struct SecretID(Scalar);
/// ///
pub struct BuildArg { pub struct BuildArg {
pub value: String,
pub name: String, pub name: String,
pub value: String,
} }
impl Input for BuildArg {} impl Input for BuildArg {}
/// 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.
pub fn id(&self) -> SecretID {
todo!()
}
/// The value of this secret.
pub fn plaintext(&self) -> String {
todo!()
}
}
impl Input for Secret {}
/// Information about the host execution environment.
pub struct Host {}
impl Host {
/// Accesses a directory on the host.
pub fn directory(
&self,
path: String,
exclude: Option<String>,
include: Option<String>,
) -> Directory {
todo!()
}
/// Accesses an environment variable on the host.
pub fn env_variable(&self, name: String) -> HostVariable {
todo!()
}
/// Accesses a Unix socket on the host.
pub fn unix_socket(&self, path: String) -> Socket {
todo!()
}
/// Retrieves the current working directory on the host.
pub fn workdir(&self, exclude: Option<String>, include: Option<String>) -> Directory {
todo!()
}
}
impl Input for Host {}
/// A git repository.
pub struct GitRepository {}
impl GitRepository {
/// Returns details on one branch.
pub fn branch(&self, name: String) -> GitRef {
todo!()
}
/// Lists of branches on the repository.
pub fn branches(&self) -> Option<String> {
todo!()
}
/// Returns details on one commit.
pub fn commit(&self, id: String) -> GitRef {
todo!()
}
/// Returns details on one tag.
pub fn tag(&self, name: String) -> GitRef {
todo!()
}
/// Lists of tags on the repository.
pub fn tags(&self) -> Option<String> {
todo!()
}
}
impl Input for GitRepository {}
/// 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) -> String {
todo!()
}
/// The filesystem tree at this ref.
pub fn tree(&self, ssh_known_hosts: String, ssh_auth_socket: SocketID) -> Directory {
todo!()
}
}
impl Input for GitRef {}
/// An environment variable on the host environment.
pub struct HostVariable {}
impl HostVariable {
/// A secret referencing the value of this variable.
pub fn secret(&self) -> Secret {
todo!()
}
/// The value of this variable.
pub fn value(&self) -> String {
todo!()
}
}
impl Input for HostVariable {}
/// A directory whose contents persist across runs.
pub struct CacheVolume {}
impl CacheVolume {
///
pub fn id(&self) -> CacheID {
todo!()
}
}
impl Input for CacheVolume {}
/// A directory. /// A directory.
pub struct Directory {} pub struct Directory {}
@ -190,14 +63,14 @@ impl Directory {
&self, &self,
dockerfile: String, dockerfile: String,
platform: Platform, platform: Platform,
build_args: Option<BuildArg>, build_args: Vec<BuildArg>,
target: String, target: String,
) -> Container { ) -> Container {
todo!() todo!()
} }
/// Returns a list of files and directories at the given path. /// Returns a list of files and directories at the given path.
pub fn entries(&self, path: String) -> Option<String> { pub fn entries(&self, path: String) -> Vec<String> {
todo!() todo!()
} }
@ -239,8 +112,8 @@ impl Directory {
&self, &self,
path: String, path: String,
directory: DirectoryID, directory: DirectoryID,
exclude: Option<String>, exclude: Vec<String>,
include: Option<String>, include: Vec<String>,
) -> Directory { ) -> Directory {
todo!() todo!()
} }
@ -278,22 +151,303 @@ impl Directory {
impl Input for Directory {} impl Input for Directory {}
/// A simple key value object that represents a label. /// A file.
pub struct Label {} pub struct File {}
impl Label { impl File {
/// The label name. /// Retrieves the contents of the file.
pub fn contents(&self) -> String {
todo!()
}
/// Writes the file to a file path on the host.
pub fn export(&self, path: String) -> Boolean {
todo!()
}
/// Retrieves the content-addressed identifier of the file.
pub fn id(&self) -> FileID {
todo!()
}
/// Retrieves a secret referencing the contents of this file.
pub fn secret(&self) -> Secret {
todo!()
}
/// Gets the size of the file, in bytes.
pub fn size(&self) -> Int {
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: Int) -> File {
todo!()
}
}
impl Input for File {}
///
pub struct Socket {}
impl Socket {
/// The content-addressed identifier of the socket.
pub fn id(&self) -> SocketID {
todo!()
}
}
impl Input for Socket {}
/// A simple key value object that represents an environment variable.
pub struct EnvVariable {}
impl EnvVariable {
/// The environment variable name.
pub fn name(&self) -> String { pub fn name(&self) -> String {
todo!() todo!()
} }
/// The label value. /// The environment variable value.
pub fn value(&self) -> String { pub fn value(&self) -> String {
todo!() todo!()
} }
} }
impl Input for Label {} impl Input for EnvVariable {}
/// A git repository.
pub struct GitRepository {}
impl GitRepository {
/// Returns details on one branch.
pub fn branch(&self, name: String) -> GitRef {
todo!()
}
/// Lists of branches on the repository.
pub fn branches(&self) -> Vec<String> {
todo!()
}
/// Returns details on one commit.
pub fn commit(&self, id: String) -> GitRef {
todo!()
}
/// Returns details on one tag.
pub fn tag(&self, name: String) -> GitRef {
todo!()
}
/// Lists of tags on the repository.
pub fn tags(&self) -> Vec<String> {
todo!()
}
}
impl Input for GitRepository {}
/// A directory whose contents persist across runs.
pub struct CacheVolume {}
impl CacheVolume {
///
pub fn id(&self) -> CacheID {
todo!()
}
}
impl Input for CacheVolume {}
/// 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.
pub fn id(&self) -> SecretID {
todo!()
}
/// The value of this secret.
pub fn plaintext(&self) -> String {
todo!()
}
}
impl Input for Secret {}
/// 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) -> String {
todo!()
}
/// The filesystem tree at this ref.
pub fn tree(&self, ssh_known_hosts: String, ssh_auth_socket: SocketID) -> Directory {
todo!()
}
}
impl Input for GitRef {}
/// An environment variable on the host environment.
pub struct HostVariable {}
impl HostVariable {
/// A secret referencing the value of this variable.
pub fn secret(&self) -> Secret {
todo!()
}
/// The value of this variable.
pub fn value(&self) -> String {
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: String) -> CacheVolume {
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) -> Container {
todo!()
}
/// The default platform of the builder.
pub fn default_platform(&self) -> Platform {
todo!()
}
/// Load a directory by ID. No argument produces an empty directory.
pub fn directory(&self, id: DirectoryID) -> Directory {
todo!()
}
/// Loads a file by ID.
pub fn file(&self, id: FileID) -> File {
todo!()
}
/// Queries a git repository.
pub fn git(&self, url: String, keep_git_dir: Boolean) -> GitRepository {
todo!()
}
/// Queries the host environment.
pub fn host(&self) -> Host {
todo!()
}
/// Returns a file containing an http remote url content.
pub fn http(&self, url: String) -> File {
todo!()
}
/// Creates a named sub-pipeline
pub fn pipeline(&self, name: String, description: String) -> Query {
todo!()
}
/// Look up a project by name
pub fn project(&self, name: String) -> Project {
todo!()
}
/// Loads a secret from its ID.
pub fn secret(&self, id: SecretID) -> Secret {
todo!()
}
/// Loads a socket by its ID.
pub fn socket(&self, id: SocketID) -> Socket {
todo!()
}
}
impl Input for Query {}
/// Information about the host execution environment.
pub struct Host {}
impl Host {
/// Accesses a directory on the host.
pub fn directory(&self, path: String, exclude: Vec<String>, include: Vec<String>) -> Directory {
todo!()
}
/// Accesses an environment variable on the host.
pub fn env_variable(&self, name: String) -> HostVariable {
todo!()
}
/// Accesses a Unix socket on the host.
pub fn unix_socket(&self, path: String) -> Socket {
todo!()
}
/// Retrieves the current working directory on the host.
pub fn workdir(&self, exclude: Vec<String>, include: Vec<String>) -> Directory {
todo!()
}
}
impl Input for Host {}
/// A set of scripts and/or extensions
pub struct Project {}
impl Project {
/// extensions in this project
pub fn extensions(&self) -> Vec<Project> {
todo!()
}
/// Code files generated by the SDKs in the project
pub fn generated_code(&self) -> Directory {
todo!()
}
/// install the project's schema
pub fn install(&self) -> Boolean {
todo!()
}
/// name of the project
pub fn name(&self) -> String {
todo!()
}
/// schema provided by the project
pub fn schema(&self) -> String {
todo!()
}
/// sdk used to generate code for and/or execute this project
pub fn sdk(&self) -> String {
todo!()
}
}
impl Input for Project {}
/// An OCI-compatible container, also known as a docker container. /// An OCI-compatible container, also known as a docker container.
pub struct Container {} pub struct Container {}
@ -315,14 +469,14 @@ impl Container {
&self, &self,
context: DirectoryID, context: DirectoryID,
dockerfile: String, dockerfile: String,
build_args: Option<BuildArg>, build_args: Vec<BuildArg>,
target: String, target: String,
) -> Container { ) -> Container {
todo!() todo!()
} }
/// Retrieves default arguments for future commands. /// Retrieves default arguments for future commands.
pub fn default_args(&self) -> Option<String> { pub fn default_args(&self) -> Vec<String> {
todo!() todo!()
} }
@ -332,7 +486,7 @@ impl Container {
} }
/// Retrieves entrypoint to be prepended to the arguments of all commands. /// Retrieves entrypoint to be prepended to the arguments of all commands.
pub fn entrypoint(&self) -> Option<String> { pub fn entrypoint(&self) -> Vec<String> {
todo!() todo!()
} }
@ -342,7 +496,7 @@ impl Container {
} }
/// Retrieves the list of environment variables passed to commands. /// Retrieves the list of environment variables passed to commands.
pub fn env_variables(&self) -> Option<EnvVariable> { pub fn env_variables(&self) -> Vec<EnvVariable> {
todo!() todo!()
} }
@ -363,7 +517,7 @@ impl Container {
/// The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM. /// The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.
pub fn exec( pub fn exec(
&self, &self,
args: Option<String>, args: Vec<String>,
stdin: String, stdin: String,
redirect_stdout: String, redirect_stdout: String,
redirect_stderr: String, redirect_stderr: String,
@ -388,7 +542,7 @@ impl Container {
/// * `platformVariants` - Identifiers for other platform specific containers. /// * `platformVariants` - Identifiers for other platform specific containers.
/// Identifiers for other platform specific containers. /// Identifiers for other platform specific containers.
/// Used for multi-platform image. /// Used for multi-platform image.
pub fn export(&self, path: String, platform_variants: Option<ContainerID>) -> Boolean { pub fn export(&self, path: String, platform_variants: Vec<ContainerID>) -> Boolean {
todo!() todo!()
} }
@ -423,12 +577,12 @@ impl Container {
} }
/// Retrieves the list of labels passed to container. /// Retrieves the list of labels passed to container.
pub fn labels(&self) -> Option<Label> { pub fn labels(&self) -> Vec<Label> {
todo!() todo!()
} }
/// Retrieves the list of paths where a directory is mounted. /// Retrieves the list of paths where a directory is mounted.
pub fn mounts(&self) -> Option<String> { pub fn mounts(&self) -> Vec<String> {
todo!() todo!()
} }
@ -451,7 +605,7 @@ impl Container {
/// * `platformVariants` - Identifiers for other platform specific containers. /// * `platformVariants` - Identifiers for other platform specific containers.
/// Identifiers for other platform specific containers. /// Identifiers for other platform specific containers.
/// Used for multi-platform image. /// Used for multi-platform image.
pub fn publish(&self, address: String, platform_variants: Option<ContainerID>) -> String { pub fn publish(&self, address: String, platform_variants: Vec<ContainerID>) -> String {
todo!() todo!()
} }
@ -478,7 +632,7 @@ impl Container {
} }
/// Configures default arguments for future commands. /// Configures default arguments for future commands.
pub fn with_default_args(&self, args: Option<String>) -> Container { pub fn with_default_args(&self, args: Vec<String>) -> Container {
todo!() todo!()
} }
@ -487,14 +641,14 @@ impl Container {
&self, &self,
path: String, path: String,
directory: DirectoryID, directory: DirectoryID,
exclude: Option<String>, exclude: Vec<String>,
include: Option<String>, include: Vec<String>,
) -> Container { ) -> Container {
todo!() todo!()
} }
/// Retrieves this container but with a different command entrypoint. /// Retrieves this container but with a different command entrypoint.
pub fn with_entrypoint(&self, args: Option<String>) -> Container { pub fn with_entrypoint(&self, args: Vec<String>) -> Container {
todo!() todo!()
} }
@ -520,7 +674,7 @@ impl Container {
/// The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM. /// The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.
pub fn with_exec( pub fn with_exec(
&self, &self,
args: Option<String>, args: Vec<String>,
stdin: String, stdin: String,
redirect_stdout: String, redirect_stdout: String,
redirect_stderr: String, redirect_stderr: String,
@ -632,178 +786,19 @@ impl Container {
impl Input for Container {} impl Input for Container {}
/// A file. /// A simple key value object that represents a label.
pub struct File {} pub struct Label {}
impl File { impl Label {
/// Retrieves the contents of the file. /// The label name.
pub fn contents(&self) -> String {
todo!()
}
/// Writes the file to a file path on the host.
pub fn export(&self, path: String) -> Boolean {
todo!()
}
/// Retrieves the content-addressed identifier of the file.
pub fn id(&self) -> FileID {
todo!()
}
/// Retrieves a secret referencing the contents of this file.
pub fn secret(&self) -> Secret {
todo!()
}
/// Gets the size of the file, in bytes.
pub fn size(&self) -> Int {
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: Int) -> File {
todo!()
}
}
impl Input for File {}
///
pub struct Socket {}
impl Socket {
/// The content-addressed identifier of the socket.
pub fn id(&self) -> SocketID {
todo!()
}
}
impl Input for Socket {}
///
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: String) -> CacheVolume {
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) -> Container {
todo!()
}
/// The default platform of the builder.
pub fn default_platform(&self) -> Platform {
todo!()
}
/// Load a directory by ID. No argument produces an empty directory.
pub fn directory(&self, id: DirectoryID) -> Directory {
todo!()
}
/// Loads a file by ID.
pub fn file(&self, id: FileID) -> File {
todo!()
}
/// Queries a git repository.
pub fn git(&self, url: String, keep_git_dir: Boolean) -> GitRepository {
todo!()
}
/// Queries the host environment.
pub fn host(&self) -> Host {
todo!()
}
/// Returns a file containing an http remote url content.
pub fn http(&self, url: String) -> File {
todo!()
}
/// Creates a named sub-pipeline
pub fn pipeline(&self, name: String, description: String) -> Query {
todo!()
}
/// Look up a project by name
pub fn project(&self, name: String) -> Project {
todo!()
}
/// Loads a secret from its ID.
pub fn secret(&self, id: SecretID) -> Secret {
todo!()
}
/// Loads a socket by its ID.
pub fn socket(&self, id: SocketID) -> Socket {
todo!()
}
}
impl Input for Query {}
/// A set of scripts and/or extensions
pub struct Project {}
impl Project {
/// extensions in this project
pub fn extensions(&self) -> Option<Project> {
todo!()
}
/// Code files generated by the SDKs in the project
pub fn generated_code(&self) -> Directory {
todo!()
}
/// install the project's schema
pub fn install(&self) -> Boolean {
todo!()
}
/// name of the project
pub fn name(&self) -> String { pub fn name(&self) -> String {
todo!() todo!()
} }
/// schema provided by the project /// The label value.
pub fn schema(&self) -> String {
todo!()
}
/// sdk used to generate code for and/or execute this project
pub fn sdk(&self) -> String {
todo!()
}
}
impl Input for Project {}
/// A simple key value object that represents an environment variable.
pub struct EnvVariable {}
impl EnvVariable {
/// The environment variable name.
pub fn name(&self) -> String {
todo!()
}
/// The environment variable value.
pub fn value(&self) -> String { pub fn value(&self) -> String {
todo!() todo!()
} }
} }
impl Input for EnvVariable {} impl Input for Label {}