Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed May 9, 2024
1 parent 8b715cb commit 67fcc23
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions benches/data_loader_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
10 changes: 5 additions & 5 deletions src/cli/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn EnvIO> {
Expand All @@ -24,7 +24,7 @@ fn init_file() -> Arc<dyn FileIO> {
fn init_hook_http(http: Arc<impl HttpIO>, script: Option<blueprint::Script>) -> Arc<dyn HttpIO> {
#[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"))]
Expand All @@ -35,13 +35,13 @@ fn init_hook_http(http: Arc<impl HttpIO>, script: Option<blueprint::Script>) ->
}

fn init_http_worker_io(script: Option<blueprint::Script>) -> Arc<dyn WorkerIO<Event, Command>> {
crate::javascript::init_rt(script)
javascript::init_rt(script)
}

fn init_resolver_worker_io(
script: Option<blueprint::Script>,
) -> Arc<dyn WorkerIO<Option<async_graphql::Value>, async_graphql::Value>> {
crate::javascript::init_rt(script)
javascript::init_rt(script)
}

// Provides access to http in native rust environment
Expand Down
17 changes: 9 additions & 8 deletions src/core/blueprint/operators/js.rs
Original file line number Diff line number Diff line change
@@ -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;

Check failure on line 4 in src/core/blueprint/operators/js.rs

View workflow job for this annotation

GitHub Actions / Test AWS Lambda Build

unused import: `crate::core::lambda::IO`

Check failure on line 4 in src/core/blueprint/operators/js.rs

View workflow job for this annotation

GitHub Actions / Run Tests (WASM)

unused import: `crate::core::lambda::IO`
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;
use crate::{ConfigModule, Expression, ValidationError, Validator};

Check failure on line 7 in src/core/blueprint/operators/js.rs

View workflow job for this annotation

GitHub Actions / Test AWS Lambda Build

unused import: `ValidationError`

Check failure on line 7 in src/core/blueprint/operators/js.rs

View workflow job for this annotation

GitHub Actions / Run Tests (WASM)

unused import: `ValidationError`

pub struct CompileJs<'a> {
pub name: &'a str,
Expand Down Expand Up @@ -36,9 +37,9 @@ fn js_enabled(inputs: CompileJs) -> Valid<Expression, String> {
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() }))
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/javascript/mod.rs → src/core/javascript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::blueprint::Script>) -> Arc<Runtime> {
pub fn init_rt(script: Option<Script>) -> Arc<Runtime> {
if let Some(script) = script {
Arc::new(Runtime::new(script))
} else {
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod grpc;
pub mod has_headers;
pub mod helpers;
pub mod http;
pub mod javascript;
pub mod json;
pub mod lambda;
pub mod merge_right;
Expand Down
5 changes: 3 additions & 2 deletions src/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use async_graphql_value::ConstValue;

use crate::javascript::{Command, Event};
use crate::core::javascript::{Command, Event};
use crate::core::schema_extension::SchemaExtension;
use crate::core::{Cache, EnvIO, FileIO, HttpIO, WorkerIO};

Expand Down Expand Up @@ -58,8 +58,9 @@ pub mod test {
use crate::core::blueprint::Upstream;
use crate::core::cache::InMemoryCache;
use crate::core::http::Response;
use crate::core::javascript::{Command, Event};
use crate::core::runtime::TargetRuntime;
use crate::core::{blueprint, EnvIO, FileIO, HttpIO};
use crate::core::{blueprint, javascript, EnvIO, FileIO, HttpIO};
use crate::WorkerIO;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod core;
pub mod core;

#[cfg(feature = "cli")]
pub mod cli;
Expand Down
2 changes: 1 addition & 1 deletion tailcall-aws-lambda/src/worker_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_graphql_value::ConstValue;
use tailcall::javascript::{Command, Event};
use tailcall::core::javascript::{Command, Event};
use tailcall::WorkerIO;

pub struct JsRuntime {}
Expand Down
2 changes: 1 addition & 1 deletion tailcall-cloudflare/src/worker_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_graphql_value::ConstValue;
use tailcall::javascript::{Command, Event};
use tailcall::core::javascript::{Command, Event};
use tailcall::WorkerIO;

pub struct JsRuntime {}
Expand Down
1 change: 1 addition & 0 deletions tests/core/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::Arc;
use anyhow::anyhow;
use markdown::mdast::Node;
use markdown::ParseOptions;
use tailcall::core::javascript;
use tailcall::{AppContext, Blueprint, ConfigModule, EnvIO, InMemoryCache, Source, TargetRuntime};

use super::file::File;
Expand Down
1 change: 1 addition & 0 deletions tests/core/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use derive_setters::Setters;
use tailcall::core::javascript;
use tailcall::{InMemoryCache, Script, Source, TargetRuntime};

use super::env::Env;
Expand Down
2 changes: 1 addition & 1 deletion tests/core/worker_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_graphql_value::ConstValue;
use tailcall::javascript::{Command, Event};
use tailcall::core::javascript::{Command, Event};
use tailcall::WorkerIO;

pub struct JsRuntime {}
Expand Down
2 changes: 2 additions & 0 deletions tests/server_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub mod test {
use hyper::body::Bytes;
use reqwest::Client;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use tailcall::core::javascript;
use tailcall::core::javascript::{Command, Event};
use tailcall::{InMemoryCache, Response, Script, TargetRuntime, WorkerIO};
use tokio::io::{AsyncReadExt, AsyncWriteExt};

Expand Down

0 comments on commit 67fcc23

Please sign in to comment.