Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9038607729 | |||
| 9f6c27c3b8 | |||
| 75aac41362 | |||
| dbcef42401 |
@ -719,6 +719,24 @@
|
|||||||
{
|
{
|
||||||
"name": "attachment",
|
"name": "attachment",
|
||||||
"schemas": [
|
"schemas": [
|
||||||
|
{
|
||||||
|
"$id": "type_metadata",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$id": "other_metadata",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"other": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"$id": "attachment",
|
"$id": "attachment",
|
||||||
"$ref": "entity",
|
"$ref": "entity",
|
||||||
@ -729,9 +747,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"metadata": {
|
"type_metadata": {
|
||||||
"type": "object",
|
"$ref": "type_metadata"
|
||||||
"additionalProperties": true
|
},
|
||||||
|
"other_metadata": {
|
||||||
|
"$ref": "other_metadata"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -744,7 +764,8 @@
|
|||||||
"id",
|
"id",
|
||||||
"type",
|
"type",
|
||||||
"flags",
|
"flags",
|
||||||
"metadata",
|
"type_metadata",
|
||||||
|
"other_metadata",
|
||||||
"created_at",
|
"created_at",
|
||||||
"created_by",
|
"created_by",
|
||||||
"modified_at",
|
"modified_at",
|
||||||
@ -756,7 +777,8 @@
|
|||||||
"id",
|
"id",
|
||||||
"type",
|
"type",
|
||||||
"flags",
|
"flags",
|
||||||
"metadata"
|
"type_metadata",
|
||||||
|
"other_metadata"
|
||||||
],
|
],
|
||||||
"entity": [
|
"entity": [
|
||||||
"id",
|
"id",
|
||||||
@ -772,7 +794,8 @@
|
|||||||
"id": "uuid",
|
"id": "uuid",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"flags": "_text",
|
"flags": "_text",
|
||||||
"metadata": "jsonb",
|
"type_metadata": "jsonb",
|
||||||
|
"other_metadata": "jsonb",
|
||||||
"created_at": "timestamptz",
|
"created_at": "timestamptz",
|
||||||
"created_by": "uuid",
|
"created_by": "uuid",
|
||||||
"modified_at": "timestamptz",
|
"modified_at": "timestamptz",
|
||||||
@ -2260,7 +2283,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Insert attachment displaying side-by-side array literal and jsonb formatting translations",
|
"description": "Attachment with text[] and jsonb metadata structures",
|
||||||
"action": "merge",
|
"action": "merge",
|
||||||
"data": {
|
"data": {
|
||||||
"type": "attachment",
|
"type": "attachment",
|
||||||
@ -2268,9 +2291,11 @@
|
|||||||
"urgent",
|
"urgent",
|
||||||
"reviewed"
|
"reviewed"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"other_metadata": {
|
||||||
"size": 1024,
|
"other": "hello"
|
||||||
"source": "upload"
|
},
|
||||||
|
"type_metadata": {
|
||||||
|
"type": "type_metadata"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expect": {
|
"expect": {
|
||||||
@ -2298,14 +2323,16 @@
|
|||||||
"INSERT INTO agreego.\"attachment\" (",
|
"INSERT INTO agreego.\"attachment\" (",
|
||||||
" \"flags\",",
|
" \"flags\",",
|
||||||
" \"id\",",
|
" \"id\",",
|
||||||
" \"metadata\",",
|
" \"other_metadata\",",
|
||||||
" \"type\"",
|
" \"type\",",
|
||||||
|
" \"type_metadata\"",
|
||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{\"urgent\",\"reviewed\"}',",
|
" '{\"urgent\",\"reviewed\"}',",
|
||||||
" '{{uuid:attachment_id}}',",
|
" '{{uuid:attachment_id}}',",
|
||||||
" '{\"size\":1024,\"source\":\"upload\"}',",
|
" '{\"other\":\"hello\"}',",
|
||||||
" 'attachment'",
|
" 'attachment',",
|
||||||
|
" '{\"type\":\"type_metadata\"}'",
|
||||||
")"
|
")"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -2322,8 +2349,9 @@
|
|||||||
" NULL,",
|
" NULL,",
|
||||||
" '{",
|
" '{",
|
||||||
" \"flags\":[\"urgent\",\"reviewed\"],",
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
" \"type\":\"attachment\"",
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
" }',",
|
" }',",
|
||||||
" '{{uuid:attachment_id}}',",
|
" '{{uuid:attachment_id}}',",
|
||||||
" '{{uuid}}',",
|
" '{{uuid}}',",
|
||||||
@ -2339,15 +2367,17 @@
|
|||||||
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
||||||
" \"flags\":[\"urgent\",\"reviewed\"],",
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
" \"id\":\"{{uuid:attachment_id}}\",",
|
" \"id\":\"{{uuid:attachment_id}}\",",
|
||||||
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
|
|
||||||
" \"modified_at\":\"{{timestamp}}\",",
|
" \"modified_at\":\"{{timestamp}}\",",
|
||||||
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
||||||
" \"type\":\"attachment\"",
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
" },",
|
" },",
|
||||||
" \"new\":{",
|
" \"new\":{",
|
||||||
" \"flags\":[\"urgent\",\"reviewed\"],",
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
" \"metadata\":{\"size\":1024,\"source\":\"upload\"},",
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
" \"type\":\"attachment\"",
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
" }",
|
" }",
|
||||||
" }')"
|
" }')"
|
||||||
]
|
]
|
||||||
|
|||||||
102
m1.json
Normal file
102
m1.json
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
{
|
||||||
|
"description": "Attachment with both type_metadata and other_metadata ad-hoc structures",
|
||||||
|
"action": "merge",
|
||||||
|
"data": {
|
||||||
|
"type": "attachment",
|
||||||
|
"flags": [
|
||||||
|
"urgent",
|
||||||
|
"reviewed"
|
||||||
|
],
|
||||||
|
"other_metadata": {
|
||||||
|
"other": "hello"
|
||||||
|
},
|
||||||
|
"type_metadata": {
|
||||||
|
"type": "type_metadata"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expect": {
|
||||||
|
"success": true,
|
||||||
|
"sql": [
|
||||||
|
[
|
||||||
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
|
" \"created_at\",",
|
||||||
|
" \"created_by\",",
|
||||||
|
" \"id\",",
|
||||||
|
" \"modified_at\",",
|
||||||
|
" \"modified_by\",",
|
||||||
|
" \"type\"",
|
||||||
|
")",
|
||||||
|
"VALUES (",
|
||||||
|
" '{{timestamp}}',",
|
||||||
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
|
" '{{uuid:attachment_id}}',",
|
||||||
|
" '{{timestamp}}',",
|
||||||
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
|
" 'attachment'",
|
||||||
|
")"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"INSERT INTO agreego.\"attachment\" (",
|
||||||
|
" \"flags\",",
|
||||||
|
" \"id\",",
|
||||||
|
" \"other_metadata\",",
|
||||||
|
" \"type\",",
|
||||||
|
" \"type_metadata\"",
|
||||||
|
")",
|
||||||
|
"VALUES (",
|
||||||
|
" '{\"urgent\",\"reviewed\"}',",
|
||||||
|
" '{{uuid:attachment_id}}',",
|
||||||
|
" '{\"other\":\"hello\"}',",
|
||||||
|
" 'attachment',",
|
||||||
|
" '{\"type\":\"type_metadata\"}'",
|
||||||
|
")"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"INSERT INTO agreego.change (",
|
||||||
|
" \"old\",",
|
||||||
|
" \"new\",",
|
||||||
|
" entity_id,",
|
||||||
|
" id,",
|
||||||
|
" kind,",
|
||||||
|
" modified_at,",
|
||||||
|
" modified_by",
|
||||||
|
")",
|
||||||
|
"VALUES (",
|
||||||
|
" NULL,",
|
||||||
|
" '{",
|
||||||
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
|
" }',",
|
||||||
|
" '{{uuid:attachment_id}}',",
|
||||||
|
" '{{uuid}}',",
|
||||||
|
" 'create',",
|
||||||
|
" '{{timestamp}}',",
|
||||||
|
" '00000000-0000-0000-0000-000000000000'",
|
||||||
|
")"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"SELECT pg_notify('entity', '{",
|
||||||
|
" \"complete\":{",
|
||||||
|
" \"created_at\":\"{{timestamp}}\",",
|
||||||
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
||||||
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
|
" \"id\":\"{{uuid:attachment_id}}\",",
|
||||||
|
" \"modified_at\":\"{{timestamp}}\",",
|
||||||
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
||||||
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
|
" },",
|
||||||
|
" \"new\":{",
|
||||||
|
" \"flags\":[\"urgent\",\"reviewed\"],",
|
||||||
|
" \"other_metadata\":{\"other\":\"hello\"},",
|
||||||
|
" \"type\":\"attachment\",",
|
||||||
|
" \"type_metadata\":{\"type\":\"type_metadata\"}",
|
||||||
|
" }",
|
||||||
|
" }')"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -176,7 +176,7 @@ impl Merger {
|
|||||||
|
|
||||||
// Attempt to extract relative object type name
|
// Attempt to extract relative object type name
|
||||||
let relative_type_name = match relative.get("type").and_then(|v| v.as_str()) {
|
let relative_type_name = match relative.get("type").and_then(|v| v.as_str()) {
|
||||||
Some(t) => t,
|
Some(t) => t.to_string(),
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ impl Merger {
|
|||||||
// Call central Database O(1) graph logic
|
// Call central Database O(1) graph logic
|
||||||
let relative_relation = self.db.get_relation(
|
let relative_relation = self.db.get_relation(
|
||||||
&type_def.name,
|
&type_def.name,
|
||||||
relative_type_name,
|
&relative_type_name,
|
||||||
&relation_name,
|
&relation_name,
|
||||||
Some(&relative_keys),
|
Some(&relative_keys),
|
||||||
);
|
);
|
||||||
@ -200,11 +200,16 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let merged_relative = match self.merge_internal(Value::Object(relative), notifications)? {
|
let mut merged_relative = match self.merge_internal(Value::Object(relative), notifications)? {
|
||||||
Value::Object(m) => m,
|
Value::Object(m) => m,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
merged_relative.insert(
|
||||||
|
"type".to_string(),
|
||||||
|
Value::String(relative_type_name),
|
||||||
|
);
|
||||||
|
|
||||||
Self::apply_entity_relation(
|
Self::apply_entity_relation(
|
||||||
&mut entity_fields,
|
&mut entity_fields,
|
||||||
&relation.source_columns,
|
&relation.source_columns,
|
||||||
|
|||||||
@ -13,13 +13,18 @@ impl<'a> ValidationContext<'a> {
|
|||||||
) -> Result<bool, ValidationError> {
|
) -> Result<bool, ValidationError> {
|
||||||
let current = self.instance;
|
let current = self.instance;
|
||||||
if let Some(obj) = current.as_object() {
|
if let Some(obj) = current.as_object() {
|
||||||
// Entity Bound Implicit Type Validation
|
// Entity implicit type validation
|
||||||
if let Some(lookup_key) = self.schema.id.as_ref().or(self.schema.r#ref.as_ref()) {
|
// Use the specific schema id or ref as a fallback
|
||||||
let base_type_name = lookup_key.split('.').next_back().unwrap_or("").to_string();
|
if let Some(identifier) = self.schema.id.as_ref().or(self.schema.r#ref.as_ref()) {
|
||||||
if let Some(type_def) = self.db.types.get(&base_type_name)
|
// Kick in if the data object has a type field
|
||||||
&& let Some(type_val) = obj.get("type")
|
if let Some(type_val) = obj.get("type")
|
||||||
&& let Some(type_str) = type_val.as_str()
|
&& let Some(type_str) = type_val.as_str()
|
||||||
{
|
{
|
||||||
|
// Get the string or the final segment as the base
|
||||||
|
let base = identifier.split('.').next_back().unwrap_or("").to_string();
|
||||||
|
// Check if the base is a global type name
|
||||||
|
if let Some(type_def) = self.db.types.get(&base) {
|
||||||
|
// Ensure the instance type is a variation of the global type
|
||||||
if type_def.variations.contains(type_str) {
|
if type_def.variations.contains(type_str) {
|
||||||
// Ensure it passes strict mode
|
// Ensure it passes strict mode
|
||||||
result.evaluated_keys.insert("type".to_string());
|
result.evaluated_keys.insert("type".to_string());
|
||||||
@ -33,8 +38,15 @@ impl<'a> ValidationContext<'a> {
|
|||||||
path: format!("{}/type", self.path),
|
path: format!("{}/type", self.path),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Ad-Hoc schemas natively use strict schema discriminator strings instead of variation inheritance
|
||||||
|
if type_str == identifier {
|
||||||
|
result.evaluated_keys.insert("type".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(min) = self.schema.min_properties
|
if let Some(min) = self.schema.min_properties
|
||||||
&& (obj.len() as f64) < min
|
&& (obj.len() as f64) < min
|
||||||
{
|
{
|
||||||
@ -44,6 +56,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
path: self.path.to_string(),
|
path: self.path.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(max) = self.schema.max_properties
|
if let Some(max) = self.schema.max_properties
|
||||||
&& (obj.len() as f64) > max
|
&& (obj.len() as f64) > max
|
||||||
{
|
{
|
||||||
@ -53,6 +66,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
path: self.path.to_string(),
|
path: self.path.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref req) = self.schema.required {
|
if let Some(ref req) = self.schema.required {
|
||||||
for field in req {
|
for field in req {
|
||||||
if !obj.contains_key(field) {
|
if !obj.contains_key(field) {
|
||||||
@ -114,10 +128,14 @@ impl<'a> ValidationContext<'a> {
|
|||||||
|
|
||||||
// Entity Bound Implicit Type Interception
|
// Entity Bound Implicit Type Interception
|
||||||
if key == "type"
|
if key == "type"
|
||||||
&& let Some(lookup_key) = sub_schema.id.as_ref().or(sub_schema.r#ref.as_ref())
|
&& let Some(schema_bound) = sub_schema.id.as_ref().or(sub_schema.r#ref.as_ref())
|
||||||
{
|
{
|
||||||
let base_type_name = lookup_key.split('.').next_back().unwrap_or("").to_string();
|
let physical_type_name = schema_bound
|
||||||
if let Some(type_def) = self.db.types.get(&base_type_name)
|
.split('.')
|
||||||
|
.next_back()
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
|
if let Some(type_def) = self.db.types.get(&physical_type_name)
|
||||||
&& let Some(instance_type) = child_instance.as_str()
|
&& let Some(instance_type) = child_instance.as_str()
|
||||||
&& type_def.variations.contains(instance_type)
|
&& type_def.variations.contains(instance_type)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user