Skip to content

Commit

Permalink
refactor: renamed Property.value to Property.default
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 2, 2024
1 parent 928285f commit c5d13c8
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 231 deletions.
368 changes: 184 additions & 184 deletions fastn-builtins/src/lib.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions fastn-resolved/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Field {
pub name: String,
pub kind: fastn_resolved::KindData,
pub mutable: bool,
pub value: Option<fastn_resolved::PropertyValue>,
pub default: Option<fastn_resolved::PropertyValue>,
pub line_number: usize,
pub access_modifier: AccessModifier,
}
Expand All @@ -36,7 +36,7 @@ impl Field {
name: name.to_string(),
kind,
mutable,
value,
default: value,
line_number,
access_modifier: Default::default(),
}
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Field {
name: name.to_string(),
kind,
mutable: false,
value: None,
default: None,
line_number: 0,
access_modifier: Default::default(),
}
Expand All @@ -82,7 +82,7 @@ impl Field {
name: name.to_string(),
kind,
mutable: false,
value: Some(value),
default: Some(value),
line_number: 0,
access_modifier: Default::default(),
}
Expand All @@ -104,7 +104,7 @@ impl Field {
if self.kind.is_optional() || self.kind.is_list() {
return false;
}
self.value.is_none()
self.default.is_none()
}
}

Expand Down
2 changes: 1 addition & 1 deletion fastn-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub fn get_all_asts(
} else if let fastn_resolved::Definition::OrType(ot) = definition {
let mut fields = vec![];
for variant in &ot.variants {
if let Some(ref value) = variant.clone().fields().first().unwrap().value {
if let Some(ref value) = variant.clone().fields().first().unwrap().default {
fields.push((
variant
.name()
Expand Down
2 changes: 1 addition & 1 deletion fastn-runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub(crate) fn is_module_argument(
component_arguments.iter().find_map(|v| {
if v.name.eq(module_name) && v.kind.is_module() {
let module = v
.value
.default
.as_ref()
.and_then(|v| v.value_optional())
.and_then(|v| v.module_name_optional())?;
Expand Down
2 changes: 1 addition & 1 deletion fastn-runtime/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl fastn_runtime::extensions::ExpressionExt for fastn_resolved::Expression {

impl fastn_runtime::extensions::ArgumentExt for fastn_resolved::Argument {
fn get_default_value(&self) -> Option<fastn_runtime::Value> {
if let Some(ref value) = self.value {
if let Some(ref value) = self.default {
Some(value.to_value())
} else if self.kind.is_list() {
Some(fastn_runtime::Value::Data(fastn_resolved::Value::List {
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/executor/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl ExecuteDoc<'_> {
is_mutable: argument.mutable,
line_number: instruction.line_number,
}
} else if let Some(ref value) = argument.value {
} else if let Some(ref value) = argument.default {
value.to_owned()
} else {
unreachable!()
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/html/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ pub(crate) fn to_argument_string(
let mut properties_string = "".to_string();
for argument in arguments {
let mut result_value = "null".to_string();
if let Some(ref value) = argument.value {
if let Some(ref value) = argument.default {
if let Ok(Some(value_string)) =
ftd::html::utils::get_formatted_dep_string_from_property_value(
id, doc, value, &None, None, false,
Expand Down
1 change: 0 additions & 1 deletion ftd/src/interpreter/tdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ impl<'a> TDoc<'a> {
),
ftd::interpreter::Thing::Function(f) => (f.return_kind, false),
ftd::interpreter::Thing::Export { .. } => unreachable!(),
ftd::interpreter::Thing::Module { .. } => todo!(),
};

(
Expand Down
8 changes: 4 additions & 4 deletions ftd/src/interpreter/things/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ fn get_module_name_and_thing(
use ftd::interpreter::{PropertyValueExt, ValueExt};

let default_things = {
let value = if let Some(ref value) = component_argument.value {
let value = if let Some(ref value) = component_argument.default {
value.clone().resolve(doc, module_property.line_number)?
} else {
return ftd::interpreter::utils::e2(
Expand Down Expand Up @@ -353,7 +353,7 @@ fn get_module_name_and_thing(
module_property.line_number,
)?
{
if let Some(ref mut property_value) = argument.value {
if let Some(ref mut property_value) = argument.default {
if let fastn_resolved::PropertyValue::Value { value, .. } = property_value {
if let Some((name, thing)) = value.mut_module_optional() {
thing.extend(default_things);
Expand Down Expand Up @@ -1406,7 +1406,7 @@ impl ComponentExt for fastn_resolved::ComponentInvocation {
if arg.kind.is_module() {
let component_name = {
let (m_name, _) = match arg
.value
.default
.as_ref()
.unwrap()
.clone()
Expand Down Expand Up @@ -1541,7 +1541,7 @@ impl LoopExt for fastn_resolved::Loop {
name: self.alias.to_string(),
kind: fastn_resolved::KindData::new(kind),
mutable: self.on.is_mutable(),
value: Some(self.on.to_owned()),
default: Some(self.on.to_owned()),
line_number: self.on.line_number(),
access_modifier: Default::default(),
})
Expand Down
4 changes: 2 additions & 2 deletions ftd/src/interpreter/things/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl FunctionCallExt for fastn_resolved::FunctionCall {
if let Some(fastn_resolved::PropertyValue::Value {
value: fastn_resolved::Value::Module { ref name, .. },
..
}) = argument.value
}) = argument.default
{
if let Some(function) = function {
module_name = Some((
Expand Down Expand Up @@ -367,7 +367,7 @@ impl FunctionCallExt for fastn_resolved::FunctionCall {
loop_object_name_and_kind,
)?)
} else {
match argument.value {
match argument.default {
Some(ref value) => value.clone(),
None if argument.kind.is_optional() => fastn_resolved::PropertyValue::new_none(
argument.kind.clone(),
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/interpreter/things/or_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn validate_constant_variant(
variant: &fastn_resolved::Field,
doc: &ftd::interpreter::TDoc,
) -> ftd::interpreter::Result<()> {
if variant.value.is_none()
if variant.default.is_none()
&& !(variant.kind.is_void() || variant.kind.is_optional() || variant.kind.is_list())
{
return ftd::interpreter::utils::e2(
Expand Down
6 changes: 3 additions & 3 deletions ftd/src/interpreter/things/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl FieldExt for fastn_resolved::Field {
None
};

field.value = value;
field.default = value;
}
let resolved_fields = fields_with_resolved_kinds
.into_iter()
Expand Down Expand Up @@ -368,7 +368,7 @@ impl FieldExt for fastn_resolved::Field {
name: field.name.to_string(),
kind,
mutable: field.mutable,
value,
default: value,
line_number: field.line_number,
access_modifier: access_modifier(field.access_modifier),
},
Expand Down Expand Up @@ -396,7 +396,7 @@ impl FieldExt for fastn_resolved::Field {
name: field.name.to_string(),
kind,
mutable: field.mutable,
value: None,
default: None,
line_number: field.line_number,
access_modifier: access_modifier(field.access_modifier),
},
Expand Down
26 changes: 12 additions & 14 deletions ftd/src/interpreter/things/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,18 +854,16 @@ impl PropertyValueExt for fastn_resolved::PropertyValue {
}

let constant = or_type_variant.ok_constant(doc.name)?;
let value =
constant
.value
.clone()
.ok_or(ftd::interpreter::Error::ParseError {
message: format!(
"Expected value for constant variant `{}`",
constant.name
),
doc_id: doc.name.to_string(),
line_number: constant.line_number,
})?;
let value = constant.default.clone().ok_or(
ftd::interpreter::Error::ParseError {
message: format!(
"Expected value for constant variant `{}`",
constant.name
),
doc_id: doc.name.to_string(),
line_number: constant.line_number,
},
)?;

ftd::interpreter::StateWithThing::new_thing(
fastn_resolved::Value::new_or_type(
Expand Down Expand Up @@ -1021,8 +1019,8 @@ impl PropertyValueExt for fastn_resolved::PropertyValue {
continue;
}

if headers.is_none() && field.value.is_some() {
let value = field.value.as_ref().unwrap();
if headers.is_none() && field.default.is_some() {
let value = field.default.as_ref().unwrap();
match value {
fastn_resolved::PropertyValue::Reference {
name: refernence,
Expand Down
6 changes: 3 additions & 3 deletions ftd/src/interpreter/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ pub(crate) fn insert_module_thing(
things,
name: module_name,
} = arg
.value
.default
.as_mut()
.ok_or(ftd::interpreter::Error::ValueNotFound {
doc_id: doc.name.to_string(),
Expand Down Expand Up @@ -829,7 +829,7 @@ pub(crate) fn validate_properties_and_set_default(

if argument.kind.is_module() {
let (_default_module, arg_things) = match argument
.value
.default
.as_ref()
.unwrap()
.value(doc_id, line_number)?
Expand All @@ -854,7 +854,7 @@ pub(crate) fn validate_properties_and_set_default(
}
}
if found_default.is_none() {
if let Some(ref default_value) = argument.value {
if let Some(ref default_value) = argument.default {
properties.push(fastn_resolved::Property {
value: default_value.to_owned(),
source: fastn_resolved::PropertySource::Default,
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn document_into_js_ast(document: ftd::interpreter::Document) -> JSAstData {
} else if let ftd::interpreter::Thing::OrType(ot) = thing {
let mut fields = vec![];
for variant in &ot.variants {
if let Some(value) = &variant.clone().fields().get(0).unwrap().value {
if let Some(value) = &variant.clone().fields().get(0).unwrap().default {
fields.push((
variant
.name()
Expand Down
29 changes: 21 additions & 8 deletions v0.5/fastn-unresolved/src/resolver/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,32 @@ pub fn arguments(

fn caption_or_body(
v: &mut fastn_unresolved::UR<Option<fastn_section::HeaderValue>, ()>,
_is_caption: bool,
is_caption: bool,
arguments: &[fastn_resolved::Argument],
) {
if let fastn_unresolved::UR::UnResolved(None) = v {
*v = fastn_unresolved::UR::Resolved(())
*v = fastn_unresolved::UR::Resolved(());
return;
}
if let fastn_unresolved::UR::UnResolved(Some(_v)) = v {
// see if any of the arguments are of type caption.

let _argument = if let fastn_unresolved::UR::UnResolved(Some(_v)) = v {
// see if any of the arguments are of type caption or body
// assume there is only one such argument, because otherwise arguments would have failed
// to resolve
match arguments.iter().find(|v| v.is_caption()) {
Some(_v) => todo!(),
None => *v = fastn_unresolved::UR::Invalid(fastn_section::Error::UnexpectedCaption),
match arguments.iter().find(|v| {
if is_caption {
v.is_caption()
} else {
v.is_body()
}
}) {
Some(v) => v,
None => {
*v = fastn_unresolved::UR::Invalid(fastn_section::Error::UnexpectedCaption);
return;
}
}
}
} else {
return;
};
}

0 comments on commit c5d13c8

Please sign in to comment.