give access to CEL reference extraction

This commit is contained in:
2025-08-10 08:04:23 +02:00
parent 695ad2e41e
commit 8454550786

View File

@@ -265,6 +265,32 @@ fn evaluate_cel_internal(expression: &str, context: &JsValue) -> Result<Value, S
.map_err(|e| format!("Execution error: {}", e))
}
/// Extract all identifiers referenced in a CEL expression
#[wasm_bindgen]
pub fn extract_cel_references(expression: &str) -> Result<js_sys::Array, JsValue> {
// Compile the CEL expression
let program = Program::compile(expression)
.map_err(|e| JsValue::from_str(&format!("Compilation error: {}", e)))?;
// Get references using the references() method
let references = program.references();
// Convert to JS array
let js_array = js_sys::Array::new();
// Convert each reference to a JsValue and push it to the JS array
for reference in references.variables().iter() {
js_array.push(&JsValue::from_str(reference));
}
// Also add function references if available
for function in references.functions().iter() {
js_array.push(&JsValue::from_str(&format!("function:{}", function)));
}
Ok(js_array)
}
/// Initialize the WASM module (optional, for debugging)
#[wasm_bindgen(start)]
pub fn main() {