Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a32cb3a4da | |||
| 9cefc225fc | |||
| 4874c09fb5 | |||
| 86d49273bc | |||
| 724a9e3e44 | |||
| 5b2feb5ea7 | |||
| 473b087d97 | |||
| 6d6745d95d |
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>,
|
|
||||||
}
|
|
||||||
|
|||||||
20
src/lib.rs
20
src/lib.rs
@ -44,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: Json) -> 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);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ pub fn jspg_setup(database: Json) -> 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)]
|
||||||
@ -74,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 = {
|
||||||
|
|||||||
@ -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