gjson pathing for stem paths

This commit is contained in:
2026-03-13 23:35:37 -04:00
parent d6deaa0b0f
commit 290464adc1
6 changed files with 2576 additions and 139 deletions

View File

@ -112,7 +112,7 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
#[cfg_attr(not(test), pg_extern)]
pub fn jspg_stems() -> JsonB {
use serde_json::{Map, Value};
use serde_json::Value;
let engine_opt = {
let lock = GLOBAL_JSPG.read().unwrap();
@ -121,9 +121,24 @@ pub fn jspg_stems() -> JsonB {
match engine_opt {
Some(engine) => {
JsonB(serde_json::to_value(&engine.database.stems).unwrap_or(Value::Object(Map::new())))
let mut result_arr = Vec::new();
for (schema_name, stems_map) in &engine.database.stems {
let mut stems_arr = Vec::new();
for (path_key, stem_arc) in stems_map {
stems_arr.push(serde_json::json!({
"path": path_key,
"type": stem_arc.r#type,
"relation": stem_arc.relation
}));
}
result_arr.push(serde_json::json!({
"schema": schema_name,
"stems": stems_arr
}));
}
JsonB(serde_json::to_value(result_arr).unwrap_or(Value::Array(Vec::new())))
}
None => JsonB(Value::Object(Map::new())),
None => JsonB(Value::Array(Vec::new())),
}
}