Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44d36a2997 | |||
| 0091e5c226 | |||
| 2c18163961 | |||
| 0b241c5227 | |||
| 3736c9d8f0 | |||
| ccca9129b2 |
@ -70,6 +70,10 @@
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@ -181,6 +185,17 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"uuid.condition": {
|
||||
"type": "condition",
|
||||
"properties": {
|
||||
"$eq": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,6 +259,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -258,6 +274,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -278,6 +295,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -325,6 +343,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": [
|
||||
"uuid.condition",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"first_name": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
@ -396,6 +420,7 @@
|
||||
"string.condition": {},
|
||||
"integer.condition": {},
|
||||
"date.condition": {},
|
||||
"uuid.condition": {},
|
||||
"search": {},
|
||||
"search.filter": {
|
||||
"type": "filter",
|
||||
|
||||
@ -2432,7 +2432,7 @@
|
||||
" JOIN agreego.entity entity_2 ON entity_2.id = order_1.id",
|
||||
" WHERE",
|
||||
" NOT entity_2.archived",
|
||||
" AND order_1.counterparty_type = 'organization'",
|
||||
" AND order_1.counterparty_type IN ('bot', 'organization', 'person')",
|
||||
"))))"
|
||||
]
|
||||
]
|
||||
|
||||
@ -141,6 +141,8 @@ impl Schema {
|
||||
if let Some(fmt) = &schema.obj.format {
|
||||
if fmt == "date-time" {
|
||||
return Some(vec!["date.condition".to_string()]);
|
||||
} else if fmt == "uuid" {
|
||||
return Some(vec!["uuid.condition".to_string()]);
|
||||
}
|
||||
}
|
||||
Some(vec!["string.condition".to_string()])
|
||||
|
||||
@ -603,7 +603,7 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
if let Some(type_name) = bound_type_name {
|
||||
// Ensure this type actually exists
|
||||
if self.db.types.contains_key(&type_name) {
|
||||
if let Some(type_def) = self.db.types.get(&type_name) {
|
||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||
let mut poly_col = None;
|
||||
let mut table_to_alias = "";
|
||||
@ -621,7 +621,23 @@ impl<'a> Compiler<'a> {
|
||||
.get(table_to_alias)
|
||||
.or_else(|| type_aliases.get(&node.parent_alias))
|
||||
{
|
||||
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||
// DEBUG: See what variations we have for this type
|
||||
#[cfg(not(test))]
|
||||
pgrx::notice!("JSPG_POLY_BOUNDS: type={}, col={}, variations_len={}, variations={:?}", type_name, col, type_def.variations.len(), type_def.variations);
|
||||
|
||||
// Use IN clause with all variations to support inherited types.
|
||||
// e.g., "asset" has variations ["asset", "property", "unit", ...]
|
||||
// so target_type IN ('asset','property','unit') instead of = 'asset'
|
||||
if type_def.variations.len() > 1 {
|
||||
let quoted: Vec<String> = type_def.variations.iter()
|
||||
.map(|v| format!("'{}'", v))
|
||||
.collect();
|
||||
where_clauses.push(format!(
|
||||
"{}.{} IN ({})", alias, col, quoted.join(", ")
|
||||
));
|
||||
} else {
|
||||
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,10 @@ impl Queryer {
|
||||
Err(drop) => return drop,
|
||||
};
|
||||
|
||||
// DEBUG: Emit compiled SQL as a NOTICE for inspection
|
||||
#[cfg(not(test))]
|
||||
pgrx::notice!("JSPG_SQL[{}]: {}", schema_id, sql);
|
||||
|
||||
// 3. Execute via Database Executor
|
||||
self.execute_sql(schema_id, &sql, args)
|
||||
}
|
||||
|
||||
@ -42,62 +42,83 @@ impl Validator {
|
||||
}
|
||||
|
||||
pub fn validate(&self, schema_id: &str, instance: &Value) -> crate::drop::Drop {
|
||||
let schema_opt = self.db.schemas.get(schema_id);
|
||||
|
||||
if let Some(schema) = schema_opt {
|
||||
let ctx = ValidationContext::new(
|
||||
&self.db,
|
||||
&schema,
|
||||
&schema,
|
||||
instance,
|
||||
HashSet::new(),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
match ctx.validate_scoped() {
|
||||
Ok(result) => {
|
||||
if result.is_valid() {
|
||||
crate::drop::Drop::success()
|
||||
} else {
|
||||
let errors: Vec<crate::drop::Error> = result
|
||||
.errors
|
||||
.into_iter()
|
||||
.map(|e| crate::drop::Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
schema: None,
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
crate::drop::Drop::with_errors(errors)
|
||||
let schema_arc = if schema_id.trim().starts_with('{') {
|
||||
match serde_json::from_str::<crate::database::schema::Schema>(schema_id) {
|
||||
Ok(schema) => {
|
||||
let mut errors = Vec::new();
|
||||
schema.compile(&self.db, "inline", "inline".to_string(), &mut errors);
|
||||
if !errors.is_empty() {
|
||||
return crate::drop::Drop::with_errors(errors);
|
||||
}
|
||||
Arc::new(schema)
|
||||
}
|
||||
Err(e) => {
|
||||
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: "SCHEMA_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse inline schema: {}", e),
|
||||
details: crate::drop::ErrorDetails::default(),
|
||||
}]);
|
||||
}
|
||||
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
schema: None,
|
||||
},
|
||||
}]),
|
||||
}
|
||||
} else {
|
||||
crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||
message: format!("Schema {} not found", schema_id),
|
||||
match self.db.schemas.get(schema_id) {
|
||||
Some(schema) => Arc::clone(schema),
|
||||
None => {
|
||||
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||
message: format!("Schema {} not found", schema_id),
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: Some("/".to_string()),
|
||||
cause: None,
|
||||
context: None,
|
||||
schema: None,
|
||||
},
|
||||
}]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let ctx = ValidationContext::new(
|
||||
&self.db,
|
||||
&schema_arc,
|
||||
&schema_arc,
|
||||
instance,
|
||||
HashSet::new(),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
match ctx.validate_scoped() {
|
||||
Ok(result) => {
|
||||
if result.is_valid() {
|
||||
crate::drop::Drop::success()
|
||||
} else {
|
||||
let errors: Vec<crate::drop::Error> = result
|
||||
.errors
|
||||
.into_iter()
|
||||
.map(|e| crate::drop::Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
schema: None,
|
||||
},
|
||||
})
|
||||
.collect();
|
||||
crate::drop::Drop::with_errors(errors)
|
||||
}
|
||||
}
|
||||
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: Some("/".to_string()),
|
||||
path: Some(e.path),
|
||||
cause: None,
|
||||
context: None,
|
||||
schema: None,
|
||||
},
|
||||
}])
|
||||
}]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user