Skip to content

Commit

Permalink
chore: move valid to new repo (#3003)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
Co-authored-by: laststylebender <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: neo773 <[email protected]>
Co-authored-by: Dhanus <[email protected]>
  • Loading branch information
6 people authored Nov 3, 2024
1 parent cc911a3 commit 30e7617
Show file tree
Hide file tree
Showing 98 changed files with 197 additions and 865 deletions.
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 @@ fn ensure_usable_cors_rules(layer: &Cors) -> Result<(), ValidationError<String>>
Ok(())
}

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

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

1 comment on commit 30e7617

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 8.67ms 3.77ms 124.12ms 90.46%
Req/Sec 2.94k 386.50 4.08k 80.75%

351518 requests in 30.02s, 1.76GB read

Requests/sec: 11707.77

Transfer/sec: 60.09MB

Please sign in to comment.