give access to CEL reference extraction
This commit is contained in:
26
src/lib.rs
26
src/lib.rs
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user