Skip to content

Commit

Permalink
Merge pull request #2014 from fastn-stack/fastn_type_value
Browse files Browse the repository at this point in the history
Moving `Value` and `PropertyValue` to `fastn-type`
  • Loading branch information
Arpita-Jaiswal authored Nov 13, 2024
2 parents ce46ff8 + 333146d commit c6fb87a
Show file tree
Hide file tree
Showing 94 changed files with 10,134 additions and 8,988 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions design/new-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub enum AST {
pub struct Document {
pub data: indexmap::IndexMap<String, ftd::interpreter::Thing>,
pub name: String,
pub tree: Vec<ftd::interpreter::Component>,
pub tree: Vec<fastn_type::Component>,
pub aliases: ftd::Map<String>,
pub js: std::collections::HashSet<String>,
pub css: std::collections::HashSet<String>,
Expand Down Expand Up @@ -264,7 +264,7 @@ pub struct InterpreterState {
pub to_process: ToProcess,
pub pending_imports: PendingImports,
pub parsed_libs: ftd::Map<ParsedDocument>,
pub instructions: Vec<ftd::interpreter::Component>,
pub instructions: Vec<fastn_type::Component>,
}

pub enum Interpreter {
Expand Down Expand Up @@ -294,7 +294,7 @@ pub enum Interpreter {
pub struct Document {
pub data: indexmap::IndexMap<String, ftd::interpreter::Thing>,
pub name: String,
pub tree: Vec<ftd::interpreter::Component>,
pub tree: Vec<fastn_type::Component>,
pub aliases: ftd::Map<String>,
pub js: std::collections::HashSet<String>,
pub css: std::collections::HashSet<String>,
Expand All @@ -305,7 +305,7 @@ pub struct Component {
pub name: String,
pub properties: Vec<Property>,
pub iteration: Box<Option<Loop>>,
pub condition: Box<Option<ftd::interpreter::Expression>>,
pub condition: Box<Option<fastn_type::Expression>>,
pub events: Vec<Event>,
pub children: Vec<Component>,
pub source: ComponentSource,
Expand Down
10 changes: 5 additions & 5 deletions fastn-core/fbt-tests/08-static-assets/output/manifest.json

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

6 changes: 3 additions & 3 deletions fastn-core/fbt-tests/09-markdown-pages/output/manifest.json

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

1,982 changes: 991 additions & 991 deletions fastn-core/fbt-tests/15-fpm-dependency-alias/output/index.html

Large diffs are not rendered by default.

1,650 changes: 825 additions & 825 deletions fastn-core/fbt-tests/19-offline-build/output/index.html

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions fastn-core/src/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ftd::interpreter::{ComponentExt, PropertyValueExt, ValueExt};

pub(crate) const TEST_FOLDER: &str = "_tests";
pub(crate) const FIXTURE_FOLDER: &str = "fixtures";
pub(crate) const TEST_FILE_EXTENSION: &str = ".test.ftd";
Expand Down Expand Up @@ -177,7 +179,7 @@ impl fastn_core::Config {
async fn read_only_instructions(
ftd_document: fastn_core::Document,
config: &fastn_core::Config,
) -> fastn_core::Result<Vec<ftd::interpreter::Component>> {
) -> fastn_core::Result<Vec<fastn_type::Component>> {
let req = fastn_core::http::Request::default();
let base_url = "/";
let mut req_config =
Expand Down Expand Up @@ -252,10 +254,10 @@ async fn read_ftd_test_file(
// This will give all overall set of instructions for a test file
// including instructions from fixture and other test instructions
async fn get_all_instructions(
instructions: &[ftd::interpreter::Component],
instructions: &[fastn_type::Component],
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
) -> fastn_core::Result<Vec<ftd::interpreter::Component>> {
) -> fastn_core::Result<Vec<fastn_type::Component>> {
let mut fixture_and_test_instructions = vec![];
let mut rest_instructions = vec![];
let mut included_fixtures: std::collections::HashSet<String> = std::collections::HashSet::new();
Expand Down Expand Up @@ -305,7 +307,7 @@ async fn get_all_instructions(
}

async fn execute_instruction(
instruction: &ftd::interpreter::Component,
instruction: &fastn_type::Component,
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
saved_cookies: &mut std::collections::HashMap<String, String>,
Expand All @@ -330,11 +332,11 @@ async fn execute_instruction(
}

async fn get_instructions_from_test(
instruction: &ftd::interpreter::Component,
instruction: &fastn_type::Component,
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
included_fixtures: &mut std::collections::HashSet<String>,
) -> fastn_core::Result<Vec<ftd::interpreter::Component>> {
) -> fastn_core::Result<Vec<fastn_type::Component>> {
let property_values = instruction.get_interpreter_property_value_of_all_arguments(doc)?;

if let Some(title) = get_optional_value_string(TEST_TITLE_HEADER, &property_values, doc)? {
Expand All @@ -345,7 +347,7 @@ async fn get_instructions_from_test(
if let Some(fixtures) = get_optional_value_list(FIXTURE_HEADER, &property_values, doc)? {
let mut resolved_fixtures = vec![];
for fixture in fixtures.iter() {
if let ftd::interpreter::Value::String { text } = fixture {
if let fastn_type::Value::String { text } = fixture {
resolved_fixtures.push(text.to_string());
}
}
Expand All @@ -365,7 +367,7 @@ async fn get_fixture_instructions(
config: &fastn_core::Config,
fixtures: Vec<String>,
included_fixtures: &mut std::collections::HashSet<String>,
) -> fastn_core::Result<Vec<ftd::interpreter::Component>> {
) -> fastn_core::Result<Vec<fastn_type::Component>> {
let mut fixture_instructions = vec![];

for fixture_file_name in fixtures.iter() {
Expand All @@ -383,7 +385,7 @@ async fn get_fixture_instructions(
async fn read_fixture_instructions(
config: &fastn_core::Config,
fixture_file_name: &str,
) -> fastn_core::Result<Vec<ftd::interpreter::Component>> {
) -> fastn_core::Result<Vec<fastn_type::Component>> {
let fixture_files = config.get_fixture_files().await?;
let current_fixture_file = fixture_files.iter().find(|d| {
d.id.trim_start_matches(format!("{}/{}/", TEST_FOLDER, FIXTURE_FOLDER).as_str())
Expand All @@ -402,7 +404,7 @@ async fn read_fixture_instructions(
}

async fn execute_post_instruction(
instruction: &ftd::interpreter::Component,
instruction: &fastn_type::Component,
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
saved_cookies: &mut std::collections::HashMap<String, String>,
Expand Down Expand Up @@ -593,7 +595,7 @@ async fn get_post_response_for_id(
}

async fn execute_get_instruction(
instruction: &ftd::interpreter::Component,
instruction: &fastn_type::Component,
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
saved_cookies: &mut std::collections::HashMap<String, String>,
Expand All @@ -620,7 +622,7 @@ async fn execute_get_instruction(
{
let mut query_strings = vec![];
for query in query_params.iter() {
if let ftd::interpreter::Value::Record { fields, .. } = query {
if let fastn_type::Value::Record { fields, .. } = query {
let resolved_key = fields
.get(QUERY_PARAMS_HEADER_KEY)
.unwrap()
Expand Down Expand Up @@ -825,9 +827,9 @@ fn update_cookies(

fn get_value_ok(
key: &str,
property_values: &ftd::Map<ftd::interpreter::PropertyValue>,
property_values: &ftd::Map<fastn_type::PropertyValue>,
line_number: usize,
) -> fastn_core::Result<ftd::interpreter::Value> {
) -> fastn_core::Result<fastn_type::Value> {
get_value(key, property_values).ok_or(fastn_core::Error::NotFound(format!(
"Key '{}' not found, line number: {}",
key, line_number
Expand All @@ -836,22 +838,22 @@ fn get_value_ok(

fn get_value(
key: &str,
property_values: &ftd::Map<ftd::interpreter::PropertyValue>,
) -> Option<ftd::interpreter::Value> {
property_values: &ftd::Map<fastn_type::PropertyValue>,
) -> Option<fastn_type::Value> {
let property_value = property_values.get(key)?;
match property_value {
ftd::interpreter::PropertyValue::Value { value, .. } => Some(value.clone()),
fastn_type::PropertyValue::Value { value, .. } => Some(value.clone()),
_ => unimplemented!(),
}
}

fn get_optional_value(
key: &str,
property_values: &ftd::Map<ftd::interpreter::PropertyValue>,
) -> Option<ftd::interpreter::Value> {
property_values: &ftd::Map<fastn_type::PropertyValue>,
) -> Option<fastn_type::Value> {
if let Some(property_value) = property_values.get(key) {
return match property_value {
ftd::interpreter::PropertyValue::Value { value, .. } => Some(value.clone()),
fastn_type::PropertyValue::Value { value, .. } => Some(value.clone()),
_ => unimplemented!(),
};
}
Expand All @@ -860,9 +862,9 @@ fn get_optional_value(

fn get_optional_value_list(
key: &str,
property_values: &ftd::Map<ftd::interpreter::PropertyValue>,
property_values: &ftd::Map<fastn_type::PropertyValue>,
doc: &ftd::interpreter::TDoc<'_>,
) -> ftd::interpreter::Result<Option<Vec<ftd::interpreter::Value>>> {
) -> ftd::interpreter::Result<Option<Vec<fastn_type::Value>>> {
let value = get_optional_value(key, property_values);
if let Some(ref value) = value {
return value.to_list(doc, false);
Expand All @@ -872,7 +874,7 @@ fn get_optional_value_list(

fn get_optional_value_string(
key: &str,
property_values: &ftd::Map<ftd::interpreter::PropertyValue>,
property_values: &ftd::Map<fastn_type::PropertyValue>,
doc: &ftd::interpreter::TDoc<'_>,
) -> ftd::interpreter::Result<Option<String>> {
let value = get_optional_value(key, property_values);
Expand Down Expand Up @@ -1050,7 +1052,7 @@ fn fastn_test_data(
}

async fn execute_redirect_instruction(
instruction: &ftd::interpreter::Component,
instruction: &fastn_type::Component,
doc: &ftd::interpreter::TDoc<'_>,
config: &fastn_core::Config,
saved_cookies: &mut std::collections::HashMap<String, String>,
Expand Down
26 changes: 13 additions & 13 deletions fastn-core/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub async fn resolve_foreign_variable2022(
download_assets: bool,
caller_module: &str,
preview_session_id: &Option<String>,
) -> ftd::interpreter::Result<ftd::interpreter::Value> {
) -> ftd::interpreter::Result<fastn_type::Value> {
let package = lib.get_current_package(caller_module)?;
if let Ok(value) = resolve_ftd_foreign_variable_2022(variable, doc_name) {
return Ok(value);
Expand Down Expand Up @@ -327,7 +327,7 @@ pub async fn resolve_foreign_variable2022(
base_url: &str,
download_assets: bool, // true: in case of `fastn build`
preview_session_id: &Option<String>,
) -> ftd::ftd2021::p1::Result<ftd::interpreter::Value> {
) -> ftd::ftd2021::p1::Result<fastn_type::Value> {
lib.push_package_under_process(module, package, preview_session_id)
.await?;
let _base_url = base_url.trim_end_matches('/');
Expand Down Expand Up @@ -412,7 +412,7 @@ pub async fn resolve_foreign_variable2022(
}

if light {
return Ok(ftd::interpreter::Value::String {
return Ok(fastn_type::Value::String {
text: light_mode.trim_start_matches('/').to_string(),
});
}
Expand Down Expand Up @@ -477,26 +477,26 @@ pub async fn resolve_foreign_variable2022(
}

if dark {
return Ok(ftd::interpreter::Value::String {
return Ok(fastn_type::Value::String {
text: dark_mode.trim_start_matches('/').to_string(),
});
}
#[allow(deprecated)]
Ok(ftd::interpreter::Value::Record {
Ok(fastn_type::Value::Record {
name: "ftd#image-src".to_string(),
fields: std::array::IntoIter::new([
(
"light".to_string(),
ftd::interpreter::PropertyValue::Value {
value: ftd::interpreter::Value::String { text: light_mode },
fastn_type::PropertyValue::Value {
value: fastn_type::Value::String { text: light_mode },
is_mutable: false,
line_number: 0,
},
),
(
"dark".to_string(),
ftd::interpreter::PropertyValue::Value {
value: ftd::interpreter::Value::String { text: dark_mode },
fastn_type::PropertyValue::Value {
value: fastn_type::Value::String { text: dark_mode },
is_mutable: false,
line_number: 0,
},
Expand All @@ -514,7 +514,7 @@ pub async fn resolve_foreign_variable2022(
preview_session_id,
)
.await?;
Ok(ftd::interpreter::Value::String {
Ok(fastn_type::Value::String {
text: format!("-/{}/{}.{}", package.name, file.replace('.', "/"), ext),
})
}
Expand All @@ -527,7 +527,7 @@ pub async fn resolve_foreign_variable2022(
preview_session_id,
)
.await?;
Ok(ftd::interpreter::Value::String {
Ok(fastn_type::Value::String {
text: format!("-/{}/{}", package.name, files),
})
}
Expand Down Expand Up @@ -891,9 +891,9 @@ fn resolve_ftd_foreign_variable(
fn resolve_ftd_foreign_variable_2022(
variable: &str,
doc_name: &str,
) -> ftd::ftd2021::p1::Result<ftd::interpreter::Value> {
) -> ftd::ftd2021::p1::Result<fastn_type::Value> {
match variable.strip_prefix("fastn/time#") {
Some("now-str") => Ok(ftd::interpreter::Value::String {
Some("now-str") => Ok(fastn_type::Value::String {
text: std::str::from_utf8(
std::process::Command::new("date")
.output()
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/src/library2022/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Library2022 {
processor: String,
doc: &'a mut ftd::interpreter::TDoc<'a>,
preview_session_id: &Option<String>,
) -> ftd::interpreter::Result<ftd::interpreter::Value> {
) -> ftd::interpreter::Result<fastn_type::Value> {
tracing::info!(
msg = "stuck-on-processor",
doc = doc.name,
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/src/library2022/processor/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub fn process(
kind: fastn_type::Kind,
doc: &ftd::interpreter::TDoc,
req_config: &fastn_core::RequestConfig,
) -> ftd::interpreter::Result<ftd::interpreter::Value> {
) -> ftd::interpreter::Result<fastn_type::Value> {
use itertools::Itertools;
#[derive(Debug, serde::Serialize)]
struct UiApp {
Expand Down
Loading

0 comments on commit c6fb87a

Please sign in to comment.