added traits and include features with docs
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
pub mod action;
|
||||
pub mod compile;
|
||||
pub mod compose;
|
||||
pub mod edge;
|
||||
pub mod r#enum;
|
||||
pub mod executors;
|
||||
@ -41,7 +42,7 @@ pub struct Database {
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new(val: &serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
pub fn new(mut val: serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
let mut db = Self {
|
||||
enums: IndexMap::new(),
|
||||
types: IndexMap::new(),
|
||||
@ -56,101 +57,115 @@ impl Database {
|
||||
|
||||
let mut errors = Vec::new();
|
||||
|
||||
if let Some(arr) = val.get("enums").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Enum>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.enums.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_ENUM_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database enum '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Err(e) = compose::compose(&mut val, &mut errors) {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "COMPOSE_FAILED".to_string(),
|
||||
message: format!("Fatal error during trait composition: {}", e),
|
||||
details: crate::drop::ErrorDetails::default(),
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("types").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Type>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.types.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_TYPE_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database type '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("relations").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Relation>(item.clone()) {
|
||||
Ok(def) => {
|
||||
if db.types.contains_key(&def.source_type)
|
||||
&& db.types.contains_key(&def.destination_type)
|
||||
{
|
||||
db.relations.insert(def.constraint.clone(), def);
|
||||
if let serde_json::Value::Object(mut map) = val {
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("enums") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Enum>(item) {
|
||||
Ok(def) => {
|
||||
db.enums.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_ENUM_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database enum '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let constraint = item
|
||||
.get("constraint")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_RELATION_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database relation '{}': {}", constraint, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(constraint)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("types") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Type>(item) {
|
||||
Ok(def) => {
|
||||
db.types.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_TYPE_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database type '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("puncs").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Punc>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.puncs.insert(def.name.clone(), def);
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("relations") {
|
||||
for item in arr {
|
||||
let constraint = item
|
||||
.get("constraint")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Relation>(item) {
|
||||
Ok(def) => {
|
||||
if db.types.contains_key(&def.source_type)
|
||||
&& db.types.contains_key(&def.destination_type)
|
||||
{
|
||||
db.relations.insert(def.constraint.clone(), def);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_RELATION_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database relation '{}': {}", constraint, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(constraint)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_PUNC_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database punc '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("puncs") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Punc>(item) {
|
||||
Ok(def) => {
|
||||
db.puncs.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_PUNC_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database punc '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user