Skip to content

Commit

Permalink
chore: move valid to new repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Oct 12, 2024
1 parent 1679aea commit 64c2756
Show file tree
Hide file tree
Showing 90 changed files with 139 additions and 852 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ num = "0.4.3"
indenter = "0.3.3"
derive_more = { workspace = true }
strum = "0.26.2"
tailcall-valid = {git = "https://github.com/tailcallhq/valid.git"}

[dev-dependencies]
datatest-stable = "0.2.9"
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 @@ -12,7 +12,7 @@ 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};
use tailcall_valid::{Valid, ValidateFrom, Validator};

#[derive(Deserialize, Serialize, Debug, Default, Setters)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -277,7 +277,7 @@ mod tests {
use pretty_assertions::assert_eq;

use super::*;
use crate::core::valid::{ValidateInto, ValidationError, Validator};
use tailcall_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 @@ -14,7 +14,7 @@ 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 tailcall_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 @@ -4,7 +4,7 @@ use std::fmt::Debug;
use jsonwebtoken::jwk::JwkSet;

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

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Basic {
Expand Down
19 changes: 12 additions & 7 deletions src/core/blueprint/cors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::fmt::Display;
use derive_setters::Setters;
use http::header;
use http::header::{HeaderName, HeaderValue};
use http::request::Parts;

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

#[derive(Clone, Debug, Setters, Default)]
pub struct Cors {
Expand Down Expand Up @@ -155,39 +156,43 @@ 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()?),
.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| Ok(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| Ok(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 @@ -11,7 +11,7 @@ use crate::core::config::{Config, Enum, Field, GraphQLOperationType, Protected,
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 tailcall_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 @@ -4,7 +4,7 @@ use async_graphql::parser::types::ConstDirective;
use async_graphql::Name;
use serde_json::Value;

use crate::core::valid::{Valid, ValidationError, Validator};
use tailcall_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 @@ -12,7 +12,7 @@ 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 tailcall_valid::{Valid, ValidationError, Validator};
use crate::core::Type;

pub fn config_blueprint<'a>() -> TryFold<'a, ConfigModule, Blueprint, String> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/interface_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::core::config::{ConfigModule, Field};
use crate::core::ir::model::IR;
use crate::core::ir::Discriminator;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};

fn compile_interface_resolver(
config: &ConfigModule,
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 @@ -10,7 +10,7 @@ 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;
use tailcall_valid::Validator;

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

pub struct Links;

Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/mustache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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};
use tailcall_valid::{Valid, Validator};

struct MustachePartsValidator<'a> {
type_of: &'a config::Type,
Expand Down Expand Up @@ -182,7 +182,7 @@ mod test {
use super::MustachePartsValidator;
use crate::core::blueprint::{FieldDefinition, InputFieldDefinition};
use crate::core::config::{self, Config, Field};
use crate::core::valid::Validator;
use tailcall_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 @@ -9,7 +9,7 @@ use crate::core::config::{
ApolloFederation, ConfigModule, EntityResolver, Field, GraphQLOperationType, Resolver,
};
use crate::core::ir::model::IR;
use crate::core::valid::{Valid, Validator};
use tailcall_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
Expand Up @@ -5,7 +5,7 @@ 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};
use tailcall_valid::{Valid, ValidationError, Validator};

pub fn update_call<'a>(
operation_type: &'a GraphQLOperationType,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/enum_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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;
use tailcall_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
Expand Up @@ -6,7 +6,7 @@ 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};
use tailcall_valid::{Valid, ValidationError, Validator};

fn validate_data_with_schema(
config: &config::Config,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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};
use tailcall_valid::{Valid, ValidationError, Validator};

fn create_related_fields(
config: &Config,
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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 tailcall_valid::{Valid, ValidationError, Validator};
use crate::core::{config, helpers};

fn to_url(grpc: &Grpc, method: &GrpcMethod, config: &Config) -> Valid<Mustache, String> {
Expand Down Expand Up @@ -246,7 +246,7 @@ mod tests {
use std::convert::TryFrom;

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

#[test]
fn try_from_grpc_method() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::core::endpoint::Endpoint;
use crate::core::http::{HttpFilter, Method, RequestTemplate};
use crate::core::ir::model::{IO, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};
use tailcall_valid::{Valid, ValidationError, Validator};
use crate::core::{config, helpers, Mustache};

pub fn compile_http(
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::config;
use crate::core::config::{ConfigModule, Field, Resolver, JS};
use crate::core::ir::model::{IO, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};

pub struct CompileJs<'a> {
pub js: &'a JS,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::config;
use crate::core::config::Field;
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;
use tailcall_valid::Valid;

pub fn update_modify<'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/protected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::core::blueprint::FieldDefinition;
use crate::core::config::{self, ConfigModule, Field};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;
use tailcall_valid::Valid;

pub fn update_protected<'a>(
type_name: &'a str,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde_json::Value;

use crate::core::blueprint::DynamicValue;
use crate::core::ir::model::IR;
use crate::core::valid::Valid;
use tailcall_valid::Valid;

pub fn apply_select(input: (IR, &Option<Value>)) -> Valid<IR, String> {
let (mut ir, select) = input;
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use directive::to_directive;
use crate::core::blueprint::*;
use crate::core::config::{Config, Field, Type};
use crate::core::directive::DirectiveCodec;
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};

fn validate_query(config: &Config) -> Valid<(), String> {
Valid::from_option(
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustls_pki_types::CertificateDer;
use super::Auth;
use crate::core::blueprint::Cors;
use crate::core::config::{self, ConfigModule, HttpVersion, PrivateKey, Routes};
use crate::core::valid::{Valid, ValidationError, Validator};
use tailcall_valid::{Valid, ValidationError, Validator};

#[derive(Clone, Debug, Setters)]
pub struct Server {
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core::config::{
};
use crate::core::directive::DirectiveCodec;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, ValidationError, Validator};
use tailcall_valid::{Valid, ValidationError, Validator};

#[derive(Debug, Clone)]
pub struct OtlpExporter {
Expand Down Expand Up @@ -100,7 +100,7 @@ fn validate_graph_ref(graph_ref: &str) -> Valid<(), String> {
#[cfg(test)]
mod tests {
use super::validate_graph_ref;
use crate::core::valid::Valid;
use tailcall_valid::Valid;

#[test]
fn test_validate_graph_ref() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/union_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::config::{ConfigModule, Field};
use crate::core::ir::model::IR;
use crate::core::ir::Discriminator;
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};

fn compile_union_resolver(
config: &ConfigModule,
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeSet;
use derive_setters::Setters;

use crate::core::config::{self, Batch, ConfigModule};
use crate::core::valid::{Valid, ValidationError, Validator};
use tailcall_valid::{Valid, ValidationError, Validator};

#[derive(PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct Proxy {
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::core::is_default;
use crate::core::macros::MergeRight;
use crate::core::merge_right::MergeRight;
use crate::core::scalar::Scalar;
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};

#[derive(
Serialize,
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/config_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::core::macros::MergeRight;
use crate::core::merge_right::MergeRight;
use crate::core::proto_reader::ProtoMetadata;
use crate::core::rest::{EndpointSet, Unchecked};
use crate::core::valid::{Valid, Validator};
use tailcall_valid::{Valid, Validator};
use crate::core::Transform;

mod merge;
Expand Down
Loading

0 comments on commit 64c2756

Please sign in to comment.