added realm to jspg processing
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
pub mod cache;
|
||||
|
||||
use crate::database::Database;
|
||||
use crate::database::realm::SchemaRealm;
|
||||
use crate::database::r#type::Type;
|
||||
use serde_json::Value;
|
||||
use std::sync::Arc;
|
||||
@ -24,8 +25,8 @@ impl Merger {
|
||||
pub fn merge(&self, schema_id: &str, data: Value) -> crate::drop::Drop {
|
||||
let mut notifications_queue = Vec::new();
|
||||
|
||||
let target_schema = match self.db.schemas.get(schema_id) {
|
||||
Some(s) => Arc::clone(s),
|
||||
let target_schema = match self.db.get_scoped_schema(SchemaRealm::Type, schema_id) {
|
||||
Some(s) => Arc::clone(&s),
|
||||
None => {
|
||||
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: "MERGE_FAILED".to_string(),
|
||||
@ -144,30 +145,49 @@ impl Merger {
|
||||
if let Some(v) = val {
|
||||
if let Some((idx_opt, target_id_opt)) = options.get(v) {
|
||||
if let Some(target_id) = target_id_opt {
|
||||
if let Some(target_schema) = self.db.schemas.get(target_id) {
|
||||
schema = Arc::clone(target_schema);
|
||||
if let Some(target_schema) =
|
||||
self.db.get_scoped_schema(SchemaRealm::Type, target_id)
|
||||
{
|
||||
schema = target_schema.clone();
|
||||
} else {
|
||||
return Err(format!("Polymorphic mapped target '{}' not found in database registry", target_id));
|
||||
return Err(format!(
|
||||
"Polymorphic mapped target '{}' not found in database registry",
|
||||
target_id
|
||||
));
|
||||
}
|
||||
} else if let Some(idx) = idx_opt {
|
||||
if let Some(target_schema) = schema.obj.one_of.as_ref().and_then(|options| options.get(*idx)) {
|
||||
schema = Arc::clone(target_schema);
|
||||
if let Some(target_schema) = schema
|
||||
.obj
|
||||
.one_of
|
||||
.as_ref()
|
||||
.and_then(|options| options.get(*idx))
|
||||
{
|
||||
schema = Arc::clone(target_schema);
|
||||
} else {
|
||||
return Err(format!("Polymorphic index target '{}' not found in local oneOf array", idx));
|
||||
return Err(format!(
|
||||
"Polymorphic index target '{}' not found in local oneOf array",
|
||||
idx
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(format!("Polymorphic mapped target has no path"));
|
||||
}
|
||||
} else {
|
||||
return Err(format!("Polymorphic discriminator {}='{}' matched no compiled options", disc, v));
|
||||
return Err(format!(
|
||||
"Polymorphic discriminator {}='{}' matched no compiled options",
|
||||
disc, v
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(format!("Polymorphic merging failed: missing required discriminator '{}'", disc));
|
||||
return Err(format!(
|
||||
"Polymorphic merging failed: missing required discriminator '{}'",
|
||||
disc
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.merge_object(schema, map, notifications)
|
||||
},
|
||||
}
|
||||
_ => Err("Invalid merge payload: root must be an Object or Array".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user