Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move mustache to tailcall-jq #3122

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 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 @@ -174,6 +174,7 @@ tailcall-valid = { workspace = true }
dashmap = "6.1.0"
urlencoding = "2.1.3"
tailcall-chunk = "0.2.5"
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]
Expand Down
2 changes: 1 addition & 1 deletion benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_template::mustache::path::PathString;

struct Http {
client: ClientWithMiddleware,
Expand Down
2 changes: 1 addition & 1 deletion benches/request_template_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_template::mustache::path::{PathString, PathValue, ValueString};

#[derive(Setters)]
struct Context {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::Path;
use http::header::{HeaderMap, HeaderName, HeaderValue};
use inquire::Confirm;
use pathdiff::diff_paths;
use tailcall_template::mustache::Mustache;
use tailcall_valid::{ValidateInto, Validator};

use super::config::{Config, LLMConfig, Resolved, Source};
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/cli/llm/infer_type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use genai::chat::{ChatMessage, ChatRequest, ChatResponse};
use indexmap::{indexset, IndexSet};
use serde::{Deserialize, Serialize};
use serde_json::json;
use tailcall_template::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 {
Expand Down
7 changes: 2 additions & 5 deletions src/core/blueprint/dynamic_value.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use async_graphql_value::{ConstValue, Name};
use indexmap::IndexMap;
use serde_json::Value;

use crate::core::mustache::Mustache;
use tailcall_template::mustache::{Mustache, Segment};

#[derive(Debug, Clone, PartialEq)]
pub enum DynamicValue<A> {
Expand All @@ -24,9 +23,7 @@ impl<A> DynamicValue<A> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;

use prost_reflect::prost_types::FileDescriptorSet;
use prost_reflect::FieldDescriptor;
use tailcall_template::mustache::Mustache;
use tailcall_valid::{Valid, ValidationError, Validator};

use super::apply_select;
Expand All @@ -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};

Expand Down
3 changes: 2 additions & 1 deletion src/core/blueprint/operators/http.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use tailcall_template::mustache::Mustache;
use tailcall_valid::{Valid, ValidationError, Validator};

use crate::core::blueprint::*;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/apollo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use tailcall_template::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")]
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/directives/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;

Check warning on line 1 in src/core/config/directives/telemetry.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/config/directives/telemetry.rs
use serde::{Deserialize, Serialize};
use tailcall_template::mustache::Mustache;
use tailcall_macros::{DirectiveDefinition, InputDefinition};
use tailcall_valid::Validator;

Expand All @@ -8,7 +9,6 @@
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/reader_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::borrow::Cow;
use std::collections::BTreeMap;

use http::header::HeaderMap;
use tailcall_template::mustache::path::PathString;

use crate::core::has_headers::HasHeaders;
use crate::core::path::PathString;
use crate::core::runtime::TargetRuntime;

pub struct ConfigReaderContext<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/core/config/transformer/subgraph.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::borrow::Borrow;
use std::collections::BTreeMap;
use std::convert::identity;
use std::fmt::{Display, Write};

Check warning on line 4 in src/core/config/transformer/subgraph.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/config/transformer/subgraph.rs
use std::ops::Deref;

use tailcall_template::mustache::{Mustache, Segment};
use tailcall_macros::MergeRight;
use tailcall_valid::{Valid, Validator};

Expand All @@ -14,8 +15,7 @@
};
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";
Expand Down
6 changes: 3 additions & 3 deletions src/core/graphql/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use std::hash::{Hash, Hasher};
use derive_setters::Setters;
use http::header::{HeaderMap, HeaderValue};
use tailcall_hasher::TailcallHasher;
use tailcall_template::mustache::path::PathGraphql;
use tailcall_template::mustache::Mustache;

use crate::core::config::{GraphQLOperationType, KeyValue};
use crate::core::has_headers::HasHeaders;
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)]
Expand Down Expand Up @@ -170,6 +170,7 @@ mod tests {
use http::header::HeaderMap;
use pretty_assertions::assert_eq;
use serde_json::json;
use tailcall_template::mustache::path::PathGraphql;

use crate::core::config::GraphQLOperationType;
use crate::core::graphql::request_template::RelatedFields;
Expand All @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/core/grpc/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use anyhow::Result;
use derive_setters::Setters;
use http::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use tailcall_hasher::TailcallHasher;
use tailcall_template::mustache::path::PathString;
use tailcall_template::mustache::Mustache;
use url::Url;

use super::request::create_grpc_request;
Expand All @@ -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");

Expand Down Expand Up @@ -136,6 +136,8 @@ mod tests {
use http::Method;
use pretty_assertions::assert_eq;
use tailcall_fixtures::protobuf;
use tailcall_template::mustache::path::PathString;
use tailcall_template::mustache::Mustache;

use super::{RequestBody, RequestTemplate};
use crate::core::blueprint::GrpcMethod;
Expand All @@ -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;
Expand Down Expand Up @@ -203,7 +204,7 @@ mod tests {
}
}

impl crate::core::path::PathString for Context {
impl PathString for Context {
fn path_string<'a, T: AsRef<str>>(&'a self, parts: &'a [T]) -> Option<Cow<'a, str>> {
self.value.path_string(parts)
}
Expand Down
Loading
Loading