Merge branch 'main' into pierremtb/issue7657-Allow-all-sweeps-to-work-on-variable-less-profiles
This commit is contained in:
@ -7,7 +7,6 @@ VITE_KC_API_WS_MODELING_URL=wss://api.dev.zoo.dev/ws/modeling/commands
|
|||||||
VITE_KC_API_BASE_URL=https://api.dev.zoo.dev
|
VITE_KC_API_BASE_URL=https://api.dev.zoo.dev
|
||||||
VITE_KC_SITE_BASE_URL=https://dev.zoo.dev
|
VITE_KC_SITE_BASE_URL=https://dev.zoo.dev
|
||||||
VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev
|
VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev
|
||||||
VITE_KC_SKIP_AUTH=false
|
|
||||||
VITE_KC_CONNECTION_TIMEOUT_MS=5000
|
VITE_KC_CONNECTION_TIMEOUT_MS=5000
|
||||||
#VITE_WASM_URL="optional way of overriding the wasm url, particular for unit tests which need this if you running not on the default 3000 port"
|
#VITE_WASM_URL="optional way of overriding the wasm url, particular for unit tests which need this if you running not on the default 3000 port"
|
||||||
#VITE_KC_DEV_TOKEN="optional token to skip auth in the app"
|
#VITE_KC_DEV_TOKEN="optional token to skip auth in the app"
|
||||||
|
@ -3,5 +3,4 @@ VITE_KC_API_WS_MODELING_URL=wss://api.zoo.dev/ws/modeling/commands
|
|||||||
VITE_KC_API_BASE_URL=https://api.zoo.dev
|
VITE_KC_API_BASE_URL=https://api.zoo.dev
|
||||||
VITE_KC_SITE_BASE_URL=https://zoo.dev
|
VITE_KC_SITE_BASE_URL=https://zoo.dev
|
||||||
VITE_KC_SITE_APP_URL=https://app.zoo.dev
|
VITE_KC_SITE_APP_URL=https://app.zoo.dev
|
||||||
VITE_KC_SKIP_AUTH=false
|
|
||||||
VITE_KC_CONNECTION_TIMEOUT_MS=15000
|
VITE_KC_CONNECTION_TIMEOUT_MS=15000
|
||||||
|
1
interface.d.ts
vendored
1
interface.d.ts
vendored
@ -79,7 +79,6 @@ export interface IElectronAPI {
|
|||||||
VITE_KC_API_BASE_URL: string
|
VITE_KC_API_BASE_URL: string
|
||||||
VITE_KC_SITE_BASE_URL: string
|
VITE_KC_SITE_BASE_URL: string
|
||||||
VITE_KC_SITE_APP_URL: string
|
VITE_KC_SITE_APP_URL: string
|
||||||
VITE_KC_SKIP_AUTH: string
|
|
||||||
VITE_KC_CONNECTION_TIMEOUT_MS: string
|
VITE_KC_CONNECTION_TIMEOUT_MS: string
|
||||||
VITE_KC_DEV_TOKEN: string
|
VITE_KC_DEV_TOKEN: string
|
||||||
NODE_ENV: string
|
NODE_ENV: string
|
||||||
|
@ -864,6 +864,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.execute(exec_state, ctx).await,
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.execute(exec_state, ctx).await,
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.get_result(exec_state, ctx).await,
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.get_result(exec_state, ctx).await,
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.get_result(exec_state, ctx).await,
|
BinaryPart::MemberExpression(member_expression) => member_expression.get_result(exec_state, ctx).await,
|
||||||
|
BinaryPart::ArrayExpression(e) => e.execute(exec_state, ctx).await,
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.execute(exec_state, ctx).await,
|
||||||
|
BinaryPart::ObjectExpression(e) => e.execute(exec_state, ctx).await,
|
||||||
BinaryPart::IfExpression(e) => e.get_result(exec_state, ctx).await,
|
BinaryPart::IfExpression(e) => e.get_result(exec_state, ctx).await,
|
||||||
BinaryPart::AscribedExpression(e) => e.get_result(exec_state, ctx).await,
|
BinaryPart::AscribedExpression(e) => e.get_result(exec_state, ctx).await,
|
||||||
}
|
}
|
||||||
@ -991,6 +994,39 @@ impl Node<MemberExpression> {
|
|||||||
|
|
||||||
// Check the property and object match -- e.g. ints for arrays, strs for objects.
|
// Check the property and object match -- e.g. ints for arrays, strs for objects.
|
||||||
match (object, property, self.computed) {
|
match (object, property, self.computed) {
|
||||||
|
(KclValue::Plane { value: plane }, Property::String(property), false) => match property.as_str() {
|
||||||
|
"yAxis" => {
|
||||||
|
let (p, u) = plane.info.y_axis.as_3_dims();
|
||||||
|
Ok(KclValue::array_from_point3d(
|
||||||
|
p,
|
||||||
|
NumericType::Known(crate::exec::UnitType::Length(u)),
|
||||||
|
vec![meta],
|
||||||
|
))
|
||||||
|
}
|
||||||
|
"xAxis" => {
|
||||||
|
let (p, u) = plane.info.x_axis.as_3_dims();
|
||||||
|
Ok(KclValue::array_from_point3d(
|
||||||
|
p,
|
||||||
|
NumericType::Known(crate::exec::UnitType::Length(u)),
|
||||||
|
vec![meta],
|
||||||
|
))
|
||||||
|
}
|
||||||
|
"origin" => {
|
||||||
|
let (p, u) = plane.info.origin.as_3_dims();
|
||||||
|
Ok(KclValue::array_from_point3d(
|
||||||
|
p,
|
||||||
|
NumericType::Known(crate::exec::UnitType::Length(u)),
|
||||||
|
vec![meta],
|
||||||
|
))
|
||||||
|
}
|
||||||
|
other => Err(KclError::new_undefined_value(
|
||||||
|
KclErrorDetails::new(
|
||||||
|
format!("Property '{other}' not found in plane"),
|
||||||
|
vec![self.clone().into()],
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)),
|
||||||
|
},
|
||||||
(KclValue::Object { value: map, meta: _ }, Property::String(property), false) => {
|
(KclValue::Object { value: map, meta: _ }, Property::String(property), false) => {
|
||||||
if let Some(value) = map.get(&property) {
|
if let Some(value) = map.get(&property) {
|
||||||
Ok(value.to_owned())
|
Ok(value.to_owned())
|
||||||
@ -1010,7 +1046,22 @@ impl Node<MemberExpression> {
|
|||||||
vec![self.clone().into()],
|
vec![self.clone().into()],
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
(KclValue::Object { .. }, p, _) => {
|
(KclValue::Object { value: map, .. }, p @ Property::UInt(i), _) => {
|
||||||
|
if i == 0
|
||||||
|
&& let Some(value) = map.get("x")
|
||||||
|
{
|
||||||
|
return Ok(value.to_owned());
|
||||||
|
}
|
||||||
|
if i == 1
|
||||||
|
&& let Some(value) = map.get("y")
|
||||||
|
{
|
||||||
|
return Ok(value.to_owned());
|
||||||
|
}
|
||||||
|
if i == 2
|
||||||
|
&& let Some(value) = map.get("z")
|
||||||
|
{
|
||||||
|
return Ok(value.to_owned());
|
||||||
|
}
|
||||||
let t = p.type_name();
|
let t = p.type_name();
|
||||||
let article = article_for(t);
|
let article = article_for(t);
|
||||||
Err(KclError::new_semantic(KclErrorDetails::new(
|
Err(KclError::new_semantic(KclErrorDetails::new(
|
||||||
@ -2202,4 +2253,12 @@ y = x[0mm + 1]
|
|||||||
"#;
|
"#;
|
||||||
parse_execute(ast).await.unwrap_err();
|
parse_execute(ast).await.unwrap_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn getting_property_of_plane() {
|
||||||
|
// let ast = include_str!("../../tests/inputs/planestuff.kcl");
|
||||||
|
let ast = std::fs::read_to_string("tests/inputs/planestuff.kcl").unwrap();
|
||||||
|
|
||||||
|
parse_execute(&ast).await.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,6 +921,12 @@ impl Point3d {
|
|||||||
units: UnitLen::Unknown,
|
units: UnitLen::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_3_dims(&self) -> ([f64; 3], UnitLen) {
|
||||||
|
let p = [self.x, self.y, self.z];
|
||||||
|
let u = self.units;
|
||||||
|
(p, u)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[TyF64; 3]> for Point3d {
|
impl From<[TyF64; 3]> for Point3d {
|
||||||
|
@ -458,6 +458,31 @@ impl KclValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Put the point into a KCL point.
|
||||||
|
pub fn array_from_point3d(p: [f64; 3], ty: NumericType, meta: Vec<Metadata>) -> Self {
|
||||||
|
let [x, y, z] = p;
|
||||||
|
Self::HomArray {
|
||||||
|
value: vec![
|
||||||
|
Self::Number {
|
||||||
|
value: x,
|
||||||
|
meta: meta.clone(),
|
||||||
|
ty,
|
||||||
|
},
|
||||||
|
Self::Number {
|
||||||
|
value: y,
|
||||||
|
meta: meta.clone(),
|
||||||
|
ty,
|
||||||
|
},
|
||||||
|
Self::Number {
|
||||||
|
value: z,
|
||||||
|
meta: meta.clone(),
|
||||||
|
ty,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
ty: ty.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn as_usize(&self) -> Option<usize> {
|
pub(crate) fn as_usize(&self) -> Option<usize> {
|
||||||
match self {
|
match self {
|
||||||
KclValue::Number { value, .. } => crate::try_f64_to_usize(*value),
|
KclValue::Number { value, .. } => crate::try_f64_to_usize(*value),
|
||||||
|
@ -149,6 +149,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::UnaryExpression(unary_expression) => {
|
BinaryPart::UnaryExpression(unary_expression) => {
|
||||||
unary_expression.get_hover_value_for_position(pos, code, opts)
|
unary_expression.get_hover_value_for_position(pos, code, opts)
|
||||||
}
|
}
|
||||||
|
BinaryPart::ArrayExpression(e) => e.get_hover_value_for_position(pos, code, opts),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.get_hover_value_for_position(pos, code, opts),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.get_hover_value_for_position(pos, code, opts),
|
||||||
BinaryPart::IfExpression(e) => e.get_hover_value_for_position(pos, code, opts),
|
BinaryPart::IfExpression(e) => e.get_hover_value_for_position(pos, code, opts),
|
||||||
BinaryPart::AscribedExpression(e) => e.expr.get_hover_value_for_position(pos, code, opts),
|
BinaryPart::AscribedExpression(e) => e.expr.get_hover_value_for_position(pos, code, opts),
|
||||||
BinaryPart::MemberExpression(member_expression) => {
|
BinaryPart::MemberExpression(member_expression) => {
|
||||||
|
@ -161,6 +161,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(ce) => ce.compute_digest(),
|
BinaryPart::CallExpressionKw(ce) => ce.compute_digest(),
|
||||||
BinaryPart::UnaryExpression(ue) => ue.compute_digest(),
|
BinaryPart::UnaryExpression(ue) => ue.compute_digest(),
|
||||||
BinaryPart::MemberExpression(me) => me.compute_digest(),
|
BinaryPart::MemberExpression(me) => me.compute_digest(),
|
||||||
|
BinaryPart::ArrayExpression(e) => e.compute_digest(),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.compute_digest(),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.compute_digest(),
|
||||||
BinaryPart::IfExpression(e) => e.compute_digest(),
|
BinaryPart::IfExpression(e) => e.compute_digest(),
|
||||||
BinaryPart::AscribedExpression(e) => e.compute_digest(),
|
BinaryPart::AscribedExpression(e) => e.compute_digest(),
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.module_id,
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.module_id,
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.module_id,
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.module_id,
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.module_id,
|
BinaryPart::MemberExpression(member_expression) => member_expression.module_id,
|
||||||
|
BinaryPart::ArrayExpression(e) => e.module_id,
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.module_id,
|
||||||
|
BinaryPart::ObjectExpression(e) => e.module_id,
|
||||||
BinaryPart::IfExpression(e) => e.module_id,
|
BinaryPart::IfExpression(e) => e.module_id,
|
||||||
BinaryPart::AscribedExpression(e) => e.module_id,
|
BinaryPart::AscribedExpression(e) => e.module_id,
|
||||||
}
|
}
|
||||||
|
@ -1214,6 +1214,9 @@ impl From<&BinaryPart> for Expr {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => Expr::CallExpressionKw(call_expression.clone()),
|
BinaryPart::CallExpressionKw(call_expression) => Expr::CallExpressionKw(call_expression.clone()),
|
||||||
BinaryPart::UnaryExpression(unary_expression) => Expr::UnaryExpression(unary_expression.clone()),
|
BinaryPart::UnaryExpression(unary_expression) => Expr::UnaryExpression(unary_expression.clone()),
|
||||||
BinaryPart::MemberExpression(member_expression) => Expr::MemberExpression(member_expression.clone()),
|
BinaryPart::MemberExpression(member_expression) => Expr::MemberExpression(member_expression.clone()),
|
||||||
|
BinaryPart::ArrayExpression(e) => Expr::ArrayExpression(e.clone()),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => Expr::ArrayRangeExpression(e.clone()),
|
||||||
|
BinaryPart::ObjectExpression(e) => Expr::ObjectExpression(e.clone()),
|
||||||
BinaryPart::IfExpression(e) => Expr::IfExpression(e.clone()),
|
BinaryPart::IfExpression(e) => Expr::IfExpression(e.clone()),
|
||||||
BinaryPart::AscribedExpression(e) => Expr::AscribedExpression(e.clone()),
|
BinaryPart::AscribedExpression(e) => Expr::AscribedExpression(e.clone()),
|
||||||
}
|
}
|
||||||
@ -1281,6 +1284,9 @@ pub enum BinaryPart {
|
|||||||
CallExpressionKw(BoxNode<CallExpressionKw>),
|
CallExpressionKw(BoxNode<CallExpressionKw>),
|
||||||
UnaryExpression(BoxNode<UnaryExpression>),
|
UnaryExpression(BoxNode<UnaryExpression>),
|
||||||
MemberExpression(BoxNode<MemberExpression>),
|
MemberExpression(BoxNode<MemberExpression>),
|
||||||
|
ArrayExpression(BoxNode<ArrayExpression>),
|
||||||
|
ArrayRangeExpression(BoxNode<ArrayRangeExpression>),
|
||||||
|
ObjectExpression(BoxNode<ObjectExpression>),
|
||||||
IfExpression(BoxNode<IfExpression>),
|
IfExpression(BoxNode<IfExpression>),
|
||||||
AscribedExpression(BoxNode<AscribedExpression>),
|
AscribedExpression(BoxNode<AscribedExpression>),
|
||||||
}
|
}
|
||||||
@ -1307,6 +1313,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.get_constraint_level(),
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.get_constraint_level(),
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.get_constraint_level(),
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.get_constraint_level(),
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.get_constraint_level(),
|
BinaryPart::MemberExpression(member_expression) => member_expression.get_constraint_level(),
|
||||||
|
BinaryPart::ArrayExpression(e) => e.get_constraint_level(),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.get_constraint_level(),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.get_constraint_level(),
|
||||||
BinaryPart::IfExpression(e) => e.get_constraint_level(),
|
BinaryPart::IfExpression(e) => e.get_constraint_level(),
|
||||||
BinaryPart::AscribedExpression(e) => e.expr.get_constraint_level(),
|
BinaryPart::AscribedExpression(e) => e.expr.get_constraint_level(),
|
||||||
}
|
}
|
||||||
@ -1320,6 +1329,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.replace_value(source_range, new_value),
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.replace_value(source_range, new_value),
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.replace_value(source_range, new_value),
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.replace_value(source_range, new_value),
|
||||||
BinaryPart::MemberExpression(_) => {}
|
BinaryPart::MemberExpression(_) => {}
|
||||||
|
BinaryPart::ArrayExpression(e) => e.replace_value(source_range, new_value),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.replace_value(source_range, new_value),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.replace_value(source_range, new_value),
|
||||||
BinaryPart::IfExpression(e) => e.replace_value(source_range, new_value),
|
BinaryPart::IfExpression(e) => e.replace_value(source_range, new_value),
|
||||||
BinaryPart::AscribedExpression(e) => e.expr.replace_value(source_range, new_value),
|
BinaryPart::AscribedExpression(e) => e.expr.replace_value(source_range, new_value),
|
||||||
}
|
}
|
||||||
@ -1333,6 +1345,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.start,
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.start,
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.start,
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.start,
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.start,
|
BinaryPart::MemberExpression(member_expression) => member_expression.start,
|
||||||
|
BinaryPart::ArrayExpression(e) => e.start,
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.start,
|
||||||
|
BinaryPart::ObjectExpression(e) => e.start,
|
||||||
BinaryPart::IfExpression(e) => e.start,
|
BinaryPart::IfExpression(e) => e.start,
|
||||||
BinaryPart::AscribedExpression(e) => e.start,
|
BinaryPart::AscribedExpression(e) => e.start,
|
||||||
}
|
}
|
||||||
@ -1346,6 +1361,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.end,
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.end,
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.end,
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.end,
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.end,
|
BinaryPart::MemberExpression(member_expression) => member_expression.end,
|
||||||
|
BinaryPart::ArrayExpression(e) => e.end,
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.end,
|
||||||
|
BinaryPart::ObjectExpression(e) => e.end,
|
||||||
BinaryPart::IfExpression(e) => e.end,
|
BinaryPart::IfExpression(e) => e.end,
|
||||||
BinaryPart::AscribedExpression(e) => e.end,
|
BinaryPart::AscribedExpression(e) => e.end,
|
||||||
}
|
}
|
||||||
@ -1360,6 +1378,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.rename_identifiers(old_name, new_name),
|
BinaryPart::CallExpressionKw(call_expression) => call_expression.rename_identifiers(old_name, new_name),
|
||||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.rename_identifiers(old_name, new_name),
|
BinaryPart::UnaryExpression(unary_expression) => unary_expression.rename_identifiers(old_name, new_name),
|
||||||
BinaryPart::MemberExpression(member_expression) => member_expression.rename_identifiers(old_name, new_name),
|
BinaryPart::MemberExpression(member_expression) => member_expression.rename_identifiers(old_name, new_name),
|
||||||
|
BinaryPart::ArrayExpression(e) => e.rename_identifiers(old_name, new_name),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.rename_identifiers(old_name, new_name),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.rename_identifiers(old_name, new_name),
|
||||||
BinaryPart::IfExpression(if_expression) => if_expression.rename_identifiers(old_name, new_name),
|
BinaryPart::IfExpression(if_expression) => if_expression.rename_identifiers(old_name, new_name),
|
||||||
BinaryPart::AscribedExpression(e) => e.expr.rename_identifiers(old_name, new_name),
|
BinaryPart::AscribedExpression(e) => e.expr.rename_identifiers(old_name, new_name),
|
||||||
}
|
}
|
||||||
|
@ -624,9 +624,6 @@ fn operand(i: &mut TokenSlice) -> ModalResult<BinaryPart> {
|
|||||||
Expr::FunctionExpression(_)
|
Expr::FunctionExpression(_)
|
||||||
| Expr::PipeExpression(_)
|
| Expr::PipeExpression(_)
|
||||||
| Expr::PipeSubstitution(_)
|
| Expr::PipeSubstitution(_)
|
||||||
| Expr::ArrayExpression(_)
|
|
||||||
| Expr::ArrayRangeExpression(_)
|
|
||||||
| Expr::ObjectExpression(_)
|
|
||||||
| Expr::LabelledExpression(..) => return Err(CompilationError::fatal(source_range, TODO_783)),
|
| Expr::LabelledExpression(..) => return Err(CompilationError::fatal(source_range, TODO_783)),
|
||||||
Expr::None(_) => {
|
Expr::None(_) => {
|
||||||
return Err(CompilationError::fatal(
|
return Err(CompilationError::fatal(
|
||||||
@ -652,6 +649,9 @@ fn operand(i: &mut TokenSlice) -> ModalResult<BinaryPart> {
|
|||||||
Expr::BinaryExpression(x) => BinaryPart::BinaryExpression(x),
|
Expr::BinaryExpression(x) => BinaryPart::BinaryExpression(x),
|
||||||
Expr::CallExpressionKw(x) => BinaryPart::CallExpressionKw(x),
|
Expr::CallExpressionKw(x) => BinaryPart::CallExpressionKw(x),
|
||||||
Expr::MemberExpression(x) => BinaryPart::MemberExpression(x),
|
Expr::MemberExpression(x) => BinaryPart::MemberExpression(x),
|
||||||
|
Expr::ArrayExpression(x) => BinaryPart::ArrayExpression(x),
|
||||||
|
Expr::ArrayRangeExpression(x) => BinaryPart::ArrayRangeExpression(x),
|
||||||
|
Expr::ObjectExpression(x) => BinaryPart::ObjectExpression(x),
|
||||||
Expr::IfExpression(x) => BinaryPart::IfExpression(x),
|
Expr::IfExpression(x) => BinaryPart::IfExpression(x),
|
||||||
Expr::AscribedExpression(x) => BinaryPart::AscribedExpression(x),
|
Expr::AscribedExpression(x) => BinaryPart::AscribedExpression(x),
|
||||||
};
|
};
|
||||||
@ -2115,6 +2115,8 @@ fn possible_operands(i: &mut TokenSlice) -> ModalResult<Expr> {
|
|||||||
literal.map(Expr::Literal),
|
literal.map(Expr::Literal),
|
||||||
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
||||||
name.map(Box::new).map(Expr::Name),
|
name.map(Box::new).map(Expr::Name),
|
||||||
|
array,
|
||||||
|
object.map(Box::new).map(Expr::ObjectExpression),
|
||||||
binary_expr_in_parens.map(Box::new).map(Expr::BinaryExpression),
|
binary_expr_in_parens.map(Box::new).map(Expr::BinaryExpression),
|
||||||
unnecessarily_bracketed,
|
unnecessarily_bracketed,
|
||||||
))
|
))
|
||||||
@ -3398,6 +3400,27 @@ mod tests {
|
|||||||
operand.parse(tokens).unwrap();
|
operand.parse(tokens).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_binary_operator_on_array() {
|
||||||
|
let tokens = crate::parsing::token::lex("[0] + 1", ModuleId::default()).unwrap();
|
||||||
|
let tokens = tokens.as_slice();
|
||||||
|
binary_expression.parse(tokens).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_binary_operator_on_object() {
|
||||||
|
let tokens = crate::parsing::token::lex("{ a = 1 } + 2", ModuleId::default()).unwrap();
|
||||||
|
let tokens = tokens.as_slice();
|
||||||
|
binary_expression.parse(tokens).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_call_array_operator() {
|
||||||
|
let tokens = crate::parsing::token::lex("f([0] + 1)", ModuleId::default()).unwrap();
|
||||||
|
let tokens = tokens.as_slice();
|
||||||
|
fn_call_kw.parse(tokens).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn weird_program_just_a_pipe() {
|
fn weird_program_just_a_pipe() {
|
||||||
let tokens = crate::parsing::token::lex("|", ModuleId::default()).unwrap();
|
let tokens = crate::parsing::token::lex("|", ModuleId::default()).unwrap();
|
||||||
|
@ -779,6 +779,27 @@ mod add_lots {
|
|||||||
super::execute(TEST_NAME, false).await
|
super::execute(TEST_NAME, false).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mod add_arrays {
|
||||||
|
const TEST_NAME: &str = "add_arrays";
|
||||||
|
|
||||||
|
/// Test parsing KCL.
|
||||||
|
#[test]
|
||||||
|
fn parse() {
|
||||||
|
super::parse(TEST_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn unparse() {
|
||||||
|
super::unparse(TEST_NAME).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test that KCL is executed correctly.
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn kcl_test_execute() {
|
||||||
|
super::execute(TEST_NAME, false).await
|
||||||
|
}
|
||||||
|
}
|
||||||
mod argument_error {
|
mod argument_error {
|
||||||
//! The argument error points to the problematic argument in the call site,
|
//! The argument error points to the problematic argument in the call site,
|
||||||
//! not the function definition that the variable points to.
|
//! not the function definition that the variable points to.
|
||||||
|
@ -363,6 +363,9 @@ impl BinaryPart {
|
|||||||
BinaryPart::MemberExpression(member_expression) => {
|
BinaryPart::MemberExpression(member_expression) => {
|
||||||
member_expression.recast(options, indentation_level, ctxt)
|
member_expression.recast(options, indentation_level, ctxt)
|
||||||
}
|
}
|
||||||
|
BinaryPart::ArrayExpression(e) => e.recast(options, indentation_level, ctxt),
|
||||||
|
BinaryPart::ArrayRangeExpression(e) => e.recast(options, indentation_level, ctxt),
|
||||||
|
BinaryPart::ObjectExpression(e) => e.recast(options, indentation_level, ctxt),
|
||||||
BinaryPart::IfExpression(e) => e.recast(options, indentation_level, ExprContext::Other),
|
BinaryPart::IfExpression(e) => e.recast(options, indentation_level, ExprContext::Other),
|
||||||
BinaryPart::AscribedExpression(e) => e.recast(options, indentation_level, ExprContext::Other),
|
BinaryPart::AscribedExpression(e) => e.recast(options, indentation_level, ExprContext::Other),
|
||||||
}
|
}
|
||||||
@ -745,6 +748,9 @@ impl UnaryExpression {
|
|||||||
BinaryPart::Literal(_)
|
BinaryPart::Literal(_)
|
||||||
| BinaryPart::Name(_)
|
| BinaryPart::Name(_)
|
||||||
| BinaryPart::MemberExpression(_)
|
| BinaryPart::MemberExpression(_)
|
||||||
|
| BinaryPart::ArrayExpression(_)
|
||||||
|
| BinaryPart::ArrayRangeExpression(_)
|
||||||
|
| BinaryPart::ObjectExpression(_)
|
||||||
| BinaryPart::IfExpression(_)
|
| BinaryPart::IfExpression(_)
|
||||||
| BinaryPart::AscribedExpression(_)
|
| BinaryPart::AscribedExpression(_)
|
||||||
| BinaryPart::CallExpressionKw(_) => {
|
| BinaryPart::CallExpressionKw(_) => {
|
||||||
|
@ -220,6 +220,9 @@ impl<'tree> From<&'tree types::BinaryPart> for Node<'tree> {
|
|||||||
types::BinaryPart::CallExpressionKw(ce) => ce.as_ref().into(),
|
types::BinaryPart::CallExpressionKw(ce) => ce.as_ref().into(),
|
||||||
types::BinaryPart::UnaryExpression(ue) => ue.as_ref().into(),
|
types::BinaryPart::UnaryExpression(ue) => ue.as_ref().into(),
|
||||||
types::BinaryPart::MemberExpression(me) => me.as_ref().into(),
|
types::BinaryPart::MemberExpression(me) => me.as_ref().into(),
|
||||||
|
types::BinaryPart::ArrayExpression(e) => e.as_ref().into(),
|
||||||
|
types::BinaryPart::ArrayRangeExpression(e) => e.as_ref().into(),
|
||||||
|
types::BinaryPart::ObjectExpression(e) => e.as_ref().into(),
|
||||||
types::BinaryPart::IfExpression(e) => e.as_ref().into(),
|
types::BinaryPart::IfExpression(e) => e.as_ref().into(),
|
||||||
types::BinaryPart::AscribedExpression(e) => e.as_ref().into(),
|
types::BinaryPart::AscribedExpression(e) => e.as_ref().into(),
|
||||||
}
|
}
|
||||||
|
18
rust/kcl-lib/tests/add_arrays/artifact_commands.snap
Normal file
18
rust/kcl-lib/tests/add_arrays/artifact_commands.snap
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Artifact commands add_arrays.kcl
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"rust/kcl-lib/tests/add_arrays/input.kcl": [],
|
||||||
|
"std::appearance": [],
|
||||||
|
"std::array": [],
|
||||||
|
"std::math": [],
|
||||||
|
"std::prelude": [],
|
||||||
|
"std::sketch": [],
|
||||||
|
"std::solid": [],
|
||||||
|
"std::sweep": [],
|
||||||
|
"std::transform": [],
|
||||||
|
"std::turns": [],
|
||||||
|
"std::types": [],
|
||||||
|
"std::units": []
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Artifact graph flowchart add_arrays.kcl
|
||||||
|
extension: md
|
||||||
|
snapshot_kind: binary
|
||||||
|
---
|
@ -0,0 +1,3 @@
|
|||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
```
|
106
rust/kcl-lib/tests/add_arrays/ast.snap
Normal file
106
rust/kcl-lib/tests/add_arrays/ast.snap
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Result of parsing add_arrays.kcl
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"Ok": {
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"commentStart": 0,
|
||||||
|
"declaration": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"id": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"name": "answer",
|
||||||
|
"start": 0,
|
||||||
|
"type": "Identifier"
|
||||||
|
},
|
||||||
|
"init": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"left": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"raw": "0",
|
||||||
|
"start": 0,
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"value": {
|
||||||
|
"value": 0.0,
|
||||||
|
"suffix": "None"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"raw": "1",
|
||||||
|
"start": 0,
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"value": {
|
||||||
|
"value": 1.0,
|
||||||
|
"suffix": "None"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"start": 0,
|
||||||
|
"type": "ArrayExpression",
|
||||||
|
"type": "ArrayExpression"
|
||||||
|
},
|
||||||
|
"moduleId": 0,
|
||||||
|
"operator": "+",
|
||||||
|
"right": {
|
||||||
|
"commentStart": 0,
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"raw": "2",
|
||||||
|
"start": 0,
|
||||||
|
"type": "Literal",
|
||||||
|
"type": "Literal",
|
||||||
|
"value": {
|
||||||
|
"value": 2.0,
|
||||||
|
"suffix": "None"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"start": 0,
|
||||||
|
"type": "ArrayExpression",
|
||||||
|
"type": "ArrayExpression"
|
||||||
|
},
|
||||||
|
"start": 0,
|
||||||
|
"type": "BinaryExpression",
|
||||||
|
"type": "BinaryExpression"
|
||||||
|
},
|
||||||
|
"moduleId": 0,
|
||||||
|
"start": 0,
|
||||||
|
"type": "VariableDeclarator"
|
||||||
|
},
|
||||||
|
"end": 0,
|
||||||
|
"kind": "const",
|
||||||
|
"moduleId": 0,
|
||||||
|
"start": 0,
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"type": "VariableDeclaration"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commentStart": 0,
|
||||||
|
"end": 0,
|
||||||
|
"moduleId": 0,
|
||||||
|
"start": 0
|
||||||
|
}
|
||||||
|
}
|
12
rust/kcl-lib/tests/add_arrays/execution_error.snap
Normal file
12
rust/kcl-lib/tests/add_arrays/execution_error.snap
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Error from executing add_arrays.kcl
|
||||||
|
---
|
||||||
|
KCL Semantic error
|
||||||
|
|
||||||
|
× semantic: Expected a number, but found an array of `number`, `number`
|
||||||
|
╭────
|
||||||
|
1 │ answer = [0, 1] + [2]
|
||||||
|
· ───┬──
|
||||||
|
· ╰── tests/add_arrays/input.kcl
|
||||||
|
╰────
|
1
rust/kcl-lib/tests/add_arrays/input.kcl
Normal file
1
rust/kcl-lib/tests/add_arrays/input.kcl
Normal file
@ -0,0 +1 @@
|
|||||||
|
answer = [0, 1] + [2]
|
96
rust/kcl-lib/tests/add_arrays/ops.snap
Normal file
96
rust/kcl-lib/tests/add_arrays/ops.snap
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Operations executed add_arrays.kcl
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"rust/kcl-lib/tests/add_arrays/input.kcl": [],
|
||||||
|
"std::appearance": [],
|
||||||
|
"std::array": [],
|
||||||
|
"std::math": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"name": "PI",
|
||||||
|
"value": {
|
||||||
|
"type": "Number",
|
||||||
|
"value": 3.141592653589793,
|
||||||
|
"ty": {
|
||||||
|
"type": "Unknown"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "export",
|
||||||
|
"nodePath": {
|
||||||
|
"steps": []
|
||||||
|
},
|
||||||
|
"sourceRange": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"name": "E",
|
||||||
|
"value": {
|
||||||
|
"type": "Number",
|
||||||
|
"value": 2.718281828459045,
|
||||||
|
"ty": {
|
||||||
|
"type": "Known",
|
||||||
|
"type": "Count"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "export",
|
||||||
|
"nodePath": {
|
||||||
|
"steps": []
|
||||||
|
},
|
||||||
|
"sourceRange": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"name": "TAU",
|
||||||
|
"value": {
|
||||||
|
"type": "Number",
|
||||||
|
"value": 6.283185307179586,
|
||||||
|
"ty": {
|
||||||
|
"type": "Known",
|
||||||
|
"type": "Count"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "export",
|
||||||
|
"nodePath": {
|
||||||
|
"steps": []
|
||||||
|
},
|
||||||
|
"sourceRange": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"std::prelude": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"name": "START",
|
||||||
|
"value": {
|
||||||
|
"type": "String",
|
||||||
|
"value": "start"
|
||||||
|
},
|
||||||
|
"visibility": "export",
|
||||||
|
"nodePath": {
|
||||||
|
"steps": []
|
||||||
|
},
|
||||||
|
"sourceRange": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"name": "END",
|
||||||
|
"value": {
|
||||||
|
"type": "String",
|
||||||
|
"value": "end"
|
||||||
|
},
|
||||||
|
"visibility": "export",
|
||||||
|
"nodePath": {
|
||||||
|
"steps": []
|
||||||
|
},
|
||||||
|
"sourceRange": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"std::sketch": [],
|
||||||
|
"std::solid": [],
|
||||||
|
"std::sweep": [],
|
||||||
|
"std::transform": [],
|
||||||
|
"std::turns": [],
|
||||||
|
"std::types": [],
|
||||||
|
"std::units": []
|
||||||
|
}
|
5
rust/kcl-lib/tests/add_arrays/unparsed.snap
Normal file
5
rust/kcl-lib/tests/add_arrays/unparsed.snap
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Result of unparsing add_arrays.kcl
|
||||||
|
---
|
||||||
|
answer = [0, 1] + [2]
|
60
rust/kcl-lib/tests/inputs/planestuff.kcl
Normal file
60
rust/kcl-lib/tests/inputs/planestuff.kcl
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// There are 3 ways to define a plane in KCL, according to https://zoo.dev/docs/kcl-std/types/std-types-Plane
|
||||||
|
// - A default plane
|
||||||
|
// - Modifying a default plane e.g. via offsetPlane
|
||||||
|
// - Defining your own struct
|
||||||
|
// This file tests they all work equivalently.
|
||||||
|
|
||||||
|
// Define a plane using struct representation.
|
||||||
|
myPlane = {
|
||||||
|
origin = { x = 0, y = 0, z = 0 },
|
||||||
|
xAxis = { x = 1, y = 0, z = 0 },
|
||||||
|
yAxis = { x = 0, y = 1, z = 0 },
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prove we can get its axes and origin.
|
||||||
|
ax = myPlane.xAxis
|
||||||
|
assert(ax[0], isEqualTo = 1)
|
||||||
|
assert(ax[1], isEqualTo = 0)
|
||||||
|
assert(ax[2], isEqualTo = 0)
|
||||||
|
ay = myPlane.yAxis
|
||||||
|
assert(ay[0], isEqualTo = 0)
|
||||||
|
assert(ay[1], isEqualTo = 1)
|
||||||
|
assert(ay[2], isEqualTo = 0)
|
||||||
|
aorigin = myPlane.origin
|
||||||
|
assert(aorigin[0], isEqualTo = 0)
|
||||||
|
assert(aorigin[1], isEqualTo = 0)
|
||||||
|
assert(aorigin[2], isEqualTo = 0)
|
||||||
|
|
||||||
|
// Define a plane using standard planes.
|
||||||
|
myOtherPlane = XY
|
||||||
|
|
||||||
|
// Prove we can get its axes and origin.
|
||||||
|
axOther = myOtherPlane.xAxis
|
||||||
|
assert(axOther[0], isEqualTo = 1)
|
||||||
|
assert(axOther[1], isEqualTo = 0)
|
||||||
|
assert(axOther[2], isEqualTo = 0)
|
||||||
|
ayOther = myOtherPlane.yAxis
|
||||||
|
assert(ayOther[0], isEqualTo = 0)
|
||||||
|
assert(ayOther[1], isEqualTo = 1)
|
||||||
|
assert(ayOther[2], isEqualTo = 0)
|
||||||
|
aoriginOther = myOtherPlane.origin
|
||||||
|
assert(aoriginOther[0], isEqualTo = 0)
|
||||||
|
assert(aoriginOther[1], isEqualTo = 0)
|
||||||
|
assert(aoriginOther[2], isEqualTo = 0)
|
||||||
|
|
||||||
|
// Define a plane using a plane-modifying function like offsetPlane.
|
||||||
|
myAlternatePlane = offsetPlane(XY, offset = 0)
|
||||||
|
|
||||||
|
// Prove we can get its axes and origin.
|
||||||
|
axAlternate = myAlternatePlane.xAxis
|
||||||
|
assert(axAlternate[0], isEqualTo = 1)
|
||||||
|
assert(axAlternate[1], isEqualTo = 0)
|
||||||
|
assert(axAlternate[2], isEqualTo = 0)
|
||||||
|
ayAlternate = myAlternatePlane.yAxis
|
||||||
|
assert(ayAlternate[0], isEqualTo = 0)
|
||||||
|
assert(ayAlternate[1], isEqualTo = 1)
|
||||||
|
assert(ayAlternate[2], isEqualTo = 0)
|
||||||
|
aoriginAlternate = myAlternatePlane.origin
|
||||||
|
assert(aoriginAlternate[0], isEqualTo = 0)
|
||||||
|
assert(aoriginAlternate[1], isEqualTo = 0)
|
||||||
|
assert(aoriginAlternate[2], isEqualTo = 0)
|
@ -11,7 +11,6 @@ export const VITE_KC_API_WS_MODELING_URL = env.VITE_KC_API_WS_MODELING_URL as
|
|||||||
export const VITE_KC_API_BASE_URL = env.VITE_KC_API_BASE_URL
|
export const VITE_KC_API_BASE_URL = env.VITE_KC_API_BASE_URL
|
||||||
export const VITE_KC_SITE_BASE_URL = env.VITE_KC_SITE_BASE_URL
|
export const VITE_KC_SITE_BASE_URL = env.VITE_KC_SITE_BASE_URL
|
||||||
export const VITE_KC_SITE_APP_URL = env.VITE_KC_SITE_APP_URL
|
export const VITE_KC_SITE_APP_URL = env.VITE_KC_SITE_APP_URL
|
||||||
export const VITE_KC_SKIP_AUTH = env.VITE_KC_SKIP_AUTH as string | undefined
|
|
||||||
export const VITE_KC_CONNECTION_TIMEOUT_MS =
|
export const VITE_KC_CONNECTION_TIMEOUT_MS =
|
||||||
env.VITE_KC_CONNECTION_TIMEOUT_MS as string | undefined
|
env.VITE_KC_CONNECTION_TIMEOUT_MS as string | undefined
|
||||||
export const VITE_KC_DEV_TOKEN = env.VITE_KC_DEV_TOKEN as string | undefined
|
export const VITE_KC_DEV_TOKEN = env.VITE_KC_DEV_TOKEN as string | undefined
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import type { Models } from '@kittycad/lib'
|
import type { Models } from '@kittycad/lib'
|
||||||
import {
|
import { VITE_KC_API_BASE_URL, VITE_KC_DEV_TOKEN } from '@src/env'
|
||||||
DEV,
|
|
||||||
VITE_KC_API_BASE_URL,
|
|
||||||
VITE_KC_DEV_TOKEN,
|
|
||||||
VITE_KC_SKIP_AUTH,
|
|
||||||
} from '@src/env'
|
|
||||||
import { assign, fromPromise, setup } from 'xstate'
|
import { assign, fromPromise, setup } from 'xstate'
|
||||||
|
|
||||||
import { COOKIE_NAME, OAUTH2_DEVICE_CLIENT_ID } from '@src/lib/constants'
|
import { COOKIE_NAME, OAUTH2_DEVICE_CLIENT_ID } from '@src/lib/constants'
|
||||||
@ -21,26 +16,6 @@ import {
|
|||||||
} from '@src/lib/withBaseURL'
|
} from '@src/lib/withBaseURL'
|
||||||
import { ACTOR_IDS } from '@src/machines/machineConstants'
|
import { ACTOR_IDS } from '@src/machines/machineConstants'
|
||||||
|
|
||||||
const SKIP_AUTH = VITE_KC_SKIP_AUTH === 'true' && DEV
|
|
||||||
|
|
||||||
const LOCAL_USER: Models['User_type'] = {
|
|
||||||
id: '8675309',
|
|
||||||
name: 'Test User',
|
|
||||||
email: 'kittycad.sidebar.test@example.com',
|
|
||||||
image: 'https://placekitten.com/200/200',
|
|
||||||
created_at: 'yesteryear',
|
|
||||||
updated_at: 'today',
|
|
||||||
company: 'Test Company',
|
|
||||||
discord: 'Test User#1234',
|
|
||||||
github: 'testuser',
|
|
||||||
phone: '555-555-5555',
|
|
||||||
first_name: 'Test',
|
|
||||||
last_name: 'User',
|
|
||||||
can_train_on_data: false,
|
|
||||||
is_service_account: false,
|
|
||||||
deletion_scheduled: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UserContext {
|
export interface UserContext {
|
||||||
user?: Models['User_type']
|
user?: Models['User_type']
|
||||||
token: string
|
token: string
|
||||||
@ -165,19 +140,6 @@ async function getUser(input: { token?: string }) {
|
|||||||
if (!token && isDesktop()) return Promise.reject(new Error('No token found'))
|
if (!token && isDesktop()) return Promise.reject(new Error('No token found'))
|
||||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||||
|
|
||||||
if (SKIP_AUTH) {
|
|
||||||
// For local tests
|
|
||||||
if (localStorage.getItem('FORCE_NO_IMAGE')) {
|
|
||||||
LOCAL_USER.image = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
markOnce('code/didAuth')
|
|
||||||
return {
|
|
||||||
user: LOCAL_USER,
|
|
||||||
token,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const userPromise = isDesktop()
|
const userPromise = isDesktop()
|
||||||
? getUserDesktop(token, VITE_KC_API_BASE_URL)
|
? getUserDesktop(token, VITE_KC_API_BASE_URL)
|
||||||
: fetch(url, {
|
: fetch(url, {
|
||||||
|
@ -75,7 +75,6 @@ process.env.VITE_KC_API_WS_MODELING_URL ??= viteEnv.VITE_KC_API_WS_MODELING_URL
|
|||||||
process.env.VITE_KC_API_BASE_URL ??= viteEnv.VITE_KC_API_BASE_URL
|
process.env.VITE_KC_API_BASE_URL ??= viteEnv.VITE_KC_API_BASE_URL
|
||||||
process.env.VITE_KC_SITE_BASE_URL ??= viteEnv.VITE_KC_SITE_BASE_URL
|
process.env.VITE_KC_SITE_BASE_URL ??= viteEnv.VITE_KC_SITE_BASE_URL
|
||||||
process.env.VITE_KC_SITE_APP_URL ??= viteEnv.VITE_KC_SITE_APP_URL
|
process.env.VITE_KC_SITE_APP_URL ??= viteEnv.VITE_KC_SITE_APP_URL
|
||||||
process.env.VITE_KC_SKIP_AUTH ??= viteEnv.VITE_KC_SKIP_AUTH
|
|
||||||
process.env.VITE_KC_CONNECTION_TIMEOUT_MS ??=
|
process.env.VITE_KC_CONNECTION_TIMEOUT_MS ??=
|
||||||
viteEnv.VITE_KC_CONNECTION_TIMEOUT_MS
|
viteEnv.VITE_KC_CONNECTION_TIMEOUT_MS
|
||||||
|
|
||||||
|
@ -292,7 +292,6 @@ contextBridge.exposeInMainWorld('electron', {
|
|||||||
'VITE_KC_API_BASE_URL',
|
'VITE_KC_API_BASE_URL',
|
||||||
'VITE_KC_SITE_BASE_URL',
|
'VITE_KC_SITE_BASE_URL',
|
||||||
'VITE_KC_SITE_APP_URL',
|
'VITE_KC_SITE_APP_URL',
|
||||||
'VITE_KC_SKIP_AUTH',
|
|
||||||
'VITE_KC_CONNECTION_TIMEOUT_MS',
|
'VITE_KC_CONNECTION_TIMEOUT_MS',
|
||||||
'VITE_KC_DEV_TOKEN',
|
'VITE_KC_DEV_TOKEN',
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user