From 89d5b39f1681c22993313b7184faa2d017210668 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Tue, 19 Nov 2024 00:53:42 -0500 Subject: [PATCH 1/2] refactor: move `mustache` to `tailcall-jq` --- Cargo.lock | 50 +++- Cargo.toml | 1 + ...impl_path_string_for_evaluation_context.rs | 2 +- benches/request_template_bench.rs | 2 +- src/cli/generator/generator.rs | 3 +- src/cli/llm/infer_type_name.rs | 3 +- src/core/blueprint/dynamic_value.rs | 7 +- src/core/blueprint/operators/grpc.rs | 2 +- src/core/blueprint/operators/http.rs | 3 +- src/core/config/apollo.rs | 2 +- src/core/config/directives/telemetry.rs | 2 +- src/core/config/reader_context.rs | 2 +- src/core/config/transformer/subgraph.rs | 4 +- src/core/graphql/request_template.rs | 6 +- src/core/grpc/request_template.rs | 9 +- src/core/helpers/body.rs | 4 +- src/core/helpers/headers.rs | 4 +- src/core/helpers/url.rs | 7 +- src/core/http/query_encoder.rs | 2 +- src/core/http/request_template.rs | 20 +- src/core/mod.rs | 2 - src/core/mustache/mod.rs | 5 - src/core/mustache/model.rs | 72 ----- src/core/mustache/parse.rs | 272 ------------------ src/core/path.rs | 45 +-- src/core/proto_reader/fetch.rs | 2 +- src/core/serde_value_ext.rs | 2 +- tests/expression_spec.rs | 2 +- 28 files changed, 84 insertions(+), 453 deletions(-) delete mode 100644 src/core/mustache/mod.rs delete mode 100644 src/core/mustache/model.rs delete mode 100644 src/core/mustache/parse.rs diff --git a/Cargo.lock b/Cargo.lock index 3d62a39282..694c86511d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "anymap2" @@ -643,7 +643,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -843,7 +843,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ - "nom", + "nom 7.1.3", ] [[package]] @@ -1576,7 +1576,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74fef4569247a5f429d9156b9d0a2599914385dd189c539334c625d8099d90ab" dependencies = [ "futures-core", - "nom", + "nom 7.1.3", "pin-project-lite", ] @@ -2852,7 +2852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3247,6 +3247,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nom" +version = "8.0.0-alpha2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2785486691910e746b3d84220af18362bd15ba71f9b7bc0a47ac549550b7fe2" +dependencies = [ + "memchr", +] + [[package]] name = "ntapi" version = "0.4.1" @@ -3736,7 +3745,7 @@ dependencies = [ "fnv", "itertools 0.12.1", "lazy_static", - "nom", + "nom 7.1.3", "quick-xml", "regex", "regex-cache", @@ -4580,7 +4589,7 @@ dependencies = [ "futures-core", "futures-timer", "mime", - "nom", + "nom 7.1.3", "pin-project-lite", "reqwest 0.12.7", "thiserror", @@ -4999,9 +5008,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "indexmap 2.6.0", "itoa", @@ -5012,9 +5021,9 @@ dependencies = [ [[package]] name = "serde_json_borrow" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8dc27b181f9294b9cd937ae4375414cd0a77f542a34e063ced1e47ed2ceaa" +checksum = "724685c39b301aa2cf7de617fed340d6529694a72fc0f5cc3b1846423e71c630" dependencies = [ "serde", "serde_json", @@ -5470,7 +5479,7 @@ dependencies = [ "mimalloc", "mime", "moka", - "nom", + "nom 7.1.3", "num", "num_cpus", "once_cell", @@ -5517,6 +5526,7 @@ dependencies = [ "tailcall-fixtures", "tailcall-hasher", "tailcall-http-cache", + "tailcall-jq", "tailcall-macros", "tailcall-prettier", "tailcall-tracker", @@ -5620,6 +5630,20 @@ dependencies = [ "url", ] +[[package]] +name = "tailcall-jq" +version = "0.1.0" +source = "git+https://github.com/tailcallhq/tailcall-jq#53b7d679d657887bee72acfea19cf225e0a52de0" +dependencies = [ + "anyhow", + "async-graphql", + "async-graphql-value", + "indexmap 2.6.0", + "nom 8.0.0-alpha2", + "serde_json", + "serde_json_borrow", +] + [[package]] name = "tailcall-macros" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 04b545bf46..04fd12cc16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,6 +174,7 @@ tailcall-valid = { workspace = true } dashmap = "6.1.0" urlencoding = "2.1.3" tailcall-chunk = "0.2.5" +tailcall-jq = { git = "https://github.com/tailcallhq/tailcall-jq" } # to build rquickjs bindings on systems without builtin bindings [target.'cfg(all(target_os = "windows", target_arch = "x86"))'.dependencies] diff --git a/benches/impl_path_string_for_evaluation_context.rs b/benches/impl_path_string_for_evaluation_context.rs index e4eb603f67..29797d378a 100644 --- a/benches/impl_path_string_for_evaluation_context.rs +++ b/benches/impl_path_string_for_evaluation_context.rs @@ -17,10 +17,10 @@ use tailcall::core::blueprint::{Server, Upstream}; use tailcall::core::cache::InMemoryCache; use tailcall::core::http::{RequestContext, Response}; use tailcall::core::ir::{EvalContext, ResolverContextLike, SelectionField}; -use tailcall::core::path::PathString; use tailcall::core::runtime::TargetRuntime; use tailcall::core::{EnvIO, FileIO, HttpIO}; use tailcall_http_cache::HttpCacheManager; +use tailcall_jq::mustache::path::PathString; struct Http { client: ClientWithMiddleware, diff --git a/benches/request_template_bench.rs b/benches/request_template_bench.rs index 416e3c9db5..9f55e3cb96 100644 --- a/benches/request_template_bench.rs +++ b/benches/request_template_bench.rs @@ -8,7 +8,7 @@ use tailcall::core::endpoint::Endpoint; use tailcall::core::has_headers::HasHeaders; use tailcall::core::http::RequestTemplate; use tailcall::core::json::JsonLike; -use tailcall::core::path::{PathString, PathValue, ValueString}; +use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; #[derive(Setters)] struct Context { diff --git a/src/cli/generator/generator.rs b/src/cli/generator/generator.rs index 4cdbb1ea50..4a44a15828 100644 --- a/src/cli/generator/generator.rs +++ b/src/cli/generator/generator.rs @@ -4,6 +4,7 @@ use std::path::Path; use http::header::{HeaderMap, HeaderName, HeaderValue}; use inquire::Confirm; use pathdiff::diff_paths; +use tailcall_jq::mustache::Mustache; use tailcall_valid::{ValidateInto, Validator}; use super::config::{Config, LLMConfig, Resolved, Source}; @@ -15,7 +16,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::{Mustache, Transform}; +use crate::core::Transform; /// CLI that reads the the config file and generates the required tailcall /// configuration. diff --git a/src/cli/llm/infer_type_name.rs b/src/cli/llm/infer_type_name.rs index 7183eacbde..0021a36248 100644 --- a/src/cli/llm/infer_type_name.rs +++ b/src/cli/llm/infer_type_name.rs @@ -4,12 +4,11 @@ use genai::chat::{ChatMessage, ChatRequest, ChatResponse}; use indexmap::{indexset, IndexSet}; use serde::{Deserialize, Serialize}; use serde_json::json; +use tailcall_jq::mustache::Mustache; use super::{Error, Result, Wizard}; use crate::core::config::Config; use crate::core::generator::PREFIX; -use crate::core::Mustache; - const BASE_TEMPLATE: &str = include_str!("prompts/infer_type_name.md"); pub struct InferTypeName { diff --git a/src/core/blueprint/dynamic_value.rs b/src/core/blueprint/dynamic_value.rs index 0d3d36b6ad..3ddf7b1965 100644 --- a/src/core/blueprint/dynamic_value.rs +++ b/src/core/blueprint/dynamic_value.rs @@ -1,8 +1,7 @@ use async_graphql_value::{ConstValue, Name}; use indexmap::IndexMap; use serde_json::Value; - -use crate::core::mustache::Mustache; +use tailcall_jq::mustache::{Mustache, Segment}; #[derive(Debug, Clone, PartialEq)] pub enum DynamicValue { @@ -24,9 +23,7 @@ impl DynamicValue { DynamicValue::Mustache(mustache) } else { let segments = mustache.segments_mut(); - if let Some(crate::core::mustache::Segment::Expression(vec)) = - segments.get_mut(0) - { + if let Some(Segment::Expression(vec)) = segments.get_mut(0) { vec.insert(0, name.to_string()); } DynamicValue::Mustache(mustache) diff --git a/src/core/blueprint/operators/grpc.rs b/src/core/blueprint/operators/grpc.rs index 3f730b109c..21aa7359bf 100644 --- a/src/core/blueprint/operators/grpc.rs +++ b/src/core/blueprint/operators/grpc.rs @@ -2,6 +2,7 @@ use std::fmt::Display; use prost_reflect::prost_types::FileDescriptorSet; use prost_reflect::FieldDescriptor; +use tailcall_jq::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use super::apply_select; @@ -12,7 +13,6 @@ use crate::core::grpc::protobuf::{ProtobufOperation, ProtobufSet}; use crate::core::grpc::request_template::RequestTemplate; 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::{config, helpers}; diff --git a/src/core/blueprint/operators/http.rs b/src/core/blueprint/operators/http.rs index 6518388845..1c88acf4b0 100644 --- a/src/core/blueprint/operators/http.rs +++ b/src/core/blueprint/operators/http.rs @@ -1,3 +1,4 @@ +use tailcall_jq::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use crate::core::blueprint::*; @@ -7,7 +8,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::{config, helpers, Mustache}; +use crate::core::{config, helpers}; pub fn compile_http( config_module: &config::ConfigModule, diff --git a/src/core/config/apollo.rs b/src/core/config/apollo.rs index 2990d599b0..2049f0fe1f 100644 --- a/src/core/config/apollo.rs +++ b/src/core/config/apollo.rs @@ -1,8 +1,8 @@ use serde::{Deserialize, Serialize}; +use tailcall_jq::mustache::Mustache; use crate::core::config::ConfigReaderContext; use crate::core::is_default; -use crate::core::mustache::Mustache; #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, schemars::JsonSchema)] #[serde(rename_all = "camelCase")] diff --git a/src/core/config/directives/telemetry.rs b/src/core/config/directives/telemetry.rs index 108ff2aab3..197b6ca5c7 100644 --- a/src/core/config/directives/telemetry.rs +++ b/src/core/config/directives/telemetry.rs @@ -1,5 +1,6 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; +use tailcall_jq::mustache::Mustache; use tailcall_macros::{DirectiveDefinition, InputDefinition}; use tailcall_valid::Validator; @@ -8,7 +9,6 @@ use crate::core::helpers::headers::to_mustache_headers; use crate::core::is_default; use crate::core::macros::MergeRight; use crate::core::merge_right::MergeRight; -use crate::core::mustache::Mustache; mod defaults { pub mod prometheus { diff --git a/src/core/config/reader_context.rs b/src/core/config/reader_context.rs index ef228e3535..96ee4ceab2 100644 --- a/src/core/config/reader_context.rs +++ b/src/core/config/reader_context.rs @@ -2,9 +2,9 @@ use std::borrow::Cow; use std::collections::BTreeMap; use http::header::HeaderMap; +use tailcall_jq::mustache::path::PathString; use crate::core::has_headers::HasHeaders; -use crate::core::path::PathString; use crate::core::runtime::TargetRuntime; pub struct ConfigReaderContext<'a> { diff --git a/src/core/config/transformer/subgraph.rs b/src/core/config/transformer/subgraph.rs index b95dc2d5a3..320b108eab 100644 --- a/src/core/config/transformer/subgraph.rs +++ b/src/core/config/transformer/subgraph.rs @@ -4,6 +4,7 @@ use std::convert::identity; use std::fmt::{Display, Write}; use std::ops::Deref; +use tailcall_jq::mustache::{Mustache, Segment}; use tailcall_macros::MergeRight; use tailcall_valid::{Valid, Validator}; @@ -14,8 +15,7 @@ use crate::core::config::{ }; use crate::core::directive::DirectiveCodec; use crate::core::merge_right::MergeRight; -use crate::core::mustache::Segment; -use crate::core::{Mustache, Transform, Type}; +use crate::core::{Transform, Type}; const ENTITIES_FIELD_NAME: &str = "_entities"; const SERVICE_FIELD_NAME: &str = "_service"; diff --git a/src/core/graphql/request_template.rs b/src/core/graphql/request_template.rs index 1eb87f1cc8..63b996b543 100644 --- a/src/core/graphql/request_template.rs +++ b/src/core/graphql/request_template.rs @@ -6,6 +6,8 @@ use std::hash::{Hash, Hasher}; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; +use tailcall_jq::mustache::path::PathGraphql; +use tailcall_jq::mustache::Mustache; use crate::core::config::{GraphQLOperationType, KeyValue}; use crate::core::has_headers::HasHeaders; @@ -13,8 +15,6 @@ use crate::core::helpers::headers::MustacheHeaders; use crate::core::http::Method::POST; use crate::core::ir::model::{CacheKey, IoId}; use crate::core::ir::{GraphQLOperationContext, RelatedFields}; -use crate::core::mustache::Mustache; -use crate::core::path::PathGraphql; /// RequestTemplate for GraphQL requests (See RequestTemplate documentation) #[derive(Setters, Debug, Clone)] @@ -170,6 +170,7 @@ mod tests { use http::header::HeaderMap; use pretty_assertions::assert_eq; use serde_json::json; + use tailcall_jq::mustache::path::PathGraphql; use crate::core::config::GraphQLOperationType; use crate::core::graphql::request_template::RelatedFields; @@ -178,7 +179,6 @@ mod tests { use crate::core::ir::model::CacheKey; use crate::core::ir::GraphQLOperationContext; use crate::core::json::JsonLike; - use crate::core::path::PathGraphql; struct Context { pub value: Value, diff --git a/src/core/grpc/request_template.rs b/src/core/grpc/request_template.rs index f4901f5cc5..5f1d34637c 100644 --- a/src/core/grpc/request_template.rs +++ b/src/core/grpc/request_template.rs @@ -4,6 +4,8 @@ use anyhow::Result; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use tailcall_hasher::TailcallHasher; +use tailcall_jq::mustache::path::PathString; +use tailcall_jq::mustache::Mustache; use url::Url; use super::request::create_grpc_request; @@ -12,8 +14,6 @@ use crate::core::grpc::protobuf::ProtobufOperation; use crate::core::has_headers::HasHeaders; use crate::core::helpers::headers::MustacheHeaders; use crate::core::ir::model::{CacheKey, IoId}; -use crate::core::mustache::Mustache; -use crate::core::path::PathString; static GRPC_MIME_TYPE: HeaderValue = HeaderValue::from_static("application/grpc"); @@ -136,6 +136,8 @@ mod tests { use http::Method; use pretty_assertions::assert_eq; use tailcall_fixtures::protobuf; + use tailcall_jq::mustache::path::PathString; + use tailcall_jq::mustache::Mustache; use super::{RequestBody, RequestTemplate}; use crate::core::blueprint::GrpcMethod; @@ -145,7 +147,6 @@ mod tests { }; use crate::core::grpc::protobuf::{ProtobufOperation, ProtobufSet}; use crate::core::ir::model::CacheKey; - use crate::core::mustache::Mustache; async fn get_protobuf_op() -> ProtobufOperation { let test_file = protobuf::GREETINGS; @@ -203,7 +204,7 @@ mod tests { } } - impl crate::core::path::PathString for Context { + impl PathString for Context { fn path_string<'a, T: AsRef>(&'a self, parts: &'a [T]) -> Option> { self.value.path_string(parts) } diff --git a/src/core/helpers/body.rs b/src/core/helpers/body.rs index 5e44643d85..2ce6ccddad 100644 --- a/src/core/helpers/body.rs +++ b/src/core/helpers/body.rs @@ -1,8 +1,8 @@ use serde_json::Value; +use tailcall_jq::mustache::Mustache; use tailcall_valid::Valid; use crate::core::grpc::request_template::RequestBody; -use crate::core::mustache::Mustache; pub fn to_body(body: Option<&Value>) -> Valid, String> { let Some(body) = body else { @@ -21,11 +21,11 @@ pub fn to_body(body: Option<&Value>) -> Valid, String> { #[cfg(test)] mod tests { + use tailcall_jq::mustache::Mustache; use tailcall_valid::Valid; use super::to_body; use crate::core::grpc::request_template::RequestBody; - use crate::core::mustache::Mustache; #[test] fn no_body() { diff --git a/src/core/helpers/headers.rs b/src/core/helpers/headers.rs index 76da574439..0989d46fd1 100644 --- a/src/core/helpers/headers.rs +++ b/src/core/helpers/headers.rs @@ -1,8 +1,8 @@ use http::header::HeaderName; +use tailcall_jq::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use crate::core::config::KeyValue; -use crate::core::mustache::Mustache; pub type MustacheHeaders = Vec<(HeaderName, Mustache)>; @@ -25,11 +25,11 @@ pub fn to_mustache_headers(headers: &[KeyValue]) -> Valid Result<()> { diff --git a/src/core/helpers/url.rs b/src/core/helpers/url.rs index 51b65b36cf..82677ffb4f 100644 --- a/src/core/helpers/url.rs +++ b/src/core/helpers/url.rs @@ -1,21 +1,20 @@ +use tailcall_jq::mustache::Mustache; use tailcall_valid::Valid; -use crate::core::mustache::Mustache; - pub fn to_url(url: &str) -> Valid { Valid::succeed(Mustache::parse(url)) } #[cfg(test)] mod tests { + use tailcall_jq::mustache::Mustache; + use super::to_url; #[test] fn parse_url() { use tailcall_valid::Valid; - use crate::core::mustache::Mustache; - let url = to_url("http://localhost:3000"); assert_eq!( diff --git a/src/core/http/query_encoder.rs b/src/core/http/query_encoder.rs index 208c7a9cc4..8548bb710f 100644 --- a/src/core/http/query_encoder.rs +++ b/src/core/http/query_encoder.rs @@ -1,4 +1,4 @@ -use crate::core::path::ValueString; +use tailcall_jq::mustache::path::ValueString; /// Defines different strategies for encoding query parameters. #[derive(Default, Debug, Clone)] diff --git a/src/core/http/request_template.rs b/src/core/http/request_template.rs index 748cd395a1..77c8d3c4bb 100644 --- a/src/core/http/request_template.rs +++ b/src/core/http/request_template.rs @@ -4,6 +4,9 @@ use std::hash::{Hash, Hasher}; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; +use tailcall_jq::mustache::eval::Eval; +use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; +use tailcall_jq::mustache::{Mustache, Segment}; use url::Url; use super::query_encoder::QueryEncoder; @@ -12,8 +15,6 @@ use crate::core::endpoint::Endpoint; use crate::core::has_headers::HasHeaders; use crate::core::helpers::headers::MustacheHeaders; use crate::core::ir::model::{CacheKey, IoId}; -use crate::core::mustache::{Eval, Mustache, Segment}; -use crate::core::path::{PathString, PathValue, ValueString}; /// RequestTemplate is an extension of a Mustache template. /// Various parts of the template can be written as a mustache template. @@ -310,12 +311,12 @@ mod tests { use http::header::{HeaderMap, HeaderName}; use pretty_assertions::assert_eq; use serde_json::json; + use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; + use tailcall_jq::mustache::Mustache; use super::{Query, RequestTemplate}; use crate::core::has_headers::HasHeaders; use crate::core::json::JsonLike; - use crate::core::mustache::Mustache; - use crate::core::path::{PathString, PathValue, ValueString}; #[derive(Setters)] struct Context { @@ -330,10 +331,7 @@ mod tests { } impl PathValue for Context { - fn raw_value<'a, T: AsRef>( - &'a self, - path: &[T], - ) -> Option> { + fn raw_value<'a, T: AsRef>(&'a self, path: &[T]) -> Option> { self.value.get_path(path).map(|a| { ValueString::Value(Cow::Owned( async_graphql::Value::from_json(a.clone()).unwrap(), @@ -342,7 +340,7 @@ mod tests { } } - impl crate::core::path::PathString for Context { + impl PathString for Context { fn path_string<'a, T: AsRef>(&'a self, parts: &'a [T]) -> Option> { self.value.path_string(parts) } @@ -780,10 +778,10 @@ mod tests { mod form_encoded_url { use serde_json::json; + use tailcall_jq::mustache::Mustache; use crate::core::http::request_template::tests::Context; use crate::core::http::RequestTemplate; - use crate::core::mustache::Mustache; #[test] fn test_with_string() { @@ -844,11 +842,11 @@ mod tests { use http::header::HeaderMap; use serde_json::json; + use tailcall_jq::mustache::Mustache; use crate::core::http::request_template::tests::Context; use crate::core::http::RequestTemplate; use crate::core::ir::model::{CacheKey, IoId}; - use crate::core::mustache::Mustache; fn assert_no_duplicate(arr: [Option; N]) { let len = arr.len(); diff --git a/src/core/mod.rs b/src/core/mod.rs index a7bde1484e..d6dfc9609a 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -25,7 +25,6 @@ pub mod jit; pub mod json; mod lift; pub mod merge_right; -pub mod mustache; pub mod path; pub mod primitive; pub mod print_schema; @@ -54,7 +53,6 @@ pub use errata::Errata; pub use error::{Error, Result}; use http::Response; use ir::model::IoId; -pub use mustache::Mustache; pub use tailcall_macros as macros; pub use transform::Transform; pub use wrapping_type::Type; diff --git a/src/core/mustache/mod.rs b/src/core/mustache/mod.rs deleted file mode 100644 index 13f906c339..0000000000 --- a/src/core/mustache/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod eval; -mod model; -mod parse; -pub use eval::Eval; -pub use model::*; diff --git a/src/core/mustache/model.rs b/src/core/mustache/model.rs deleted file mode 100644 index c007e7a875..0000000000 --- a/src/core/mustache/model.rs +++ /dev/null @@ -1,72 +0,0 @@ -use std::fmt::Display; - -#[derive(Debug, Clone, PartialEq, Hash, Default)] -pub struct Mustache(Vec); - -#[derive(Debug, Clone, PartialEq, Hash)] -pub enum Segment { - Literal(String), - Expression(Vec), -} - -impl> From for Mustache { - fn from(value: A) -> Self { - Mustache(value.into_iter().collect()) - } -} - -impl Mustache { - pub fn is_const(&self) -> bool { - match self { - Mustache(segments) => { - for s in segments { - if let Segment::Expression(_) = s { - return false; - } - } - true - } - } - } - - pub fn segments(&self) -> &Vec { - &self.0 - } - - pub fn segments_mut(&mut self) -> &mut Vec { - &mut self.0 - } - - pub fn expression_segments(&self) -> Vec<&Vec> { - self.segments() - .iter() - .filter_map(|seg| match seg { - Segment::Expression(parts) => Some(parts), - _ => None, - }) - .collect() - } - - /// Checks if the mustache template contains the given expression - pub fn expression_contains(&self, expression: &str) -> bool { - self.segments() - .iter() - .any(|seg| matches!(seg, Segment::Expression(parts) if parts.iter().any(|part| part.as_str() == expression))) - } -} - -impl Display for Mustache { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let str = self - .segments() - .iter() - .map(|segment| match segment { - Segment::Literal(text) => text.clone(), - Segment::Expression(parts) => format!("{{{{{}}}}}", parts.join(".")), - }) - .collect::>() - .join(""); - - write!(f, "{}", str) - } -} diff --git a/src/core/mustache/parse.rs b/src/core/mustache/parse.rs deleted file mode 100644 index a814e22f53..0000000000 --- a/src/core/mustache/parse.rs +++ /dev/null @@ -1,272 +0,0 @@ -use nom::branch::alt; -use nom::bytes::complete::{tag, take_until}; -use nom::character::complete::char; -use nom::combinator::map; -use nom::multi::many0; -use nom::sequence::delimited; -use nom::{Finish, IResult}; - -use super::*; - -impl Mustache { - pub fn parse(str: &str) -> Mustache { - let result = parse_mustache(str).finish(); - match result { - Ok((_, mustache)) => mustache, - Err(_) => Mustache::from(vec![Segment::Literal(str.to_string())]), - } - } -} - -fn parse_name(input: &str) -> IResult<&str, String> { - let spaces = nom::character::complete::multispace0; - let alpha = nom::character::complete::alpha1; - let alphanumeric_or_underscore = nom::multi::many0(nom::branch::alt(( - nom::character::complete::alphanumeric1, - nom::bytes::complete::tag("_"), - ))); - - let parser = nom::sequence::tuple((spaces, alpha, alphanumeric_or_underscore, spaces)); - - nom::combinator::map(parser, |(_, a, b, _)| { - let b: String = b.into_iter().collect(); - format!("{}{}", a, b) - })(input) -} - -fn parse_expression(input: &str) -> IResult<&str, Segment> { - delimited( - tag("{{"), - map( - nom::sequence::tuple(( - nom::combinator::opt(char('.')), // Optional leading dot - nom::multi::separated_list1(char('.'), parse_name), - )), - |(_, expr_parts)| Segment::Expression(expr_parts), - ), - tag("}}"), - )(input) -} - -fn parse_segment(input: &str) -> IResult<&str, Vec> { - let expression_result = many0(alt(( - parse_expression, - map(take_until("{{"), |txt: &str| { - Segment::Literal(txt.to_string()) - }), - )))(input); - - if let Ok((remaining, segments)) = expression_result { - if remaining.is_empty() { - Ok((remaining, segments)) - } else { - let mut segments = segments; - segments.push(Segment::Literal(remaining.to_string())); - Ok(("", segments)) - } - } else { - Ok(("", vec![Segment::Literal(input.to_string())])) - } -} - -fn parse_mustache(input: &str) -> IResult<&str, Mustache> { - map(parse_segment, |segments| { - Mustache::from(segments.into_iter().filter(|seg| match seg { - Segment::Literal(s) => (!s.is_empty()) && s != "\"", - _ => true, - })) - })(input) -} - -#[cfg(test)] -mod tests { - - use pretty_assertions::assert_eq; - - use crate::core::mustache::{Mustache, Segment}; - - #[test] - fn test_to_string() { - let expectations = vec![ - r"/users/{{value.id}}/todos", - r"http://localhost:8090/{{foo.bar}}/api/{{hello.world}}/end", - r"http://localhost:{{args.port}}", - r"/users/{{value.userId}}", - r"/bar?id={{args.id}}&flag={{args.flag}}", - r"/foo?id={{value.id}}", - r"{{value.d}}", - r"/posts/{{args.id}}", - r"http://localhost:8000", - ]; - - for expected in expectations { - let mustache = Mustache::parse(expected); - - assert_eq!(expected, mustache.to_string()); - } - } - - #[test] - fn test_single_literal() { - let s = r"hello/world"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Literal("hello/world".to_string())]) - ); - } - - #[test] - fn test_single_template() { - let s = r"{{hello.world}}"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Expression(vec![ - "hello".to_string(), - "world".to_string(), - ])]) - ); - } - - #[test] - fn test_mixed() { - let s = r"http://localhost:8090/{{foo.bar}}/api/{{hello.world}}/end"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![ - Segment::Literal("http://localhost:8090/".to_string()), - Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), - Segment::Literal("/api/".to_string()), - Segment::Expression(vec!["hello".to_string(), "world".to_string()]), - Segment::Literal("/end".to_string()), - ]) - ); - } - - #[test] - fn test_with_spaces() { - let s = "{{ foo . bar }}"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Expression(vec![ - "foo".to_string(), - "bar".to_string(), - ])]) - ); - } - - #[test] - fn test_parse_expression_with_valid_input() { - let result = Mustache::parse("{{ foo.bar }} extra"); - let expected = Mustache::from(vec![ - Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), - Segment::Literal(" extra".to_string()), - ]); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_expression_with_invalid_input() { - let result = Mustache::parse("foo.bar }}"); - let expected = Mustache::from(vec![Segment::Literal("foo.bar }}".to_string())]); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_segments_mixed() { - let result = Mustache::parse("prefix {{foo.bar}} middle {{baz.qux}} suffix"); - let expected = Mustache::from(vec![ - Segment::Literal("prefix ".to_string()), - Segment::Expression(vec!["foo".to_string(), "bar".to_string()]), - Segment::Literal(" middle ".to_string()), - Segment::Expression(vec!["baz".to_string(), "qux".to_string()]), - Segment::Literal(" suffix".to_string()), - ]); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_segments_only_literal() { - let result = Mustache::parse("just a string"); - let expected = Mustache::from(vec![Segment::Literal("just a string".to_string())]); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_segments_only_expression() { - let result = Mustache::parse("{{foo.bar}}"); - let expected = Mustache::from(vec![Segment::Expression(vec![ - "foo".to_string(), - "bar".to_string(), - ])]); - assert_eq!(result, expected); - } - - #[test] - fn test_unfinished_expression() { - let s = r"{{hello.world"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Literal("{{hello.world".to_string())]) - ); - } - - #[test] - fn test_new_number() { - let mustache = Mustache::parse("123"); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Literal("123".to_string())]) - ); - } - - #[test] - fn parse_env_name() { - let result = Mustache::parse("{{env.FOO}}"); - assert_eq!( - result, - Mustache::from(vec![Segment::Expression(vec![ - "env".to_string(), - "FOO".to_string(), - ])]) - ); - } - - #[test] - fn parse_env_with_underscores() { - let result = Mustache::parse("{{env.FOO_BAR}}"); - assert_eq!( - result, - Mustache::from(vec![Segment::Expression(vec![ - "env".to_string(), - "FOO_BAR".to_string(), - ])]) - ); - } - - #[test] - fn single_curly_brackets() { - let result = Mustache::parse("test:{SHA}string"); - assert_eq!( - result, - Mustache::from(vec![Segment::Literal("test:{SHA}string".to_string())]) - ); - } - - #[test] - fn test_optional_dot_expression() { - let s = r"{{.foo.bar}}"; - let mustache: Mustache = Mustache::parse(s); - assert_eq!( - mustache, - Mustache::from(vec![Segment::Expression(vec![ - "foo".to_string(), - "bar".to_string(), - ])]) - ); - } -} diff --git a/src/core/path.rs b/src/core/path.rs index 006450d19c..9ae1d4f02c 100644 --- a/src/core/path.rs +++ b/src/core/path.rs @@ -3,40 +3,9 @@ use std::borrow::Cow; use serde_json::json; +use tailcall_jq::mustache::path::{PathGraphql, PathString, PathValue, ValueString}; use crate::core::ir::{EvalContext, ResolverContextLike}; -use crate::core::json::JsonLike; - -/// -/// The PathString trait provides a method for accessing values from a JSON-like -/// structure. The returned value is encoded as a plain string. -/// This is typically used in evaluating mustache templates. -pub trait PathString { - fn path_string<'a, T: AsRef>(&'a self, path: &'a [T]) -> Option>; -} - -/// PathValue trait provides a method for accessing values from JSON-like -/// structure, the returned value is wrapped with RawValue enum, delegating -/// encoding to the client of this method. -pub trait PathValue { - fn raw_value<'a, T: AsRef>(&'a self, path: &[T]) -> Option>; -} - -/// -/// The PathGraphql trait provides a method for accessing values from a -/// JSON-like structure. The returned value is encoded as a GraphQL Value. -pub trait PathGraphql { - fn path_graphql>(&self, path: &[T]) -> Option; -} - -impl PathString for serde_json::Value { - fn path_string<'a, T: AsRef>(&'a self, path: &'a [T]) -> Option> { - self.get_path(path).map(move |a| match a { - serde_json::Value::String(s) => Cow::Borrowed(s.as_str()), - _ => Cow::Owned(a.to_string()), - }) - } -} fn convert_value(value: Cow<'_, async_graphql::Value>) -> Option> { match value { @@ -55,15 +24,6 @@ fn convert_value(value: Cow<'_, async_graphql::Value>) -> Option> { } } -/// -/// An optimized version of async_graphql::Value that handles strings in a more -/// efficient manner. -#[derive(Clone, Debug, PartialEq)] -pub enum ValueString<'a> { - Value(Cow<'a, async_graphql::Value>), - String(Cow<'a, str>), -} - impl EvalContext<'_, Ctx> { fn to_raw_value>(&self, path: &[T]) -> Option> { let ctx = self; @@ -139,10 +99,11 @@ mod tests { use http::header::{HeaderMap, HeaderValue}; use indexmap::IndexMap; use once_cell::sync::Lazy; + use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; use crate::core::http::RequestContext; use crate::core::ir::{EvalContext, ResolverContextLike, SelectionField}; - use crate::core::path::{PathGraphql, PathString, PathValue, ValueString}; + use crate::core::path::PathGraphql; use crate::core::EnvIO; struct Env { diff --git a/src/core/proto_reader/fetch.rs b/src/core/proto_reader/fetch.rs index 7267918fe0..bb8648d268 100644 --- a/src/core/proto_reader/fetch.rs +++ b/src/core/proto_reader/fetch.rs @@ -9,13 +9,13 @@ use prost::Message; use prost_reflect::prost_types::{FileDescriptorProto, FileDescriptorSet}; use serde::{Deserialize, Serialize}; use serde_json::json; +use tailcall_jq::mustache::Mustache; use crate::core::blueprint::GrpcMethod; use crate::core::config::{ConfigReaderContext, KeyValue}; use crate::core::grpc::protobuf::ProtobufSet; use crate::core::grpc::request_template::RequestBody; use crate::core::grpc::RequestTemplate; -use crate::core::mustache::Mustache; use crate::core::runtime::TargetRuntime; /// diff --git a/src/core/serde_value_ext.rs b/src/core/serde_value_ext.rs index 37a095ac6c..4e05234379 100644 --- a/src/core/serde_value_ext.rs +++ b/src/core/serde_value_ext.rs @@ -2,9 +2,9 @@ use std::borrow::Cow; use async_graphql::{Name, Value as GraphQLValue}; use indexmap::IndexMap; +use tailcall_jq::mustache::path::PathString; use crate::core::blueprint::DynamicValue; -use crate::core::path::PathString; pub trait ValueExt { fn render_value(&self, ctx: &impl PathString) -> GraphQLValue; diff --git a/tests/expression_spec.rs b/tests/expression_spec.rs index 564211dae1..d7420063a1 100644 --- a/tests/expression_spec.rs +++ b/tests/expression_spec.rs @@ -7,7 +7,7 @@ mod tests { use tailcall::core::http::RequestContext; use tailcall::core::ir::model::IR; use tailcall::core::ir::{EmptyResolverContext, Error, EvalContext}; - use tailcall::core::mustache::Mustache; + use tailcall_jq::mustache::Mustache; async fn eval(expr: &IR) -> Result { let runtime = tailcall::cli::runtime::init(&Blueprint::default()); From 5a245aae6be28705433dadbcfb0391c462889257 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Wed, 20 Nov 2024 13:03:02 -0500 Subject: [PATCH 2/2] rename `tailcall-jq` to `tailcall-template` --- Cargo.lock | 34 +++++++++---------- Cargo.toml | 2 +- ...impl_path_string_for_evaluation_context.rs | 2 +- benches/request_template_bench.rs | 2 +- src/cli/generator/generator.rs | 2 +- src/cli/llm/infer_type_name.rs | 2 +- src/core/blueprint/dynamic_value.rs | 2 +- src/core/blueprint/operators/grpc.rs | 2 +- src/core/blueprint/operators/http.rs | 2 +- src/core/config/apollo.rs | 2 +- src/core/config/directives/telemetry.rs | 2 +- src/core/config/reader_context.rs | 2 +- src/core/config/transformer/subgraph.rs | 2 +- src/core/graphql/request_template.rs | 6 ++-- src/core/grpc/request_template.rs | 8 ++--- src/core/helpers/body.rs | 4 +-- src/core/helpers/headers.rs | 4 +-- src/core/helpers/url.rs | 4 +-- src/core/http/query_encoder.rs | 2 +- src/core/http/request_template.rs | 14 ++++---- src/core/path.rs | 4 +-- src/core/proto_reader/fetch.rs | 2 +- src/core/serde_value_ext.rs | 2 +- tests/expression_spec.rs | 2 +- 24 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 694c86511d..8fff1d1ca6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2852,7 +2852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -5526,9 +5526,9 @@ dependencies = [ "tailcall-fixtures", "tailcall-hasher", "tailcall-http-cache", - "tailcall-jq", "tailcall-macros", "tailcall-prettier", + "tailcall-template", "tailcall-tracker", "tailcall-typedefs-common", "tailcall-valid", @@ -5630,20 +5630,6 @@ dependencies = [ "url", ] -[[package]] -name = "tailcall-jq" -version = "0.1.0" -source = "git+https://github.com/tailcallhq/tailcall-jq#53b7d679d657887bee72acfea19cf225e0a52de0" -dependencies = [ - "anyhow", - "async-graphql", - "async-graphql-value", - "indexmap 2.6.0", - "nom 8.0.0-alpha2", - "serde_json", - "serde_json_borrow", -] - [[package]] name = "tailcall-macros" version = "0.1.0" @@ -5663,6 +5649,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "tailcall-template" +version = "0.1.0" +source = "git+https://github.com/tailcallhq/tailcall-template#5cbe15c9bb9d34ee1674b774965aa7ed90922709" +dependencies = [ + "anyhow", + "async-graphql", + "async-graphql-value", + "indexmap 2.6.0", + "nom 8.0.0-alpha2", + "serde_json", + "serde_json_borrow", +] + [[package]] name = "tailcall-tracker" version = "0.1.0" @@ -6750,7 +6750,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 04fd12cc16..a3ae3a7650 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -174,7 +174,7 @@ tailcall-valid = { workspace = true } dashmap = "6.1.0" urlencoding = "2.1.3" tailcall-chunk = "0.2.5" -tailcall-jq = { git = "https://github.com/tailcallhq/tailcall-jq" } +tailcall-template = { git = "https://github.com/tailcallhq/tailcall-template" } # to build rquickjs bindings on systems without builtin bindings [target.'cfg(all(target_os = "windows", target_arch = "x86"))'.dependencies] diff --git a/benches/impl_path_string_for_evaluation_context.rs b/benches/impl_path_string_for_evaluation_context.rs index 29797d378a..d319252e6d 100644 --- a/benches/impl_path_string_for_evaluation_context.rs +++ b/benches/impl_path_string_for_evaluation_context.rs @@ -20,7 +20,7 @@ use tailcall::core::ir::{EvalContext, ResolverContextLike, SelectionField}; use tailcall::core::runtime::TargetRuntime; use tailcall::core::{EnvIO, FileIO, HttpIO}; use tailcall_http_cache::HttpCacheManager; -use tailcall_jq::mustache::path::PathString; +use tailcall_template::mustache::path::PathString; struct Http { client: ClientWithMiddleware, diff --git a/benches/request_template_bench.rs b/benches/request_template_bench.rs index 9f55e3cb96..701f4656f4 100644 --- a/benches/request_template_bench.rs +++ b/benches/request_template_bench.rs @@ -8,7 +8,7 @@ use tailcall::core::endpoint::Endpoint; use tailcall::core::has_headers::HasHeaders; use tailcall::core::http::RequestTemplate; use tailcall::core::json::JsonLike; -use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; +use tailcall_template::mustache::path::{PathString, PathValue, ValueString}; #[derive(Setters)] struct Context { diff --git a/src/cli/generator/generator.rs b/src/cli/generator/generator.rs index 4a44a15828..e8a56bc38d 100644 --- a/src/cli/generator/generator.rs +++ b/src/cli/generator/generator.rs @@ -4,7 +4,7 @@ use std::path::Path; use http::header::{HeaderMap, HeaderName, HeaderValue}; use inquire::Confirm; use pathdiff::diff_paths; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_valid::{ValidateInto, Validator}; use super::config::{Config, LLMConfig, Resolved, Source}; diff --git a/src/cli/llm/infer_type_name.rs b/src/cli/llm/infer_type_name.rs index 0021a36248..1d4ee96271 100644 --- a/src/cli/llm/infer_type_name.rs +++ b/src/cli/llm/infer_type_name.rs @@ -4,7 +4,7 @@ use genai::chat::{ChatMessage, ChatRequest, ChatResponse}; use indexmap::{indexset, IndexSet}; use serde::{Deserialize, Serialize}; use serde_json::json; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use super::{Error, Result, Wizard}; use crate::core::config::Config; diff --git a/src/core/blueprint/dynamic_value.rs b/src/core/blueprint/dynamic_value.rs index 3ddf7b1965..8c700bac96 100644 --- a/src/core/blueprint/dynamic_value.rs +++ b/src/core/blueprint/dynamic_value.rs @@ -1,7 +1,7 @@ use async_graphql_value::{ConstValue, Name}; use indexmap::IndexMap; use serde_json::Value; -use tailcall_jq::mustache::{Mustache, Segment}; +use tailcall_template::mustache::{Mustache, Segment}; #[derive(Debug, Clone, PartialEq)] pub enum DynamicValue { diff --git a/src/core/blueprint/operators/grpc.rs b/src/core/blueprint/operators/grpc.rs index 21aa7359bf..10f0cf9177 100644 --- a/src/core/blueprint/operators/grpc.rs +++ b/src/core/blueprint/operators/grpc.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use prost_reflect::prost_types::FileDescriptorSet; use prost_reflect::FieldDescriptor; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use super::apply_select; diff --git a/src/core/blueprint/operators/http.rs b/src/core/blueprint/operators/http.rs index 1c88acf4b0..31fe75b57c 100644 --- a/src/core/blueprint/operators/http.rs +++ b/src/core/blueprint/operators/http.rs @@ -1,4 +1,4 @@ -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use crate::core::blueprint::*; diff --git a/src/core/config/apollo.rs b/src/core/config/apollo.rs index 2049f0fe1f..cef3ba9018 100644 --- a/src/core/config/apollo.rs +++ b/src/core/config/apollo.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use crate::core::config::ConfigReaderContext; use crate::core::is_default; diff --git a/src/core/config/directives/telemetry.rs b/src/core/config/directives/telemetry.rs index 197b6ca5c7..9c889543d0 100644 --- a/src/core/config/directives/telemetry.rs +++ b/src/core/config/directives/telemetry.rs @@ -1,6 +1,6 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_macros::{DirectiveDefinition, InputDefinition}; use tailcall_valid::Validator; diff --git a/src/core/config/reader_context.rs b/src/core/config/reader_context.rs index 96ee4ceab2..4d6155cf44 100644 --- a/src/core/config/reader_context.rs +++ b/src/core/config/reader_context.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; use http::header::HeaderMap; -use tailcall_jq::mustache::path::PathString; +use tailcall_template::mustache::path::PathString; use crate::core::has_headers::HasHeaders; use crate::core::runtime::TargetRuntime; diff --git a/src/core/config/transformer/subgraph.rs b/src/core/config/transformer/subgraph.rs index 320b108eab..5cef63bfa3 100644 --- a/src/core/config/transformer/subgraph.rs +++ b/src/core/config/transformer/subgraph.rs @@ -4,7 +4,7 @@ use std::convert::identity; use std::fmt::{Display, Write}; use std::ops::Deref; -use tailcall_jq::mustache::{Mustache, Segment}; +use tailcall_template::mustache::{Mustache, Segment}; use tailcall_macros::MergeRight; use tailcall_valid::{Valid, Validator}; diff --git a/src/core/graphql/request_template.rs b/src/core/graphql/request_template.rs index 63b996b543..9ba036d477 100644 --- a/src/core/graphql/request_template.rs +++ b/src/core/graphql/request_template.rs @@ -6,8 +6,8 @@ use std::hash::{Hash, Hasher}; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; -use tailcall_jq::mustache::path::PathGraphql; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::path::PathGraphql; +use tailcall_template::mustache::Mustache; use crate::core::config::{GraphQLOperationType, KeyValue}; use crate::core::has_headers::HasHeaders; @@ -170,7 +170,7 @@ mod tests { use http::header::HeaderMap; use pretty_assertions::assert_eq; use serde_json::json; - use tailcall_jq::mustache::path::PathGraphql; + use tailcall_template::mustache::path::PathGraphql; use crate::core::config::GraphQLOperationType; use crate::core::graphql::request_template::RelatedFields; diff --git a/src/core/grpc/request_template.rs b/src/core/grpc/request_template.rs index 5f1d34637c..dacd123433 100644 --- a/src/core/grpc/request_template.rs +++ b/src/core/grpc/request_template.rs @@ -4,8 +4,8 @@ use anyhow::Result; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use tailcall_hasher::TailcallHasher; -use tailcall_jq::mustache::path::PathString; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::path::PathString; +use tailcall_template::mustache::Mustache; use url::Url; use super::request::create_grpc_request; @@ -136,8 +136,8 @@ mod tests { use http::Method; use pretty_assertions::assert_eq; use tailcall_fixtures::protobuf; - use tailcall_jq::mustache::path::PathString; - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::path::PathString; + use tailcall_template::mustache::Mustache; use super::{RequestBody, RequestTemplate}; use crate::core::blueprint::GrpcMethod; diff --git a/src/core/helpers/body.rs b/src/core/helpers/body.rs index 2ce6ccddad..75eb3b44f7 100644 --- a/src/core/helpers/body.rs +++ b/src/core/helpers/body.rs @@ -1,5 +1,5 @@ use serde_json::Value; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_valid::Valid; use crate::core::grpc::request_template::RequestBody; @@ -21,7 +21,7 @@ pub fn to_body(body: Option<&Value>) -> Valid, String> { #[cfg(test)] mod tests { - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::Mustache; use tailcall_valid::Valid; use super::to_body; diff --git a/src/core/helpers/headers.rs b/src/core/helpers/headers.rs index 0989d46fd1..f50ea75d24 100644 --- a/src/core/helpers/headers.rs +++ b/src/core/helpers/headers.rs @@ -1,5 +1,5 @@ use http::header::HeaderName; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use tailcall_valid::{Valid, ValidationError, Validator}; use crate::core::config::KeyValue; @@ -25,7 +25,7 @@ pub fn to_mustache_headers(headers: &[KeyValue]) -> Valid Valid { @@ -7,7 +7,7 @@ pub fn to_url(url: &str) -> Valid { #[cfg(test)] mod tests { - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::Mustache; use super::to_url; diff --git a/src/core/http/query_encoder.rs b/src/core/http/query_encoder.rs index 8548bb710f..f5da7850a6 100644 --- a/src/core/http/query_encoder.rs +++ b/src/core/http/query_encoder.rs @@ -1,4 +1,4 @@ -use tailcall_jq::mustache::path::ValueString; +use tailcall_template::mustache::path::ValueString; /// Defines different strategies for encoding query parameters. #[derive(Default, Debug, Clone)] diff --git a/src/core/http/request_template.rs b/src/core/http/request_template.rs index 77c8d3c4bb..1a86c80c9a 100644 --- a/src/core/http/request_template.rs +++ b/src/core/http/request_template.rs @@ -4,9 +4,9 @@ use std::hash::{Hash, Hasher}; use derive_setters::Setters; use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; -use tailcall_jq::mustache::eval::Eval; -use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; -use tailcall_jq::mustache::{Mustache, Segment}; +use tailcall_template::mustache::eval::Eval; +use tailcall_template::mustache::path::{PathString, PathValue, ValueString}; +use tailcall_template::mustache::{Mustache, Segment}; use url::Url; use super::query_encoder::QueryEncoder; @@ -311,8 +311,8 @@ mod tests { use http::header::{HeaderMap, HeaderName}; use pretty_assertions::assert_eq; use serde_json::json; - use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::path::{PathString, PathValue, ValueString}; + use tailcall_template::mustache::Mustache; use super::{Query, RequestTemplate}; use crate::core::has_headers::HasHeaders; @@ -778,7 +778,7 @@ mod tests { mod form_encoded_url { use serde_json::json; - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::Mustache; use crate::core::http::request_template::tests::Context; use crate::core::http::RequestTemplate; @@ -842,7 +842,7 @@ mod tests { use http::header::HeaderMap; use serde_json::json; - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::Mustache; use crate::core::http::request_template::tests::Context; use crate::core::http::RequestTemplate; diff --git a/src/core/path.rs b/src/core/path.rs index 9ae1d4f02c..ec2a62c050 100644 --- a/src/core/path.rs +++ b/src/core/path.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use serde_json::json; -use tailcall_jq::mustache::path::{PathGraphql, PathString, PathValue, ValueString}; +use tailcall_template::mustache::path::{PathGraphql, PathString, PathValue, ValueString}; use crate::core::ir::{EvalContext, ResolverContextLike}; @@ -99,7 +99,7 @@ mod tests { use http::header::{HeaderMap, HeaderValue}; use indexmap::IndexMap; use once_cell::sync::Lazy; - use tailcall_jq::mustache::path::{PathString, PathValue, ValueString}; + use tailcall_template::mustache::path::{PathString, PathValue, ValueString}; use crate::core::http::RequestContext; use crate::core::ir::{EvalContext, ResolverContextLike, SelectionField}; diff --git a/src/core/proto_reader/fetch.rs b/src/core/proto_reader/fetch.rs index bb8648d268..d63465d0bf 100644 --- a/src/core/proto_reader/fetch.rs +++ b/src/core/proto_reader/fetch.rs @@ -9,7 +9,7 @@ use prost::Message; use prost_reflect::prost_types::{FileDescriptorProto, FileDescriptorSet}; use serde::{Deserialize, Serialize}; use serde_json::json; -use tailcall_jq::mustache::Mustache; +use tailcall_template::mustache::Mustache; use crate::core::blueprint::GrpcMethod; use crate::core::config::{ConfigReaderContext, KeyValue}; diff --git a/src/core/serde_value_ext.rs b/src/core/serde_value_ext.rs index 4e05234379..07ce0a1fe4 100644 --- a/src/core/serde_value_ext.rs +++ b/src/core/serde_value_ext.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use async_graphql::{Name, Value as GraphQLValue}; use indexmap::IndexMap; -use tailcall_jq::mustache::path::PathString; +use tailcall_template::mustache::path::PathString; use crate::core::blueprint::DynamicValue; diff --git a/tests/expression_spec.rs b/tests/expression_spec.rs index d7420063a1..e623141018 100644 --- a/tests/expression_spec.rs +++ b/tests/expression_spec.rs @@ -7,7 +7,7 @@ mod tests { use tailcall::core::http::RequestContext; use tailcall::core::ir::model::IR; use tailcall::core::ir::{EmptyResolverContext, Error, EvalContext}; - use tailcall_jq::mustache::Mustache; + use tailcall_template::mustache::Mustache; async fn eval(expr: &IR) -> Result { let runtime = tailcall::cli::runtime::init(&Blueprint::default());