feat!: added ability to run functions & more metadata to object instances

This commit is contained in:
selene 2025-12-28 00:40:14 +01:00
parent 26309312e8
commit 7ae145be20
Signed by: sel
SSH key fingerprint: SHA256:33R/4Rx5Lu4o81LyJyXdMrmP5CJ6j7j1Soo0Dn7mKc0
10 changed files with 323 additions and 68 deletions

View file

@ -1,5 +1,7 @@
use std::collections::HashMap;
use serde_json::json;
use crate::ObjectInstance;
use crate::{modules::FunctionItem, types::ObjectInstance};
pub const TEMPLATE: &str = r#"
[input.value]
@ -15,6 +17,19 @@ conditions = []
duplicates = false
"#;
pub const TEMPLATE_LOCAL: &str = r#"
[inputs.main]
required = true
object_type = "meta/text"
count = 1
[outputs.main]
required = true
object_type = "meta/text"
count = 1
"#;
pub fn validate(obj: &ObjectInstance) -> Result<(), String> {
let value = obj.input.get("value")
.ok_or("input.value must exist")?;
@ -25,17 +40,28 @@ pub fn validate(obj: &ObjectInstance) -> Result<(), String> {
Ok(())
}
pub fn local(obj: &ObjectInstance) -> Result<ObjectInstance, String> {
let value = obj.input.get("value")
.ok_or("input.value must exist")?;
pub fn local(
inputs: FunctionItem,
_params: Option<FunctionItem>
)
-> Result<FunctionItem, String>
{
let Some(main) = inputs.get("main")
else { unreachable!() };
let value = value.as_str()
.ok_or("input.value must be a string")?;
let main_obj = &main[0];
let mut new = obj.clone();
new.local = json!({
"length": value.len()
let Some(value) = &main_obj.input.get("value")
else { unreachable!() };
let mut result_obj = ObjectInstance::from_object_type("meta/text", main_obj.input.clone())?;
result_obj.local = json!({
"length": value.to_string().len()
});
Ok(new)
let mut result = HashMap::new();
result.insert(format!("main"), vec![result_obj]);
Ok(result)
}