Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move valid to new repo #3003

Merged
merged 17 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ derive_more = "0.99.18"
thiserror = "1.0.59"
url = { version = "2.5.0", features = ["serde"] }
convert_case = "0.6.0"
tailcall-valid = "0.1.1"

[dependencies]
# dependencies specific to CLI must have optional = true and the dep should be added to default feature.
Expand Down Expand Up @@ -169,6 +170,7 @@ num = "0.4.3"
indenter = "0.3.3"
derive_more = { workspace = true }
strum = "0.26.2"
tailcall-valid = { workspace = true }
dashmap = "6.1.0"
urlencoding = "2.1.3"

Expand Down
2 changes: 1 addition & 1 deletion benches/handle_request_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tailcall::core::async_graphql_hyper::GraphQLRequest;
use tailcall::core::blueprint::Blueprint;
use tailcall::core::config::{Config, ConfigModule};
use tailcall::core::http::handle_request;
use tailcall::core::valid::Validator;
use tailcall_valid::Validator;

static QUERY: &str = r#"{"query":"query{posts{title}}"}"#;

Expand Down
4 changes: 2 additions & 2 deletions src/cli/generator/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use derive_setters::Setters;
use path_clean::PathClean;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tailcall_valid::{Valid, ValidateFrom, Validator};
use url::Url;

use crate::core::config::transformer::Preset;
use crate::core::config::{self};
use crate::core::http::Method;
use crate::core::valid::{Valid, ValidateFrom, Validator};

#[derive(Deserialize, Serialize, Debug, Default, Setters)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -268,9 +268,9 @@ mod tests {
use std::collections::HashMap;

use pretty_assertions::assert_eq;
use tailcall_valid::{ValidateInto, ValidationError, Validator};

use super::*;
use crate::core::valid::{ValidateInto, ValidationError, Validator};

fn location<S: AsRef<str>>(s: S) -> Location<UnResolved> {
Location(s.as_ref().to_string(), PhantomData)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::Path;
use http::header::{HeaderMap, HeaderName, HeaderValue};
use inquire::Confirm;
use pathdiff::diff_paths;
use tailcall_valid::{ValidateInto, Validator};

use super::config::{Config, LLMConfig, Resolved, Source};
use super::source::ConfigSource;
Expand All @@ -14,7 +15,6 @@ use crate::core::generator::{Generator as ConfigGenerator, Input};
use crate::core::proto_reader::ProtoReader;
use crate::core::resource_reader::{Resource, ResourceReader};
use crate::core::runtime::TargetRuntime;
use crate::core::valid::{ValidateInto, Validator};
use crate::core::{Mustache, Transform};

/// CLI that reads the the config file and generates the required tailcall
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::HashSet;
use std::fmt::Debug;

use jsonwebtoken::jwk::JwkSet;
use tailcall_valid::Valid;

use crate::core::config::ConfigModule;
use crate::core::valid::Valid;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Basic {
Expand Down
34 changes: 26 additions & 8 deletions src/core/blueprint/cors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::Display;

use derive_setters::Setters;
use http::header;
use http::header::{HeaderName, HeaderValue};
use http::request::Parts;
use tailcall_valid::ValidationError;

use crate::core::config;
use crate::core::valid::ValidationError;

#[derive(Clone, Debug, Setters, Default)]
pub struct Cors {
Expand Down Expand Up @@ -155,39 +157,55 @@
Ok(())
}

fn to_validation_err<T: Display>(err: T) -> ValidationError<String> {
ValidationError::new(err.to_string())
}

Check warning on line 162 in src/core/blueprint/cors.rs

View check run for this annotation

Codecov / codecov/patch

src/core/blueprint/cors.rs#L160-L162

Added lines #L160 - L162 were not covered by tests

impl TryFrom<config::cors::Cors> for Cors {
type Error = ValidationError<String>;

fn try_from(value: config::cors::Cors) -> Result<Self, ValidationError<String>> {
let cors = Cors {
allow_credentials: value.allow_credentials.unwrap_or_default(),
allow_headers: (!value.allow_headers.is_empty())
.then_some(value.allow_headers.join(", ").parse()?),
allow_headers: (!value.allow_headers.is_empty()).then_some(
value
.allow_headers
.join(", ")
.parse()
.map_err(to_validation_err)?,
),
allow_methods: {
Some(if value.allow_methods.is_empty() {
"*".parse()?
"*".parse().map_err(to_validation_err)?
} else {
value
.allow_methods
.into_iter()
.map(|val| val.to_string())
.collect::<Vec<String>>()
.join(", ")
.parse()?
.parse()
.map_err(to_validation_err)?
})
},
allow_origins: value
.allow_origins
.into_iter()
.map(|val| Ok(val.parse()?))
.map(|val| val.parse().map_err(to_validation_err))
.collect::<Result<_, ValidationError<String>>>()?,
allow_private_network: value.allow_private_network.unwrap_or_default(),
expose_headers: Some(value.expose_headers.join(", ").parse()?),
expose_headers: Some(
value
.expose_headers
.join(", ")
.parse()
.map_err(to_validation_err)?,
),
max_age: value.max_age.map(|val| val.into()),
vary: value
.vary
.iter()
.map(|val| Ok(val.parse()?))
.map(|val| val.parse().map_err(to_validation_err))
.collect::<Result<_, ValidationError<String>>>()?,
};
ensure_usable_cors_rules(&cors)?;
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use async_graphql_value::ConstValue;
use directive::Directive;
use interface_resolver::update_interface_resolver;
use regex::Regex;
use tailcall_valid::{Valid, Validator};
use union_resolver::update_union_resolver;

use crate::core::blueprint::*;
use crate::core::config::{Config, Enum, Field, GraphQLOperationType, Protected, Union};
use crate::core::directive::DirectiveCodec;
use crate::core::ir::model::{Cache, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use crate::core::{config, scalar, Type};

pub fn to_scalar_type_definition(name: &str) -> Valid<Definition, String> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use async_graphql::parser::types::ConstDirective;
use async_graphql::Name;
use serde_json::Value;
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::valid::{Valid, ValidationError, Validator};
use crate::core::{config, pos};

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/from_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};

use async_graphql::dynamic::SchemaBuilder;
use indexmap::IndexMap;
use tailcall_valid::{Valid, ValidationError, Validator};

use self::telemetry::to_opentelemetry;
use super::Server;
Expand All @@ -12,7 +13,6 @@ use crate::core::config::{Arg, Batch, Config, ConfigModule};
use crate::core::ir::model::{IO, IR};
use crate::core::json::JsonSchema;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};
use crate::core::Type;

pub fn config_blueprint<'a>() -> TryFold<'a, ConfigModule, Blueprint, String> {
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/interface_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::BTreeSet;

use tailcall_valid::{Valid, Validator};

use crate::core::blueprint::FieldDefinition;
use crate::core::config::{ConfigModule, Discriminate, Field, Type};
use crate::core::ir::model::IR;
use crate::core::ir::Discriminator;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};

fn compile_interface_resolver(
interface_name: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use async_graphql::parser::types::{
};
use async_graphql::{Name, Positioned};
use async_graphql_value::ConstValue;
use tailcall_valid::Validator;

use super::blueprint;
use super::directive::{to_const_directive, Directive};
use crate::core::blueprint::{Blueprint, Definition};
use crate::core::pos;
use crate::core::valid::Validator;

fn to_directives(directives: &[Directive]) -> Vec<Positioned<ConstDirective>> {
directives
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/links.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::config::{Link, LinkType};
use crate::core::directive::DirectiveCodec;
use crate::core::valid::{Valid, ValidationError, Validator};

pub struct Links;

Expand Down
6 changes: 4 additions & 2 deletions src/core/blueprint/mustache.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use tailcall_valid::{Valid, Validator};

use super::FieldDefinition;
use crate::core::config::{self, Config};
use crate::core::ir::model::{IO, IR};
use crate::core::scalar;
use crate::core::valid::{Valid, Validator};

struct MustachePartsValidator<'a> {
type_of: &'a config::Type,
Expand Down Expand Up @@ -179,10 +180,11 @@ impl FieldDefinition {

#[cfg(test)]
mod test {
use tailcall_valid::Validator;

use super::MustachePartsValidator;
use crate::core::blueprint::{FieldDefinition, InputFieldDefinition};
use crate::core::config::{self, Config, Field};
use crate::core::valid::Validator;
use crate::core::Type;

fn initialize_test_config_and_field() -> (Config, FieldDefinition) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/apollo_federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::HashMap;
use std::fmt::Write;

use async_graphql::parser::types::ServiceDocument;
use tailcall_valid::{Valid, Validator};

use super::{compile_call, compile_expr, compile_graphql, compile_grpc, compile_http, compile_js};
use crate::core::blueprint::{Blueprint, Definition, TryFoldConfig};
use crate::core::config::{
ApolloFederation, ConfigModule, EntityResolver, Field, GraphQLOperationType, Resolver,
};
use crate::core::ir::model::IR;
use crate::core::valid::{Valid, Validator};
use crate::core::Type;

pub struct CompileEntityResolver<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/call.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde_json::Value;
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::blueprint::*;
use crate::core::config;
use crate::core::config::{Field, GraphQLOperationType, Resolver};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};

pub fn update_call<'a>(
operation_type: &'a GraphQLOperationType,
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/operators/enum_alias.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::HashMap;

use tailcall_valid::Valid;

use crate::core::blueprint::*;
use crate::core::config;
use crate::core::config::Field;
use crate::core::ir::model::{Map, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;

pub fn update_enum_alias<'a>(
) -> TryFold<'a, (&'a ConfigModule, &'a Field, &'a config::Type, &'a str), FieldDefinition, String>
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/expr.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use async_graphql_value::ConstValue;
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::blueprint::*;
use crate::core::config;
use crate::core::config::{Expr, Field, Resolver};
use crate::core::ir::model::IR;
use crate::core::ir::model::IR::Dynamic;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};

fn validate_data_with_schema(
config: &config::Config,
Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::{HashMap, HashSet};

use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::blueprint::FieldDefinition;
use crate::core::config::{
Config, ConfigModule, Field, GraphQL, GraphQLOperationType, Resolver, Type,
Expand All @@ -9,7 +11,6 @@ use crate::core::helpers;
use crate::core::ir::model::{IO, IR};
use crate::core::ir::RelatedFields;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};

fn create_related_fields(
config: &Config,
Expand Down
5 changes: 3 additions & 2 deletions src/core/blueprint/operators/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;

use prost_reflect::prost_types::FileDescriptorSet;
use prost_reflect::FieldDescriptor;
use tailcall_valid::{Valid, ValidationError, Validator};

use super::apply_select;
use crate::core::blueprint::FieldDefinition;
Expand All @@ -13,7 +14,6 @@ use crate::core::ir::model::{IO, IR};
use crate::core::json::JsonSchema;
use crate::core::mustache::Mustache;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};
use crate::core::{config, helpers};

fn to_url(grpc: &Grpc, method: &GrpcMethod) -> Valid<Mustache, String> {
Expand Down Expand Up @@ -241,8 +241,9 @@ pub fn update_grpc<'a>(
mod tests {
use std::convert::TryFrom;

use tailcall_valid::ValidationError;

use super::GrpcMethod;
use crate::core::valid::ValidationError;

#[test]
fn try_from_grpc_method() {
Expand Down
Loading
Loading