diff --git a/Cargo.lock b/Cargo.lock index 620e88817d..b93f5c779a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6154,8 +6154,8 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e2ee588991b9e7e6c8338edf3333fbe4da35dc72092643958ebb43f0ab2c49c" dependencies = [ - "proc-macro2 1.0.82", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -6165,8 +6165,8 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6fb8df20c9bcaa8ad6ab513f7b40104840c8867d5751126e4df3b08388d0cc7" dependencies = [ - "proc-macro2 1.0.82", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] diff --git a/benches/data_loader_bench.rs b/benches/data_loader_bench.rs index 71a92c233e..a63548319f 100644 --- a/benches/data_loader_bench.rs +++ b/benches/data_loader_bench.rs @@ -9,8 +9,11 @@ use async_graphql_value::ConstValue; use criterion::Criterion; use hyper::body::Bytes; use reqwest::Request; -use tailcall::{Batch, DataLoaderRequest, EnvIO, FileIO, HttpDataLoader, HttpIO, Response, TargetRuntime, WorkerIO}; -use tailcall::javascript::{Command, Event}; +use tailcall::core::javascript::{Command, Event}; +use tailcall::{ + Batch, DataLoaderRequest, EnvIO, FileIO, HttpDataLoader, HttpIO, Response, TargetRuntime, + WorkerIO, +}; #[derive(Clone)] struct MockHttpClient { diff --git a/benches/impl_path_string_for_evaluation_context.rs b/benches/impl_path_string_for_evaluation_context.rs index cb51cbdcd9..3e819782fe 100644 --- a/benches/impl_path_string_for_evaluation_context.rs +++ b/benches/impl_path_string_for_evaluation_context.rs @@ -16,10 +16,10 @@ use indexmap::IndexMap; use once_cell::sync::Lazy; use reqwest::{Client, Request}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; -use tailcall::javascript::{Command, Event}; +use tailcall::core::javascript::{Command, Event}; use tailcall::{ - WorkerIO, EnvIO, EvaluationContext, FileIO, HttpIO, InMemoryCache, PathString, RequestContext, - ResolverContextLike, Response, Server, TargetRuntime, Upstream, + EnvIO, EvaluationContext, FileIO, HttpIO, InMemoryCache, PathString, RequestContext, + ResolverContextLike, Response, Server, TargetRuntime, Upstream, WorkerIO, }; pub struct JsRuntime {} diff --git a/src/cli/runtime/mod.rs b/src/cli/runtime/mod.rs index 8e5ecc5ff6..09eec2109d 100644 --- a/src/cli/runtime/mod.rs +++ b/src/cli/runtime/mod.rs @@ -7,9 +7,9 @@ use std::sync::Arc; use crate::core::blueprint::Blueprint; use crate::core::cache::InMemoryCache; -use crate::javascript::{Command, Event}; +use crate::core::javascript::{Command, Event}; use crate::core::runtime::TargetRuntime; -use crate::core::{blueprint, EnvIO, FileIO, HttpIO, WorkerIO}; +use crate::core::{blueprint, javascript, EnvIO, FileIO, HttpIO, WorkerIO}; // Provides access to env in native rust environment fn init_env() -> Arc { @@ -24,7 +24,7 @@ fn init_file() -> Arc { fn init_hook_http(http: Arc, script: Option) -> Arc { #[cfg(feature = "js")] if let Some(script) = script { - return crate::javascript::init_http(http, script); + return javascript::init_http(http, script); } #[cfg(not(feature = "js"))] @@ -35,13 +35,13 @@ fn init_hook_http(http: Arc, script: Option) -> } fn init_http_worker_io(script: Option) -> Arc> { - crate::javascript::init_rt(script) + javascript::init_rt(script) } fn init_resolver_worker_io( script: Option, ) -> Arc, async_graphql::Value>> { - crate::javascript::init_rt(script) + javascript::init_rt(script) } // Provides access to http in native rust environment diff --git a/src/core/blueprint/operators/js.rs b/src/core/blueprint/operators/js.rs index f155bf8d0d..624c6dad4d 100644 --- a/src/core/blueprint/operators/js.rs +++ b/src/core/blueprint/operators/js.rs @@ -1,9 +1,10 @@ -use crate::blueprint::*; -use crate::config; -use crate::config::Field; -use crate::lambda::Expression; -use crate::try_fold::TryFold; -use crate::valid::{Valid, Validator}; +use crate::core::blueprint::FieldDefinition; +use crate::core::config; +use crate::core::config::Field; +use crate::core::lambda::IO; +use crate::core::try_fold::TryFold; +use crate::core::valid::Valid; +use crate::{ConfigModule, Expression, ValidationError, Validator}; pub struct CompileJs<'a> { pub name: &'a str, @@ -36,9 +37,9 @@ fn js_enabled(inputs: CompileJs) -> Valid { ctx.eval::<(), &str>(script)?; Ok::<_, anyhow::Error>(()) }) - .map_err(|e| crate::valid::ValidationError::new(e.to_string())), + .map_err(|e| ValidationError::new(e.to_string())), ) - .map(|_| Expression::IO(crate::lambda::IO::Js { name: name.to_string() })) + .map(|_| Expression::IO(IO::Js { name: name.to_string() })) }, ) } diff --git a/src/javascript/enable_js/js_request.rs b/src/core/javascript/enable_js/js_request.rs similarity index 99% rename from src/javascript/enable_js/js_request.rs rename to src/core/javascript/enable_js/js_request.rs index 537ab5598c..3d4bc7434c 100644 --- a/src/javascript/enable_js/js_request.rs +++ b/src/core/javascript/enable_js/js_request.rs @@ -9,7 +9,7 @@ use rquickjs::{FromJs, IntoJs}; use serde::{Deserialize, Serialize}; use crate::core::is_default; -use crate::javascript::JsRequest; +use crate::core::javascript::JsRequest; impl JsRequest { fn uri(&self) -> Uri { diff --git a/src/javascript/enable_js/js_response.rs b/src/core/javascript/enable_js/js_response.rs similarity index 99% rename from src/javascript/enable_js/js_response.rs rename to src/core/javascript/enable_js/js_response.rs index b712d58f77..810791d844 100644 --- a/src/javascript/enable_js/js_response.rs +++ b/src/core/javascript/enable_js/js_response.rs @@ -5,7 +5,7 @@ use rquickjs::{FromJs, IntoJs}; use super::create_header_map; use crate::core::http::Response; -use crate::javascript::JsResponse; +use crate::core::javascript::JsResponse; impl JsResponse { pub fn status(&self) -> u16 { diff --git a/src/javascript/enable_js/mod.rs b/src/core/javascript/enable_js/mod.rs similarity index 100% rename from src/javascript/enable_js/mod.rs rename to src/core/javascript/enable_js/mod.rs diff --git a/src/javascript/enable_js/request_filter.rs b/src/core/javascript/enable_js/request_filter.rs similarity index 97% rename from src/javascript/enable_js/request_filter.rs rename to src/core/javascript/enable_js/request_filter.rs index 9f7a0c06fd..d983eb9bbc 100644 --- a/src/javascript/enable_js/request_filter.rs +++ b/src/core/javascript/enable_js/request_filter.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use hyper::body::Bytes; use rquickjs::FromJs; -use super::{JsRequest, JsResponse}; use crate::core::http::Response; +use crate::core::javascript::{Command, Event, JsRequest, JsResponse}; use crate::core::{HttpIO, WorkerIO}; impl<'js> FromJs<'js> for Command { @@ -93,9 +93,8 @@ mod tests { use hyper::body::Bytes; use rquickjs::{Context, FromJs, IntoJs, Object, Runtime, String as JsString}; - use crate::cli::javascript::request_filter::Command; - use crate::cli::javascript::{JsRequest, JsResponse}; use crate::core::http::Response; + use crate::core::javascript::{Command, JsRequest, JsResponse}; #[test] fn test_command_from_invalid_object() { diff --git a/src/javascript/enable_js/runtime.rs b/src/core/javascript/enable_js/runtime.rs similarity index 99% rename from src/javascript/enable_js/runtime.rs rename to src/core/javascript/enable_js/runtime.rs index c8731f886f..9e052f51e2 100644 --- a/src/javascript/enable_js/runtime.rs +++ b/src/core/javascript/enable_js/runtime.rs @@ -5,7 +5,7 @@ use std::thread; use async_graphql_value::ConstValue; use rquickjs::{Context, Ctx, FromJs, Function, IntoJs, Value}; -use crate::javascript::{Command, Event, JsRequest}; +use crate::core::javascript::{Command, Event, JsRequest}; use crate::core::{blueprint, WorkerIO}; struct LocalRuntime(Context); diff --git a/src/javascript/mod.rs b/src/core/javascript/mod.rs similarity index 83% rename from src/javascript/mod.rs rename to src/core/javascript/mod.rs index 324500270a..8b327735d8 100644 --- a/src/javascript/mod.rs +++ b/src/core/javascript/mod.rs @@ -27,10 +27,9 @@ pub enum Command { Response(JsResponse), } -use crate::blueprint::Script; -use crate::http::Response; +use crate::{Response, Script}; -pub fn init_rt(script: Option) -> Arc { +pub fn init_rt(script: Option