added jspg_schemas for mixer

This commit is contained in:
2026-03-15 23:03:03 -04:00
parent 2f15ae3d41
commit c529c8b8ea
2 changed files with 33 additions and 0 deletions

View File

@ -110,6 +110,23 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
}
}
#[cfg_attr(not(test), pg_extern)]
pub fn jspg_schemas() -> JsonB {
let engine_opt = {
let lock = GLOBAL_JSPG.read().unwrap();
lock.clone()
};
match engine_opt {
Some(engine) => {
let schemas_json = serde_json::to_value(&engine.database.schemas)
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()));
JsonB(schemas_json)
}
None => JsonB(serde_json::Value::Object(serde_json::Map::new())),
}
}
#[cfg_attr(not(test), pg_extern)]
pub fn jspg_stems() -> JsonB {
let engine_opt = {

View File

@ -49,6 +49,22 @@ fn test_library_api() {
})
);
// 3. Validate jspg_schemas
let schemas_drop = jspg_schemas();
assert_eq!(
schemas_drop.0,
json!({
"test_schema": {
"$id": "test_schema",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"]
}
})
);
// 4. Validate Happy Path
let happy_drop = jspg_validate("test_schema", JsonB(json!({"name": "Neo"})));
assert_eq!(