Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9b4f417f6 | |||
| eae39f92d6 | |||
| 2895f06074 | |||
| c1c16bc814 | |||
| 5885552192 | |||
| dc033296d7 | |||
| 03a871bc1a | |||
| 8aa15873b0 | |||
| 0d282cc930 | |||
| 581fc8e0c0 | |||
| 6f0bff8dc7 | |||
| 99c69e27ab |
@ -87,6 +87,34 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"schedule": {
|
||||||
|
"type": [
|
||||||
|
"opening_hours",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"season": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"opening_hours": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"open": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"seasons": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "season"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,6 +290,7 @@
|
|||||||
"uuid_field",
|
"uuid_field",
|
||||||
"tags",
|
"tags",
|
||||||
"ad_hoc",
|
"ad_hoc",
|
||||||
|
"schedule",
|
||||||
"$and",
|
"$and",
|
||||||
"$or"
|
"$or"
|
||||||
],
|
],
|
||||||
@ -277,6 +306,7 @@
|
|||||||
"uuid_field",
|
"uuid_field",
|
||||||
"tags",
|
"tags",
|
||||||
"ad_hoc",
|
"ad_hoc",
|
||||||
|
"schedule",
|
||||||
"$and",
|
"$and",
|
||||||
"$or"
|
"$or"
|
||||||
],
|
],
|
||||||
@ -298,6 +328,7 @@
|
|||||||
"uuid_field",
|
"uuid_field",
|
||||||
"tags",
|
"tags",
|
||||||
"ad_hoc",
|
"ad_hoc",
|
||||||
|
"schedule",
|
||||||
"$and",
|
"$and",
|
||||||
"$or"
|
"$or"
|
||||||
],
|
],
|
||||||
@ -366,6 +397,12 @@
|
|||||||
"string.condition",
|
"string.condition",
|
||||||
"null"
|
"null"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"schedule": {
|
||||||
|
"type": [
|
||||||
|
"opening_hours.filter",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "filter"
|
"type": "filter"
|
||||||
@ -483,7 +520,63 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"opening_hours": {},
|
||||||
|
"season": {},
|
||||||
|
"opening_hours.filter": {
|
||||||
|
"type": "filter",
|
||||||
|
"compiledPropertyNames": [
|
||||||
|
"open",
|
||||||
|
"seasons",
|
||||||
|
"$and",
|
||||||
|
"$or"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"open": {
|
||||||
|
"type": [
|
||||||
|
"string.condition",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"seasons": {
|
||||||
|
"type": [
|
||||||
|
"season.filter",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"$and": {
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"type": "opening_hours.filter",
|
||||||
|
"compiledPropertyNames": [
|
||||||
|
"open",
|
||||||
|
"seasons",
|
||||||
|
"$and",
|
||||||
|
"$or"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"$or": {
|
||||||
|
"type": [
|
||||||
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
|
"items": {
|
||||||
|
"type": "opening_hours.filter",
|
||||||
|
"compiledPropertyNames": [
|
||||||
|
"open",
|
||||||
|
"seasons",
|
||||||
|
"$and",
|
||||||
|
"$or"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"season.filter": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1461,17 +1461,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"organization\" t2 ON ",
|
|
||||||
"JOIN agreego.\"user\" t3 ON ",
|
|
||||||
"JOIN agreego.\"person\" t4 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"first_name\" = 'LookupFirst'",
|
|
||||||
" AND \"last_name\" = 'LookupLast'",
|
|
||||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
|
||||||
" AND \"pronouns\" = 'they/them'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -1614,17 +1604,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"organization\" t2 ON ",
|
|
||||||
"JOIN agreego.\"user\" t3 ON ",
|
|
||||||
"JOIN agreego.\"person\" t4 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"first_name\" = 'LookupFirst'",
|
|
||||||
" AND \"last_name\" = 'LookupLast'",
|
|
||||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
|
||||||
" AND \"pronouns\" = 'they/them'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -2219,12 +2199,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE t1.id = 'abc' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE (\"id\" = 'abc'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"order\" t2 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = 'abc'",
|
|
||||||
" OR (\"id\" = 'abc'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -3499,12 +3474,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE (\"id\" = '{{uuid:data.id}}'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"invoice\" t2 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"id\" = '{{uuid:data.id}}'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
|
|||||||
@ -151,6 +151,7 @@ impl Schema {
|
|||||||
"number" => Some(vec!["number.condition".to_string()]),
|
"number" => Some(vec!["number.condition".to_string()]),
|
||||||
"boolean" => Some(vec!["boolean.condition".to_string()]),
|
"boolean" => Some(vec!["boolean.condition".to_string()]),
|
||||||
"object" => None, // Inline structures are ignored in Composed References
|
"object" => None, // Inline structures are ignored in Composed References
|
||||||
|
"dict" => None, // Dynamic dictionary maps are ignored in Composed References
|
||||||
"array" => {
|
"array" => {
|
||||||
if let Some(items) = &schema.obj.items {
|
if let Some(items) = &schema.obj.items {
|
||||||
return Self::resolve_filter_type(items, db);
|
return Self::resolve_filter_type(items, db);
|
||||||
@ -164,8 +165,20 @@ impl Schema {
|
|||||||
} else if db.enums.contains_key(custom) {
|
} else if db.enums.contains_key(custom) {
|
||||||
Some(vec![format!("{}.condition", custom)])
|
Some(vec![format!("{}.condition", custom)])
|
||||||
} else {
|
} else {
|
||||||
// Assume anything else is a Relational cross-boundary that already has its own .filter dynamically built
|
// A named type gets a reference to its dynamically built .filter — either a
|
||||||
|
// Relational cross-boundary (table-backed) or a named value type, whose filter
|
||||||
|
// is likewise synthesized (see Database::compile_filters). A named type with no
|
||||||
|
// compilable structure gets no filter — omit it rather than dangle a reference.
|
||||||
|
let base = custom.split('.').next_back().unwrap_or(custom);
|
||||||
|
let has_value_filter = db
|
||||||
|
.schemas
|
||||||
|
.get(custom)
|
||||||
|
.map_or(false, |s| Database::is_value_filter_candidate(custom, s));
|
||||||
|
if db.types.contains_key(base) || has_value_filter {
|
||||||
Some(vec![format!("{}.filter", custom)])
|
Some(vec![format!("{}.filter", custom)])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,6 +125,7 @@ impl Schema {
|
|||||||
child.compile(db, root_id, format!("{}/{}", path, k), errors);
|
child.compile(db, root_id, format!("{}/{}", path, k), errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(items) = &self.obj.items {
|
if let Some(items) = &self.obj.items {
|
||||||
items.compile(db, root_id, format!("{}/items", path), errors);
|
items.compile(db, root_id, format!("{}/items", path), errors);
|
||||||
}
|
}
|
||||||
@ -138,6 +139,7 @@ impl Schema {
|
|||||||
if let Some(child) = &self.obj.not {
|
if let Some(child) = &self.obj.not {
|
||||||
child.compile(db, root_id, format!("{}/not", path), errors);
|
child.compile(db, root_id, format!("{}/not", path), errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(child) = &self.obj.contains {
|
if let Some(child) = &self.obj.contains {
|
||||||
child.compile(db, root_id, format!("{}/contains", path), errors);
|
child.compile(db, root_id, format!("{}/contains", path), errors);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,15 +262,23 @@ impl Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Synthesizes Composed Filter References for all table-backed boundaries.
|
/// Synthesizes Composed Filter References for all table-backed boundaries — and for
|
||||||
|
/// named non-table value types (schema-only objects, e.g. an operating-hours config),
|
||||||
|
/// so a property reference resolves to ONE named filter instead of inlining anonymous
|
||||||
|
/// per-path copies (which duplicate identical leaf type names for downstream codegen).
|
||||||
fn compile_filters(&mut self, errors: &mut Vec<crate::drop::Error>) -> Vec<(String, String)> {
|
fn compile_filters(&mut self, errors: &mut Vec<crate::drop::Error>) -> Vec<(String, String)> {
|
||||||
let mut filter_schemas = Vec::new();
|
let mut filter_schemas = Vec::new();
|
||||||
|
let mut seen_value_ids = std::collections::HashSet::new();
|
||||||
for (type_name, type_def) in &self.types {
|
for (type_name, type_def) in &self.types {
|
||||||
for (id, schema_arc) in &type_def.schemas {
|
for (id, schema_arc) in &type_def.schemas {
|
||||||
// Only run synthesis on actual structured, table-backed boundaries. Exclude subschemas!
|
// Run synthesis on structured table-backed boundaries and named value types.
|
||||||
|
// Exclude subschemas!
|
||||||
let base_name = id.split('.').last().unwrap_or(id);
|
let base_name = id.split('.').last().unwrap_or(id);
|
||||||
let is_table_backed = base_name == type_def.name;
|
let is_table_backed = base_name == type_def.name;
|
||||||
if is_table_backed && !id.contains('/') {
|
let is_value_type = !is_table_backed
|
||||||
|
&& Self::is_value_filter_candidate(id, schema_arc)
|
||||||
|
&& seen_value_ids.insert(id.clone());
|
||||||
|
if (is_table_backed || is_value_type) && !id.contains('/') {
|
||||||
if let Some(filter_schema) = schema_arc.compile_filter(self, id, errors) {
|
if let Some(filter_schema) = schema_arc.compile_filter(self, id, errors) {
|
||||||
filter_schemas.push((
|
filter_schemas.push((
|
||||||
type_name.clone(),
|
type_name.clone(),
|
||||||
@ -293,6 +301,20 @@ impl Database {
|
|||||||
filter_ids
|
filter_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A named non-table value type that earns its own synthesized filter: a bare-named
|
||||||
|
/// (dotless) schema-only object with compiled properties. The base `filter`/`condition`
|
||||||
|
/// schemas are infrastructure, not value types.
|
||||||
|
pub fn is_value_filter_candidate(id: &str, schema: &Arc<Schema>) -> bool {
|
||||||
|
!id.contains('.')
|
||||||
|
&& id != "filter"
|
||||||
|
&& id != "condition"
|
||||||
|
&& schema
|
||||||
|
.obj
|
||||||
|
.compiled_properties
|
||||||
|
.get()
|
||||||
|
.map_or(false, |props| !props.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
/// Synthesizes strong Enum Conditions mirroring the string.condition capabilities.
|
/// Synthesizes strong Enum Conditions mirroring the string.condition capabilities.
|
||||||
fn compile_conditions(&mut self) -> Vec<(String, String)> {
|
fn compile_conditions(&mut self) -> Vec<(String, String)> {
|
||||||
let mut enum_conditions = Vec::new();
|
let mut enum_conditions = Vec::new();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::database::action::Action;
|
use crate::database::action::Action;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -13,6 +14,11 @@ pub struct Page {
|
|||||||
pub sidebar: Option<Sidebar>,
|
pub sidebar: Option<Sidebar>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub actions: Option<IndexMap<String, Action>>,
|
pub actions: Option<IndexMap<String, Action>>,
|
||||||
|
/// The personal-scope filter template ("one surface, two scopes"): the
|
||||||
|
/// "mine" predicate the page merges into its filter when the app is in
|
||||||
|
/// personal scope, e.g. {"reserved_by": "$me"}. Opaque to the engine.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub personal: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
@ -22,4 +28,6 @@ pub struct Sidebar {
|
|||||||
pub category: Option<String>,
|
pub category: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub priority: Option<i32>,
|
pub priority: Option<i32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub icon: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -744,9 +744,19 @@ impl Merger {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let where_clause = format!("WHERE {}", where_parts.join(" OR "));
|
// An OR across the hierarchy join is un-indexable — it forces a full scan
|
||||||
|
// of the subtype table on every child merge. UNION lets each arm use its
|
||||||
let final_sql = format!("{} {}", fetch_sql_template, where_clause);
|
// own index (pk for the id arm, the lk_ unique index for the lookup arm)
|
||||||
|
// and still dedups, so TOO_MANY_LOOKUP_ROWS semantics are preserved.
|
||||||
|
let final_sql = if where_parts.len() == 1 {
|
||||||
|
format!("{} WHERE {}", fetch_sql_template, where_parts[0])
|
||||||
|
} else {
|
||||||
|
where_parts
|
||||||
|
.iter()
|
||||||
|
.map(|p| format!("{} WHERE {}", fetch_sql_template, p))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" UNION ")
|
||||||
|
};
|
||||||
|
|
||||||
let fetched = match self.db.query(&final_sql, None) {
|
let fetched = match self.db.query(&final_sql, None) {
|
||||||
Ok(Value::Array(table)) => {
|
Ok(Value::Array(table)) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user