Skip to content

Commit

Permalink
feat(dal): Add support for Float backend type
Browse files Browse the repository at this point in the history
We need this when the JSON Object is a number from API responses
  • Loading branch information
stack72 committed Feb 19, 2025
1 parent e8e3b1c commit 4aae3cc
Show file tree
Hide file tree
Showing 33 changed files with 212 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/web/src/api/sdf/dal/func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const isCustomizableFuncKind = (f: FuncKind) =>
export enum FuncArgumentKind {
Array = "array",
Boolean = "boolean",
Float = "float",
Integer = "integer",
Json = "json",
Object = "object",
Expand All @@ -112,6 +113,7 @@ export enum FuncBackendKind {
Boolean = "Boolean",
Diff = "Diff",
Identity = "Identity",
Float = "Float",
Integer = "Integer",
JsAction = "JsAction",
JsAttribute = "JsAction",
Expand Down
1 change: 1 addition & 0 deletions app/web/src/api/sdf/dal/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type PropId = string;
export enum PropKind {
Array = "array",
Boolean = "boolean",
Float = "float",
Integer = "integer",
Json = "json",
Object = "object",
Expand Down
9 changes: 5 additions & 4 deletions app/web/src/assets/static/editor_typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ declare class PropWidgetDefinitionBuilder implements IPropWidgetDefinitionBuilde
* .setOption("us-east-2 - US East (Ohio)", "us-east-2")
*/
addOption(key: string, value: string): this;

/**
* Set this prop as create only prop. This means that when
* the component has a resource attached, it will be marked
Expand Down Expand Up @@ -394,6 +394,7 @@ declare class SiPropValueFromDefinitionBuilder implements ISiPropValueFromDefini
type PropDefinitionKind =
"array"
| "boolean"
| "float"
| "integer"
| "map"
| "object"
Expand Down Expand Up @@ -581,7 +582,7 @@ declare class PropBuilder implements IPropBuilder {
/**
* The type of the prop
*
* @param {string} kind [array | boolean | integer | map | object | string]
* @param {string} kind [array | boolean | float | integer | map | object | string]
*
* @returns this
*
Expand Down Expand Up @@ -648,7 +649,7 @@ interface ISecretPropBuilder {
setName(name: string): this;

setSecretKind(kind: string): this;

setConnectionAnnotation(annotation: string): this;

setDocLinkRef(ref: string): this;
Expand Down Expand Up @@ -697,7 +698,7 @@ declare class SecretPropBuilder implements ISecretPropBuilder {
* .setSecretKind("DigitalOcean Credential")
*/
setSecretKind(kind: string): this;

setConnectionAnnotation(annotation: string): this;

setDocLinkRef(ref: string): this;
Expand Down
3 changes: 2 additions & 1 deletion bin/lang-js/src/asset_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ export class SiPropValueFromDefinitionBuilder
export type PropDefinitionKind =
| "array"
| "boolean"
| "float"
| "integer"
| "map"
| "object"
Expand Down Expand Up @@ -756,7 +757,7 @@ export class PropBuilder implements IPropBuilder {
/**
* The type of the prop
*
* @param kind {PropDefinitionKind} [array | boolean | integer | map | object | string]
* @param kind {PropDefinitionKind} [array | boolean | float | integer | map | object | string]
*
* @returns this
*
Expand Down
1 change: 1 addition & 0 deletions lib/cyclone-core/src/resolver_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum ResolverFunctionResponseType {
Array,
Boolean,
CodeGeneration,
Float,
Identity,
Integer,
Json,
Expand Down
6 changes: 5 additions & 1 deletion lib/dal/src/attribute/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,11 @@ impl AttributeValue {
) -> AttributeValueResult<Vec<AttributeValueId>> {
let prop = Self::prop(ctx, id).await?;
match prop.kind {
PropKind::Boolean | PropKind::Integer | PropKind::Json | PropKind::String => Ok(vec![]),
PropKind::Boolean
| PropKind::Integer
| PropKind::Float
| PropKind::Json
| PropKind::String => Ok(vec![]),
PropKind::Array | PropKind::Map => {
Self::get_child_av_ids_from_ordering_node(ctx, id).await
}
Expand Down
1 change: 1 addition & 0 deletions lib/dal/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ impl Func {
IntrinsicFunc::SetArray
| IntrinsicFunc::SetBoolean
| IntrinsicFunc::SetInteger
| IntrinsicFunc::SetFloat
| IntrinsicFunc::SetJson
| IntrinsicFunc::SetMap
| IntrinsicFunc::SetObject
Expand Down
7 changes: 7 additions & 0 deletions lib/dal/src/func/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub enum FuncArgumentKind {
Any,
Array,
Boolean,
Float,
Integer,
Json,
Map,
Expand All @@ -96,6 +97,7 @@ impl From<FuncArgumentKind> for si_events::FuncArgumentKind {
FuncArgumentKind::Any => si_events::FuncArgumentKind::Any,
FuncArgumentKind::Array => si_events::FuncArgumentKind::Array,
FuncArgumentKind::Boolean => si_events::FuncArgumentKind::Boolean,
FuncArgumentKind::Float => si_events::FuncArgumentKind::Float,
FuncArgumentKind::Integer => si_events::FuncArgumentKind::Integer,
FuncArgumentKind::Json => si_events::FuncArgumentKind::Json,
FuncArgumentKind::Map => si_events::FuncArgumentKind::Map,
Expand All @@ -112,6 +114,7 @@ impl From<PropKind> for FuncArgumentKind {
PropKind::Array => FuncArgumentKind::Array,
PropKind::Boolean => FuncArgumentKind::Boolean,
PropKind::Integer => FuncArgumentKind::Integer,
PropKind::Float => FuncArgumentKind::Float,
PropKind::Object => FuncArgumentKind::Object,
PropKind::String => FuncArgumentKind::String,
PropKind::Map => FuncArgumentKind::Map,
Expand All @@ -126,6 +129,7 @@ impl From<PkgFuncArgumentKind> for FuncArgumentKind {
PkgFuncArgumentKind::Json => FuncArgumentKind::Json,
PkgFuncArgumentKind::Array => FuncArgumentKind::Array,
PkgFuncArgumentKind::Boolean => FuncArgumentKind::Boolean,
PkgFuncArgumentKind::Float => FuncArgumentKind::Float,
PkgFuncArgumentKind::Integer => FuncArgumentKind::Integer,
PkgFuncArgumentKind::Map => FuncArgumentKind::Map,
PkgFuncArgumentKind::Object => FuncArgumentKind::Object,
Expand All @@ -140,6 +144,7 @@ impl From<FuncArgumentKind> for PkgFuncArgumentKind {
FuncArgumentKind::Any => PkgFuncArgumentKind::Any,
FuncArgumentKind::Array => PkgFuncArgumentKind::Array,
FuncArgumentKind::Boolean => PkgFuncArgumentKind::Boolean,
FuncArgumentKind::Float => PkgFuncArgumentKind::Float,
FuncArgumentKind::Integer => PkgFuncArgumentKind::Integer,
FuncArgumentKind::Map => PkgFuncArgumentKind::Map,
FuncArgumentKind::Object => PkgFuncArgumentKind::Object,
Expand All @@ -155,6 +160,7 @@ impl From<si_frontend_types::FuncArgumentKind> for FuncArgumentKind {
si_frontend_types::FuncArgumentKind::Any => FuncArgumentKind::Any,
si_frontend_types::FuncArgumentKind::Array => FuncArgumentKind::Array,
si_frontend_types::FuncArgumentKind::Boolean => FuncArgumentKind::Boolean,
si_frontend_types::FuncArgumentKind::Float => FuncArgumentKind::Float,
si_frontend_types::FuncArgumentKind::Integer => FuncArgumentKind::Integer,
si_frontend_types::FuncArgumentKind::Json => FuncArgumentKind::Json,
si_frontend_types::FuncArgumentKind::Map => FuncArgumentKind::Map,
Expand All @@ -172,6 +178,7 @@ impl From<FuncArgumentKind> for si_frontend_types::FuncArgumentKind {
FuncArgumentKind::Any => si_frontend_types::FuncArgumentKind::Any,
FuncArgumentKind::Array => si_frontend_types::FuncArgumentKind::Array,
FuncArgumentKind::Boolean => si_frontend_types::FuncArgumentKind::Boolean,
FuncArgumentKind::Float => si_frontend_types::FuncArgumentKind::Float,
FuncArgumentKind::Integer => si_frontend_types::FuncArgumentKind::Integer,
FuncArgumentKind::Json => si_frontend_types::FuncArgumentKind::Json,
FuncArgumentKind::Map => si_frontend_types::FuncArgumentKind::Map,
Expand Down
9 changes: 9 additions & 0 deletions lib/dal/src/func/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{Func, FuncId, PropKind};
pub mod array;
pub mod boolean;
pub mod diff;
pub mod float;
pub mod identity;
pub mod integer;
pub mod js_action;
Expand Down Expand Up @@ -103,6 +104,7 @@ pub enum FuncBackendKind {
Management,
ResourcePayloadToValue,
NormalizeToArray,
Float,
}

impl From<FuncBackendKind> for si_events::FuncBackendKind {
Expand All @@ -113,6 +115,7 @@ impl From<FuncBackendKind> for si_events::FuncBackendKind {
FuncBackendKind::Diff => si_events::FuncBackendKind::Diff,
FuncBackendKind::Identity => si_events::FuncBackendKind::Identity,
FuncBackendKind::Integer => si_events::FuncBackendKind::Integer,
FuncBackendKind::Float => si_events::FuncBackendKind::Float,
FuncBackendKind::JsAction => si_events::FuncBackendKind::JsAction,
FuncBackendKind::JsAttribute => si_events::FuncBackendKind::JsAttribute,
FuncBackendKind::JsAuthentication => si_events::FuncBackendKind::JsAuthentication,
Expand Down Expand Up @@ -142,6 +145,7 @@ impl From<si_events::FuncBackendKind> for FuncBackendKind {
si_events::FuncBackendKind::Array => FuncBackendKind::Array,
si_events::FuncBackendKind::Boolean => FuncBackendKind::Boolean,
si_events::FuncBackendKind::Diff => FuncBackendKind::Diff,
si_events::FuncBackendKind::Float => FuncBackendKind::Float,
si_events::FuncBackendKind::Identity => FuncBackendKind::Identity,
si_events::FuncBackendKind::Integer => FuncBackendKind::Integer,
si_events::FuncBackendKind::JsAction => FuncBackendKind::JsAction,
Expand Down Expand Up @@ -202,6 +206,7 @@ pub enum FuncBackendResponseType {
Validation,
Void,
Management,
Float,
}

impl From<FuncBackendResponseType> for si_events::FuncBackendResponseType {
Expand All @@ -213,6 +218,7 @@ impl From<FuncBackendResponseType> for si_events::FuncBackendResponseType {
FuncBackendResponseType::CodeGeneration => {
si_events::FuncBackendResponseType::CodeGeneration
}
FuncBackendResponseType::Float => si_events::FuncBackendResponseType::Float,
FuncBackendResponseType::Identity => si_events::FuncBackendResponseType::Identity,
FuncBackendResponseType::Integer => si_events::FuncBackendResponseType::Integer,
FuncBackendResponseType::Json => si_events::FuncBackendResponseType::Json,
Expand Down Expand Up @@ -245,6 +251,7 @@ impl From<si_events::FuncBackendResponseType> for FuncBackendResponseType {
si_events::FuncBackendResponseType::CodeGeneration => {
FuncBackendResponseType::CodeGeneration
}
si_events::FuncBackendResponseType::Float => FuncBackendResponseType::Float,
si_events::FuncBackendResponseType::Identity => FuncBackendResponseType::Identity,
si_events::FuncBackendResponseType::Integer => FuncBackendResponseType::Integer,
si_events::FuncBackendResponseType::Json => FuncBackendResponseType::Json,
Expand Down Expand Up @@ -274,6 +281,7 @@ impl From<ResolverFunctionResponseType> for FuncBackendResponseType {
ResolverFunctionResponseType::Action => FuncBackendResponseType::Action,
ResolverFunctionResponseType::Array => FuncBackendResponseType::Array,
ResolverFunctionResponseType::Boolean => FuncBackendResponseType::Boolean,
ResolverFunctionResponseType::Float => FuncBackendResponseType::Float,
ResolverFunctionResponseType::Identity => FuncBackendResponseType::Identity,
ResolverFunctionResponseType::Integer => FuncBackendResponseType::Integer,
ResolverFunctionResponseType::Map => FuncBackendResponseType::Map,
Expand Down Expand Up @@ -301,6 +309,7 @@ impl TryFrom<FuncBackendResponseType> for ResolverFunctionResponseType {
FuncBackendResponseType::Action => ResolverFunctionResponseType::Action,
FuncBackendResponseType::Array => ResolverFunctionResponseType::Array,
FuncBackendResponseType::Boolean => ResolverFunctionResponseType::Boolean,
FuncBackendResponseType::Float => ResolverFunctionResponseType::Float,
FuncBackendResponseType::Integer => ResolverFunctionResponseType::Integer,
FuncBackendResponseType::Identity => ResolverFunctionResponseType::Identity,
FuncBackendResponseType::Map => ResolverFunctionResponseType::Map,
Expand Down
2 changes: 2 additions & 0 deletions lib/dal/src/func/backend/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl FuncBackend for FuncBackendArray {
PropKind::Array
} else if entry.is_i64() {
PropKind::Integer
} else if entry.is_f64() {
PropKind::Float
} else if entry.is_object() {
PropKind::Object
} else if entry.is_boolean() {
Expand Down
36 changes: 36 additions & 0 deletions lib/dal/src/func/backend/float.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

use crate::func::backend::{FuncBackend, FuncBackendResult};

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct FuncBackendFloatArgs {
pub value: f64,
}

impl FuncBackendFloatArgs {
pub fn new(value: f64) -> Self {
Self { value }
}
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct FuncBackendFloat {
args: FuncBackendFloatArgs,
}

#[async_trait]
impl FuncBackend for FuncBackendFloat {
type Args = FuncBackendFloatArgs;

fn new(args: Self::Args) -> Box<Self> {
Box::new(Self { args })
}

async fn inline(
self: Box<Self>,
) -> FuncBackendResult<(Option<serde_json::Value>, Option<serde_json::Value>)> {
let value = serde_json::to_value(self.args.value)?;
Ok((Some(value.clone()), Some(value)))
}
}
1 change: 1 addition & 0 deletions lib/dal/src/func/backend/js_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl FuncDispatch for FuncBackendJsAttribute {
| ResolverFunctionResponseType::Array
| ResolverFunctionResponseType::Boolean
| ResolverFunctionResponseType::Integer
| ResolverFunctionResponseType::Float
| ResolverFunctionResponseType::Identity
| ResolverFunctionResponseType::Map
| ResolverFunctionResponseType::Object
Expand Down
1 change: 1 addition & 0 deletions lib/dal/src/func/binding/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ async fn validate_intrinsic_inputs(
IntrinsicFunc::SetArray
| IntrinsicFunc::SetBoolean
| IntrinsicFunc::SetInteger
| IntrinsicFunc::SetFloat
| IntrinsicFunc::SetJson
| IntrinsicFunc::SetMap
| IntrinsicFunc::SetObject
Expand Down
17 changes: 17 additions & 0 deletions lib/dal/src/func/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum IntrinsicFunc {
ResourcePayloadToValue,
SetArray,
SetBoolean,
SetFloat,
SetInteger,
SetJson,
SetMap,
Expand Down Expand Up @@ -133,6 +134,19 @@ impl IntrinsicFunc {
.map_err(FuncError::IntrinsicSpecCreation)?,
);
}
Self::SetFloat => {
builder
.unique_id("ab9875b8d5987e3f41e9d5a3c2cc00896338d89b084ca570fa22202c8da0ec55");
data_builder.backend_kind(FuncSpecBackendKind::Float);
data_builder.response_type(FuncSpecBackendResponseType::Float);
builder.argument(
FuncArgumentSpec::builder()
.name("value")
.kind(FuncArgumentKind::Float)
.build()
.map_err(FuncError::IntrinsicSpecCreation)?,
);
}
Self::SetMap => {
builder
.unique_id("dea5084fbf6e7fe8328ac725852b96f4b5869b14d0fe9dd63a285fa876772496");
Expand Down Expand Up @@ -225,6 +239,7 @@ impl IntrinsicFunc {
Self::SetArray => "si:setArray",
Self::SetBoolean => "si:setBoolean",
Self::SetInteger => "si:setInteger",
Self::SetFloat => "si:setFloat",
Self::SetMap => "si:setMap",
Self::SetObject => "si:setObject",
Self::SetJson => "si:setJson",
Expand All @@ -242,6 +257,7 @@ impl IntrinsicFunc {
"si:setArray" => Self::SetArray,
"si:setBoolean" => Self::SetBoolean,
"si:setInteger" => Self::SetInteger,
"si:setFloat" => Self::SetFloat,
"si:setMap" => Self::SetMap,
"si:setObject" => Self::SetObject,
"si:setJson" => Self::SetJson,
Expand All @@ -261,6 +277,7 @@ impl From<PropKind> for IntrinsicFunc {
PropKind::Array => IntrinsicFunc::SetArray,
PropKind::Boolean => IntrinsicFunc::SetBoolean,
PropKind::Integer => IntrinsicFunc::SetInteger,
PropKind::Float => IntrinsicFunc::SetFloat,
PropKind::Json => IntrinsicFunc::SetJson,
PropKind::Map => IntrinsicFunc::SetMap,
PropKind::Object => IntrinsicFunc::SetObject,
Expand Down
1 change: 1 addition & 0 deletions lib/dal/src/func/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl FuncKind {
| FuncBackendKind::Boolean
| FuncBackendKind::Diff
| FuncBackendKind::Identity
| FuncBackendKind::Float
| FuncBackendKind::Integer
| FuncBackendKind::Map
| FuncBackendKind::NormalizeToArray
Expand Down
2 changes: 2 additions & 0 deletions lib/dal/src/func/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::{
};
use crate::{HistoryEventError, TransactionsError};

use super::backend::float::FuncBackendFloat;
use super::backend::management::FuncBackendManagement;
use super::backend::normalize_to_array::FuncBackendNormalizeToArray;
use super::backend::resource_payload_to_value::FuncBackendResourcePayloadToValue;
Expand Down Expand Up @@ -1733,6 +1734,7 @@ impl FuncRunnerExecutionTask {
FuncBackendKind::Boolean => FuncBackendBoolean::create_and_execute(&self.args).await,
FuncBackendKind::Identity => FuncBackendIdentity::create_and_execute(&self.args).await,
FuncBackendKind::Diff => FuncBackendDiff::create_and_execute(&self.args).await,
FuncBackendKind::Float => FuncBackendFloat::create_and_execute(&self.args).await,
FuncBackendKind::Integer => FuncBackendInteger::create_and_execute(&self.args).await,
FuncBackendKind::Map => FuncBackendMap::create_and_execute(&self.args).await,
FuncBackendKind::Object => FuncBackendObject::create_and_execute(&self.args).await,
Expand Down
6 changes: 5 additions & 1 deletion lib/dal/src/management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,11 @@ async fn update_component(
let prop = Prop::get_by_id(ctx, prop_id).await?;

match prop.kind {
PropKind::String | PropKind::Boolean | PropKind::Integer | PropKind::Json => {
PropKind::String
| PropKind::Boolean
| PropKind::Integer
| PropKind::Float
| PropKind::Json => {
// todo: type check!
let view = AttributeValue::get_by_id(ctx, path_attribute_value_id)
.await?
Expand Down
Loading

0 comments on commit 4aae3cc

Please sign in to comment.