Compare commits
11 Commits
2a8b991269
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a32cb3a4da | |||
| 9cefc225fc | |||
| 4874c09fb5 | |||
| 86d49273bc | |||
| 724a9e3e44 | |||
| 5b2feb5ea7 | |||
| 473b087d97 | |||
| 6d6745d95d | |||
| 146efaa2d9 | |||
| d0294eec3f | |||
| 02ab4b6438 |
12
src/database/action.rs
Normal file
12
src/database/action.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct Action {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub punc: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub navigate: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub launch: Option<String>,
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
pub mod action;
|
||||||
pub mod compile;
|
pub mod compile;
|
||||||
pub mod edge;
|
pub mod edge;
|
||||||
pub mod r#enum;
|
pub mod r#enum;
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
|
use crate::database::action::Action;
|
||||||
use crate::database::schema::Schema;
|
use crate::database::schema::Schema;
|
||||||
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
@ -219,14 +220,6 @@ pub enum SchemaTypeOrArray {
|
|||||||
Multiple(Vec<String>),
|
Multiple(Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct Action {
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub navigate: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub punc: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum Dependency {
|
pub enum Dependency {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::action::Action;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -22,14 +23,3 @@ pub struct Sidebar {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub priority: Option<i32>,
|
pub priority: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct Action {
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub punc: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub navigate: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub present: Option<String>,
|
|
||||||
}
|
|
||||||
|
|||||||
29
src/lib.rs
29
src/lib.rs
@ -7,6 +7,9 @@ pg_module_magic!();
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub struct JsonB(pub serde_json::Value);
|
pub struct JsonB(pub serde_json::Value);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub struct Json(pub serde_json::Value);
|
||||||
|
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod drop;
|
pub mod drop;
|
||||||
pub mod jspg;
|
pub mod jspg;
|
||||||
@ -41,7 +44,7 @@ fn jspg_failure() -> JsonB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern(strict))]
|
#[cfg_attr(not(test), pg_extern(strict))]
|
||||||
pub fn jspg_setup(database: JsonB) -> JsonB {
|
pub fn jspg_setup(database: Json) -> Json {
|
||||||
let (new_jspg, drop) = crate::jspg::Jspg::new(&database.0);
|
let (new_jspg, drop) = crate::jspg::Jspg::new(&database.0);
|
||||||
let new_arc = Arc::new(new_jspg);
|
let new_arc = Arc::new(new_jspg);
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ pub fn jspg_setup(database: JsonB) -> JsonB {
|
|||||||
*lock = Some(new_arc);
|
*lock = Some(new_arc);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonB(serde_json::to_value(drop).unwrap())
|
Json(serde_json::to_value(drop).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
@ -71,6 +74,22 @@ pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
|
pub fn jspg_merge_ordered(schema_id: &str, data: Json) -> Json {
|
||||||
|
let engine_opt = {
|
||||||
|
let lock = GLOBAL_JSPG.read().unwrap();
|
||||||
|
lock.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
match engine_opt {
|
||||||
|
Some(engine) => {
|
||||||
|
let drop = engine.merger.merge(schema_id, data.0);
|
||||||
|
Json(serde_json::to_value(drop).unwrap())
|
||||||
|
}
|
||||||
|
None => Json(jspg_failure().0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
pub fn jspg_query(schema_id: &str, filter: Option<JsonB>) -> JsonB {
|
pub fn jspg_query(schema_id: &str, filter: Option<JsonB>) -> JsonB {
|
||||||
let engine_opt = {
|
let engine_opt = {
|
||||||
@ -109,7 +128,7 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
pub fn jspg_database() -> JsonB {
|
pub fn jspg_database() -> Json {
|
||||||
let engine_opt = {
|
let engine_opt = {
|
||||||
let lock = GLOBAL_JSPG.read().unwrap();
|
let lock = GLOBAL_JSPG.read().unwrap();
|
||||||
lock.clone()
|
lock.clone()
|
||||||
@ -120,9 +139,9 @@ pub fn jspg_database() -> JsonB {
|
|||||||
let database_json = serde_json::to_value(&engine.database)
|
let database_json = serde_json::to_value(&engine.database)
|
||||||
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()));
|
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()));
|
||||||
let drop = crate::drop::Drop::success_with_val(database_json);
|
let drop = crate::drop::Drop::success_with_val(database_json);
|
||||||
JsonB(serde_json::to_value(drop).unwrap())
|
Json(serde_json::to_value(drop).unwrap())
|
||||||
}
|
}
|
||||||
None => jspg_failure(),
|
None => Json(jspg_failure().0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ fn test_library_api() {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
let cache_drop = jspg_setup(JsonB(db_json));
|
let cache_drop = jspg_setup(Json(db_json));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache_drop.0,
|
cache_drop.0,
|
||||||
json!({
|
json!({
|
||||||
@ -226,7 +226,10 @@ fn test_library_api() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 4. Validate Happy Path
|
// 4. Validate Happy Path
|
||||||
let happy_drop = jspg_validate("source_schema", JsonB(json!({"type": "source_schema", "name": "Neo"})));
|
let happy_drop = jspg_validate(
|
||||||
|
"source_schema",
|
||||||
|
JsonB(json!({"type": "source_schema", "name": "Neo"})),
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
happy_drop.0,
|
happy_drop.0,
|
||||||
json!({
|
json!({
|
||||||
@ -236,7 +239,10 @@ fn test_library_api() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 5. Validate Unhappy Path
|
// 5. Validate Unhappy Path
|
||||||
let unhappy_drop = jspg_validate("source_schema", JsonB(json!({"type": "source_schema", "wrong": "data"})));
|
let unhappy_drop = jspg_validate(
|
||||||
|
"source_schema",
|
||||||
|
JsonB(json!({"type": "source_schema", "wrong": "data"})),
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
unhappy_drop.0,
|
unhappy_drop.0,
|
||||||
json!({
|
json!({
|
||||||
|
|||||||
Reference in New Issue
Block a user