diff --git a/benches/data_loader_bench.rs b/benches/data_loader_bench.rs index 97f3db6b61..74cb32fdb1 100644 --- a/benches/data_loader_bench.rs +++ b/benches/data_loader_bench.rs @@ -10,9 +10,10 @@ use async_trait::async_trait; use criterion::Criterion; use hyper::body::Bytes; use reqwest::Request; -use tailcall::{ - Batch, DataLoaderRequest, EnvIO, FileIO, HttpDataLoader, HttpIO, Response, TargetRuntime, -}; +use tailcall::core::config::Batch; +use tailcall::core::http::{DataLoaderRequest, HttpDataLoader, Response}; +use tailcall::core::runtime::TargetRuntime; +use tailcall::core::{EnvIO, FileIO, HttpIO}; #[derive(Clone)] struct MockHttpClient { @@ -50,7 +51,7 @@ impl FileIO for File { struct Cache; #[async_trait] -impl tailcall::Cache for Cache { +impl tailcall::core::Cache for Cache { type Key = u64; type Value = ConstValue; diff --git a/benches/handle_request_bench.rs b/benches/handle_request_bench.rs index 612931d1f0..0c4940a274 100644 --- a/benches/handle_request_bench.rs +++ b/benches/handle_request_bench.rs @@ -3,7 +3,11 @@ use std::sync::Arc; use criterion::Criterion; use hyper::Request; use tailcall::cli::server::server_config::ServerConfig; -use tailcall::{handle_request, Blueprint, Config, ConfigModule, GraphQLRequest, Validator}; +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; static QUERY: &str = r#"{"query":"query{posts{title}}"}"#; diff --git a/benches/impl_path_string_for_evaluation_context.rs b/benches/impl_path_string_for_evaluation_context.rs index f4302f2fb9..e77a88a404 100644 --- a/benches/impl_path_string_for_evaluation_context.rs +++ b/benches/impl_path_string_for_evaluation_context.rs @@ -15,10 +15,13 @@ use indexmap::IndexMap; use once_cell::sync::Lazy; use reqwest::{Client, Request}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; -use tailcall::{ - EnvIO, EvaluationContext, FileIO, HttpIO, InMemoryCache, PathString, RequestContext, - ResolverContextLike, Response, Server, TargetRuntime, Upstream, -}; +use tailcall::core::blueprint::{Server, Upstream}; +use tailcall::core::cache::InMemoryCache; +use tailcall::core::http::{RequestContext, Response}; +use tailcall::core::lambda::{EvaluationContext, ResolverContextLike}; +use tailcall::core::path::PathString; +use tailcall::core::runtime::TargetRuntime; +use tailcall::core::{EnvIO, FileIO, HttpIO}; struct Http { client: ClientWithMiddleware, @@ -228,7 +231,7 @@ fn assert_test(eval_ctx: &EvaluationContext<'_, MockGraphqlContext>) { } fn request_context() -> RequestContext { - let config_module = tailcall::ConfigModule::default(); + let config_module = tailcall::core::config::ConfigModule::default(); //TODO: default is used only in tests. Drop default and move it to test. let upstream = Upstream::try_from(&config_module).unwrap(); diff --git a/benches/json_like_bench.rs b/benches/json_like_bench.rs index 9562412972..aae01908fb 100644 --- a/benches/json_like_bench.rs +++ b/benches/json_like_bench.rs @@ -1,6 +1,6 @@ use criterion::{black_box, Criterion}; use serde_json::json; -use tailcall::JsonLike; +use tailcall::core::json::{gather_path_matches, JsonLike}; pub fn benchmark_batched_body(c: &mut Criterion) { c.bench_function("test_batched_body", |b| { @@ -19,7 +19,7 @@ pub fn benchmark_batched_body(c: &mut Criterion) { }); black_box( - serde_json::to_value(tailcall::gather_path_matches( + serde_json::to_value(gather_path_matches( &input, &["data".into(), "user".into(), "id".into()], vec![], diff --git a/benches/protobuf_convert_output.rs b/benches/protobuf_convert_output.rs index 9dc4df1416..a83d53fa19 100644 --- a/benches/protobuf_convert_output.rs +++ b/benches/protobuf_convert_output.rs @@ -4,7 +4,8 @@ use anyhow::Result; use criterion::{black_box, Criterion}; use rand::{thread_rng, Fill}; use serde_json::{json, Value}; -use tailcall::{GrpcMethod, ProtobufSet}; +use tailcall::core::blueprint::GrpcMethod; +use tailcall::core::grpc::protobuf::ProtobufSet; const PROTO_DIR: &str = "benches/grpc"; const PROTO_FILE: &str = "dummy.proto"; diff --git a/benches/request_template_bench.rs b/benches/request_template_bench.rs index 9300ddc9d1..61c9e1f9bd 100644 --- a/benches/request_template_bench.rs +++ b/benches/request_template_bench.rs @@ -4,7 +4,10 @@ use criterion::{black_box, Criterion}; use derive_setters::Setters; use hyper::HeaderMap; use serde_json::json; -use tailcall::{Endpoint, HasHeaders, PathString, RequestTemplate}; +use tailcall::core::endpoint::Endpoint; +use tailcall::core::has_headers::HasHeaders; +use tailcall::core::http::RequestTemplate; +use tailcall::core::path::PathString; #[derive(Setters)] struct Context { diff --git a/src/lib.rs b/src/lib.rs index 41eae53292..e9a73c0ecf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,37 +1,4 @@ -mod core; +pub mod core; #[cfg(feature = "cli")] pub mod cli; - -// export only what's requried outside. -pub use core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest}; -pub use core::blueprint::{ - Blueprint, Definition, DynamicValue, GrpcMethod, Script, Server, Type, Upstream, -}; -pub use core::cache::InMemoryCache; -pub use core::config::reader::ConfigReader; -pub use core::config::{Batch, Config, ConfigModule, Source}; -pub use core::endpoint::Endpoint; -pub use core::generator::Generator; -pub use core::grpc::protobuf::ProtobufSet; -pub use core::has_headers::HasHeaders; -pub use core::http::{ - handle_request, showcase, AppContext, DataLoaderRequest, HttpDataLoader, Method, - RequestContext, RequestTemplate, Response, API_URL_PREFIX, -}; -pub use core::json::{gather_path_matches, JsonLike}; -pub use core::lambda::{ - EmptyResolverContext, Eval, EvaluationContext, EvaluationError, Expression, ResolverContextLike, -}; -pub use core::merge_right::MergeRight; -pub use core::mustache::Mustache; -pub use core::path::PathString; -pub use core::print_schema::print_schema; -pub use core::runtime::TargetRuntime; -pub use core::scalar::{is_predefined_scalar, CUSTOM_SCALARS}; -pub use core::tracing::{ - default_tracing, default_tracing_for_name, default_tracing_tailcall, get_log_level, - tailcall_filter_target, -}; -pub use core::valid::{Cause, ValidationError, Validator}; -pub use core::{Cache, EntityCache, EnvIO, FileIO, HttpIO, WorkerIO}; diff --git a/src/main.rs b/src/main.rs index 331857a4ff..0129356730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::cell::Cell; use mimalloc::MiMalloc; use tailcall::cli::CLIError; -use tailcall::default_tracing_tailcall; +use tailcall::core::tracing::default_tracing_tailcall; use tracing::subscriber::DefaultGuard; #[global_allocator] diff --git a/tailcall-aws-lambda/src/http.rs b/tailcall-aws-lambda/src/http.rs index 16a49b53fb..4cbdf82b37 100644 --- a/tailcall-aws-lambda/src/http.rs +++ b/tailcall-aws-lambda/src/http.rs @@ -4,7 +4,8 @@ use anyhow::Result; use hyper::body::Bytes; use lambda_http::RequestExt; use reqwest::Client; -use tailcall::{HttpIO, Response}; +use tailcall::core::http::Response; +use tailcall::core::HttpIO; #[derive(Clone)] pub struct LambdaHttp { diff --git a/tailcall-aws-lambda/src/main.rs b/tailcall-aws-lambda/src/main.rs index a8b7eb995d..6965a7c1cd 100644 --- a/tailcall-aws-lambda/src/main.rs +++ b/tailcall-aws-lambda/src/main.rs @@ -4,9 +4,11 @@ use dotenvy::dotenv; use http::{to_request, to_response}; use lambda_http::{run, service_fn, Body, Error, Response}; use runtime::init_runtime; -use tailcall::{ - get_log_level, handle_request, AppContext, Blueprint, ConfigReader, GraphQLRequest, -}; +use tailcall::core::async_graphql_hyper::GraphQLRequest; +use tailcall::core::blueprint::Blueprint; +use tailcall::core::config::reader::ConfigReader; +use tailcall::core::http::{handle_request, AppContext}; +use tailcall::core::tracing::get_log_level; mod http; mod runtime; diff --git a/tailcall-aws-lambda/src/runtime.rs b/tailcall-aws-lambda/src/runtime.rs index 12d19108ac..18a26273d3 100644 --- a/tailcall-aws-lambda/src/runtime.rs +++ b/tailcall-aws-lambda/src/runtime.rs @@ -2,7 +2,9 @@ use std::borrow::Cow; use std::sync::Arc; use anyhow::anyhow; -use tailcall::{EntityCache, EnvIO, FileIO, InMemoryCache, TargetRuntime}; +use tailcall::core::cache::InMemoryCache; +use tailcall::core::runtime::TargetRuntime; +use tailcall::core::{EntityCache, EnvIO, FileIO}; use tokio::io::AsyncReadExt; use crate::http::init_http; diff --git a/tailcall-cloudflare/src/cache.rs b/tailcall-cloudflare/src/cache.rs index df575f9ee2..9cba4063af 100644 --- a/tailcall-cloudflare/src/cache.rs +++ b/tailcall-cloudflare/src/cache.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use anyhow::Result; use async_graphql_value::ConstValue; use serde_json::Value; -use tailcall::Cache; +use tailcall::core::Cache; use worker::kv::KvStore; use crate::to_anyhow; diff --git a/tailcall-cloudflare/src/env.rs b/tailcall-cloudflare/src/env.rs index db6bc0007c..51838efac2 100644 --- a/tailcall-cloudflare/src/env.rs +++ b/tailcall-cloudflare/src/env.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::rc::Rc; -use tailcall::EnvIO; +use tailcall::core::EnvIO; use worker::Env; pub struct CloudflareEnv { diff --git a/tailcall-cloudflare/src/file.rs b/tailcall-cloudflare/src/file.rs index e8bbe30a40..4bb56d3d6e 100644 --- a/tailcall-cloudflare/src/file.rs +++ b/tailcall-cloudflare/src/file.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use anyhow::anyhow; use async_std::task::spawn_local; -use tailcall::FileIO; +use tailcall::core::FileIO; use worker::Env; use crate::to_anyhow; diff --git a/tailcall-cloudflare/src/handle.rs b/tailcall-cloudflare/src/handle.rs index 07b01d44c4..1a1f990ae2 100644 --- a/tailcall-cloudflare/src/handle.rs +++ b/tailcall-cloudflare/src/handle.rs @@ -4,7 +4,8 @@ use std::sync::{Arc, RwLock}; use hyper::{Body, Request, Response}; use lazy_static::lazy_static; -use tailcall::{handle_request, showcase, AppContext, GraphQLRequest}; +use tailcall::core::async_graphql_hyper::GraphQLRequest; +use tailcall::core::http::{handle_request, showcase, AppContext}; use crate::http::{to_request, to_response}; use crate::runtime; diff --git a/tailcall-cloudflare/src/http.rs b/tailcall-cloudflare/src/http.rs index 188d5cca81..3f87fe4377 100644 --- a/tailcall-cloudflare/src/http.rs +++ b/tailcall-cloudflare/src/http.rs @@ -2,7 +2,8 @@ use anyhow::{anyhow, Result}; use async_std::task::spawn_local; use hyper::body::Bytes; use reqwest::Client; -use tailcall::{HttpIO, Response}; +use tailcall::core::http::Response; +use tailcall::core::HttpIO; use crate::to_anyhow; diff --git a/tailcall-cloudflare/src/runtime.rs b/tailcall-cloudflare/src/runtime.rs index 11edc3b935..3ad5c874df 100644 --- a/tailcall-cloudflare/src/runtime.rs +++ b/tailcall-cloudflare/src/runtime.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use anyhow::anyhow; use async_graphql_value::ConstValue; -use tailcall::{EnvIO, FileIO, HttpIO, TargetRuntime}; +use tailcall::core::runtime::TargetRuntime; +use tailcall::core::{EnvIO, FileIO, HttpIO}; use crate::{cache, env, file, http}; @@ -19,7 +20,9 @@ fn init_http() -> Arc { Arc::new(http::CloudflareHttp::init()) } -fn init_cache(env: Rc) -> Arc> { +fn init_cache( + env: Rc, +) -> Arc> { Arc::new(cache::CloudflareChronoCache::init(env)) } diff --git a/tailcall-query-plan/src/execution/executor.rs b/tailcall-query-plan/src/execution/executor.rs index 0e2702608b..99cb643610 100644 --- a/tailcall-query-plan/src/execution/executor.rs +++ b/tailcall-query-plan/src/execution/executor.rs @@ -6,7 +6,8 @@ use async_graphql::{Name, Value}; use dashmap::DashMap; use futures_util::future::{join_all, try_join_all}; use indexmap::IndexMap; -use tailcall::{EvaluationContext, RequestContext, ResolverContextLike}; +use tailcall::core::http::RequestContext; +use tailcall::core::lambda::{EvaluationContext, ResolverContextLike}; use super::step::ExecutionStep; use crate::plan::{GeneralPlan, OperationPlan}; diff --git a/tailcall-query-plan/src/plan.rs b/tailcall-query-plan/src/plan.rs index 85c5d4f5e5..204be48317 100644 --- a/tailcall-query-plan/src/plan.rs +++ b/tailcall-query-plan/src/plan.rs @@ -5,7 +5,8 @@ use async_graphql::parser::types::{Selection, SelectionSet}; use async_graphql::{Name, Value}; use indenter::indented; use indexmap::IndexMap; -use tailcall::{is_predefined_scalar, Definition, Type}; +use tailcall::core::blueprint::{Definition, Type}; +use tailcall::core::scalar::is_predefined_scalar; use super::execution::executor::{ExecutionResult, ResolvedEntry}; use super::resolver::{FieldPlan, FieldPlanSelection, Id}; diff --git a/tailcall-query-plan/src/resolver.rs b/tailcall-query-plan/src/resolver.rs index 33cca0b241..b4452e48db 100644 --- a/tailcall-query-plan/src/resolver.rs +++ b/tailcall-query-plan/src/resolver.rs @@ -5,7 +5,7 @@ use anyhow::Result; use async_graphql::parser::types::{Field, Selection, SelectionSet}; use async_graphql::{Positioned, Value}; use indenter::indented; -use tailcall::{Eval, EvaluationContext, Expression, ResolverContextLike}; +use tailcall::core::lambda::{Eval, EvaluationContext, Expression, ResolverContextLike}; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Id(pub usize); diff --git a/tailcall-query-plan/tests/execution.rs b/tailcall-query-plan/tests/execution.rs index 36f6dacda5..e08e0a64dd 100644 --- a/tailcall-query-plan/tests/execution.rs +++ b/tailcall-query-plan/tests/execution.rs @@ -2,7 +2,10 @@ use std::fs; use std::path::Path; use async_graphql::parser::parse_query; -use tailcall::{Blueprint, Config, ConfigModule, RequestContext, Validator}; +use tailcall::core::blueprint::Blueprint; +use tailcall::core::config::{Config, ConfigModule}; +use tailcall::core::http::RequestContext; +use tailcall::core::valid::Validator; use tailcall_query_plan::execution::executor::Executor; use tailcall_query_plan::execution::simple::SimpleExecutionBuilder; use tailcall_query_plan::plan::{GeneralPlan, OperationPlan}; diff --git a/tailcall-typedefs/src/gen_gql_schema.rs b/tailcall-typedefs/src/gen_gql_schema.rs index b884000889..f4090605a2 100644 --- a/tailcall-typedefs/src/gen_gql_schema.rs +++ b/tailcall-typedefs/src/gen_gql_schema.rs @@ -8,7 +8,8 @@ use schemars::schema::{ ArrayValidation, InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec, }; use schemars::Map; -use tailcall::{Config, CUSTOM_SCALARS}; +use tailcall::core::config::Config; +use tailcall::core::scalar::CUSTOM_SCALARS; static GRAPHQL_SCHEMA_FILE: &str = "generated/.tailcallrc.graphql"; diff --git a/tailcall-typedefs/src/main.rs b/tailcall-typedefs/src/main.rs index 670b0c8894..a365f7347d 100644 --- a/tailcall-typedefs/src/main.rs +++ b/tailcall-typedefs/src/main.rs @@ -9,7 +9,10 @@ use gen_gql_schema::update_gql; use schemars::schema::{RootSchema, Schema}; use schemars::Map; use serde_json::{json, Value}; -use tailcall::{cli, default_tracing_for_name, Config, CUSTOM_SCALARS}; +use tailcall::cli; +use tailcall::core::config::Config; +use tailcall::core::scalar::CUSTOM_SCALARS; +use tailcall::core::tracing::default_tracing_for_name; static JSON_SCHEMA_FILE: &str = "../generated/.tailcallrc.schema.json"; diff --git a/tests/core/env.rs b/tests/core/env.rs index 51f099372b..7af2cd3907 100644 --- a/tests/core/env.rs +++ b/tests/core/env.rs @@ -3,7 +3,7 @@ extern crate core; use std::borrow::Cow; use std::collections::HashMap; -use tailcall::EnvIO; +use tailcall::core::EnvIO; #[derive(Clone)] pub struct Env { diff --git a/tests/core/file.rs b/tests/core/file.rs index e784ed306c..574bd38c5b 100644 --- a/tests/core/file.rs +++ b/tests/core/file.rs @@ -3,7 +3,7 @@ extern crate core; use std::path::PathBuf; use anyhow::{anyhow, Context}; -use tailcall::FileIO; +use tailcall::core::FileIO; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use super::runtime::ExecutionSpec; diff --git a/tests/core/http.rs b/tests/core/http.rs index 31a110940f..87192a62b8 100644 --- a/tests/core/http.rs +++ b/tests/core/http.rs @@ -8,7 +8,8 @@ use std::sync::Arc; use anyhow::anyhow; use hyper::body::Bytes; use reqwest::header::{HeaderName, HeaderValue}; -use tailcall::{HttpIO, Response}; +use tailcall::core::http::Response; +use tailcall::core::HttpIO; use super::runtime::{ExecutionMock, ExecutionSpec}; diff --git a/tests/core/model.rs b/tests/core/model.rs index 404fef92ac..bac0edc406 100644 --- a/tests/core/model.rs +++ b/tests/core/model.rs @@ -4,7 +4,7 @@ use std::path::Path; use serde::{Deserialize, Serialize}; use serde_json::Value; -use tailcall::Method; +use tailcall::core::http::Method; use url::Url; #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/tests/core/parse.rs b/tests/core/parse.rs index 2a6d456daa..705ffaa897 100644 --- a/tests/core/parse.rs +++ b/tests/core/parse.rs @@ -11,7 +11,12 @@ use anyhow::anyhow; use markdown::mdast::Node; use markdown::ParseOptions; use tailcall::cli::javascript; -use tailcall::{AppContext, Blueprint, ConfigModule, EnvIO, InMemoryCache, Source, TargetRuntime}; +use tailcall::core::blueprint::Blueprint; +use tailcall::core::cache::InMemoryCache; +use tailcall::core::config::{ConfigModule, Source}; +use tailcall::core::http::AppContext; +use tailcall::core::runtime::TargetRuntime; +use tailcall::core::EnvIO; use super::file::File; use super::http::Http; diff --git a/tests/core/runtime.rs b/tests/core/runtime.rs index 2931b9e44c..74fa1402c0 100644 --- a/tests/core/runtime.rs +++ b/tests/core/runtime.rs @@ -7,7 +7,10 @@ use std::sync::Arc; use derive_setters::Setters; use tailcall::cli::javascript; -use tailcall::{InMemoryCache, Script, Source, TargetRuntime}; +use tailcall::core::blueprint::Script; +use tailcall::core::cache::InMemoryCache; +use tailcall::core::config::Source; +use tailcall::core::runtime::TargetRuntime; use super::env::Env; use super::file::TestFileIO; diff --git a/tests/core/spec.rs b/tests/core/spec.rs index 48f8174b8c..d85886d00d 100644 --- a/tests/core/spec.rs +++ b/tests/core/spec.rs @@ -10,10 +10,14 @@ use colored::Colorize; use futures_util::future::join_all; use hyper::{Body, Request}; use serde::{Deserialize, Serialize}; -use tailcall::{ - handle_request, print_schema, AppContext, Blueprint, Cause, Config, ConfigModule, ConfigReader, - GraphQLBatchRequest, GraphQLRequest, MergeRight, Source, ValidationError, -}; +use tailcall::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest}; +use tailcall::core::blueprint::Blueprint; +use tailcall::core::config::reader::ConfigReader; +use tailcall::core::config::{Config, ConfigModule, Source}; +use tailcall::core::http::{handle_request, AppContext}; +use tailcall::core::merge_right::MergeRight; +use tailcall::core::print_schema::print_schema; +use tailcall::core::valid::{Cause, ValidationError}; use super::file::File; use super::http::Http; diff --git a/tests/expression_spec.rs b/tests/expression_spec.rs index 2dda883722..e83dc45029 100644 --- a/tests/expression_spec.rs +++ b/tests/expression_spec.rs @@ -3,10 +3,12 @@ mod tests { use async_graphql::Value; use pretty_assertions::assert_eq; use serde_json::json; - use tailcall::{ - Blueprint, DynamicValue, EmptyResolverContext, Eval, EvaluationContext, EvaluationError, - Expression, Mustache, RequestContext, + use tailcall::core::blueprint::{Blueprint, DynamicValue}; + use tailcall::core::http::RequestContext; + use tailcall::core::lambda::{ + EmptyResolverContext, Eval, EvaluationContext, EvaluationError, Expression, }; + use tailcall::core::mustache::Mustache; async fn eval(expr: &Expression) -> Result { let runtime = tailcall::cli::runtime::init(&Blueprint::default()); diff --git a/tests/server_spec.rs b/tests/server_spec.rs index 4fd55d53fd..02b32dbaec 100644 --- a/tests/server_spec.rs +++ b/tests/server_spec.rs @@ -1,5 +1,3 @@ -use tailcall::{EnvIO, FileIO, HttpIO, Upstream}; - #[cfg(test)] pub mod test { use std::borrow::Cow; @@ -13,11 +11,13 @@ pub mod test { use reqwest::Client; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use tailcall::cli::javascript; - use tailcall::{InMemoryCache, Response, Script, TargetRuntime}; + use tailcall::core::blueprint::{Script, Upstream}; + use tailcall::core::cache::InMemoryCache; + use tailcall::core::http::Response; + use tailcall::core::runtime::TargetRuntime; + use tailcall::core::{EnvIO, FileIO, HttpIO}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; - use crate::{EnvIO, FileIO, HttpIO, Upstream}; - #[derive(Clone)] struct TestHttp { client: ClientWithMiddleware, @@ -162,7 +162,7 @@ mod server_spec { use reqwest::Client; use serde_json::json; use tailcall::cli::server::Server; - use tailcall::ConfigReader; + use tailcall::core::config::reader::ConfigReader; async fn test_server(configs: &[&str], url: &str) { let runtime = crate::test::init(None);