Compare commits
13 Commits
1.0.149
...
7e28eb2645
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e28eb2645 | |||
| 5133283795 | |||
| d41209e7c1 | |||
| 03c60f5156 | |||
| 1dfd53e53c | |||
| 532bd8da43 | |||
| 271828ebe9 | |||
| 8c430d42e3 | |||
| 4cc5245336 | |||
| c71e99527d | |||
| 843891f67e | |||
| 8bb7085f76 | |||
| ea03584bbd |
@ -295,6 +295,7 @@ The Queryer transforms Postgres into a pre-compiled Semantic Query Engine, desig
|
||||
* **The Dot Convention**: When a schema requests `family: "target.schema"`, the compiler extracts the base type (e.g. `schema`) and looks up its Physical Table definition.
|
||||
* **Multi-Table Branching**: If the Physical Table is a parent to other tables (e.g. `organization` has variations `["organization", "bot", "person"]`), the compiler generates a dynamic `CASE WHEN type = '...' THEN ...` query, expanding into sub-queries for each variation. To ensure safe resolution, the compiler dynamically evaluates correlation boundaries: it attempts standard Relational Edge discovery first. If no explicit relational edge exists (indicating pure Table Inheritance rather than a standard foreign-key graph relationship), it safely invokes a **Table Parity Fallback**. This generates an explicit ID correlation constraint (`AND inner.id = outer.id`), perfectly binding the structural variations back to the parent row to eliminate Cartesian products.
|
||||
* **Single-Table Bypass**: If the Physical Table is a leaf node with only one variation (e.g. `person` has variations `["person"]`), the compiler cleanly bypasses `CASE` generation and compiles a simple `SELECT` across the base table, as all schema extensions (e.g. `light.person`, `full.person`) are guaranteed to reside in the exact same physical row.
|
||||
* **Polymorphic Relation Type Filtering**: When a relationship maps to a polymorphic target with variations, the Queryer compiles an `IN` clause containing all allowed table variations (e.g., `counterparty_type IN ('bot', 'organization', 'person')`) rather than matching the base type literal, ensuring all polymorphic types are loaded correctly.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -37,6 +37,14 @@
|
||||
},
|
||||
"filter": {
|
||||
"type": "$kind.filter"
|
||||
},
|
||||
"conditions": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"new": { "type": "$kind.filter" },
|
||||
"old": { "type": "$kind.filter" },
|
||||
"complete": { "type": "$kind.filter" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,7 +157,48 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Valid nested filter payload",
|
||||
"data": {
|
||||
"kind": "person",
|
||||
"conditions": {
|
||||
"new": {
|
||||
"age": 30
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema_id": "search",
|
||||
"action": "validate",
|
||||
"expect": {
|
||||
"success": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Invalid nested filter payload (fails constraint)",
|
||||
"data": {
|
||||
"kind": "person",
|
||||
"conditions": {
|
||||
"new": {
|
||||
"age": "thirty"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema_id": "search",
|
||||
"action": "validate",
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_TYPE",
|
||||
"details": {
|
||||
"path": "conditions/new/age"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@ -1242,7 +1242,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -1255,7 +1256,8 @@
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1274,7 +1276,8 @@
|
||||
" \"first_name\": \"IncompleteFirst\",",
|
||||
" \"last_name\": \"IncompleteLast\",",
|
||||
" \"type\": \"person\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1339,7 +1342,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
@ -1353,7 +1357,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1373,6 +1378,7 @@
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"kind\": \"update\",",
|
||||
" \"old\": {",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }",
|
||||
@ -1442,7 +1448,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
@ -1456,7 +1463,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1476,6 +1484,7 @@
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"kind\": \"update\",",
|
||||
" \"old\": {",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" },",
|
||||
@ -1540,6 +1549,7 @@
|
||||
" \"new\": {",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"kind\": \"replace\",",
|
||||
" \"replaces\": \"{{uuid:data.id}}\"",
|
||||
"}'))"
|
||||
]
|
||||
@ -1598,7 +1608,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
@ -1614,7 +1625,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1632,6 +1644,7 @@
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"kind\": \"update\",",
|
||||
" \"old\": {",
|
||||
" \"first_name\": \"OldFirst\",",
|
||||
" \"last_name\": \"OldLast\"",
|
||||
@ -1729,7 +1742,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -1744,7 +1758,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1767,7 +1782,8 @@
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"\",",
|
||||
" \"type\": \"person\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1854,7 +1870,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -1869,7 +1886,8 @@
|
||||
" '{{uuid:generated_2}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1912,7 +1930,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -1925,7 +1944,8 @@
|
||||
" '{{uuid:generated_4}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -1944,7 +1964,8 @@
|
||||
" \"total\": 100.0,",
|
||||
" \"type\": \"order\",",
|
||||
" \"customer_id\": \"{{uuid:generated_0}}\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -1967,7 +1988,8 @@
|
||||
" \"date_of_birth\": \"2000-01-01\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"organization_id\": \"{{uuid:generated_1}}\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -2072,7 +2094,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2086,7 +2109,8 @@
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2097,7 +2121,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2109,7 +2134,8 @@
|
||||
" '{{uuid:generated_2}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2126,7 +2152,8 @@
|
||||
" \"new\": {",
|
||||
" \"total\": 99.0,",
|
||||
" \"type\": \"order\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2147,7 +2174,8 @@
|
||||
" \"price\": 99.0,",
|
||||
" \"order_id\": \"abc\",",
|
||||
" \"type\": \"order_line\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -2279,7 +2307,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2291,7 +2320,8 @@
|
||||
" '{{uuid:generated_2}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'phone_number'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2342,7 +2372,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2358,7 +2389,8 @@
|
||||
" '{{uuid:generated_4}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2395,7 +2427,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2407,7 +2440,8 @@
|
||||
" '{{uuid:generated_6}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2458,7 +2492,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2474,7 +2509,8 @@
|
||||
" '{{uuid:generated_8}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2511,7 +2547,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2523,7 +2560,8 @@
|
||||
" '{{uuid:generated_10}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2574,7 +2612,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2590,7 +2629,8 @@
|
||||
" '{{uuid:generated_12}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2601,7 +2641,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2614,7 +2655,8 @@
|
||||
" '{{uuid:generated_13}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2633,7 +2675,8 @@
|
||||
" \"first_name\": \"Relation\",",
|
||||
" \"last_name\": \"Test\",",
|
||||
" \"type\": \"person\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2658,7 +2701,8 @@
|
||||
" \"target_id\": \"{{uuid:generated_1}}\",",
|
||||
" \"target_type\": \"phone_number\",",
|
||||
" \"type\": \"contact\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2675,7 +2719,8 @@
|
||||
" \"new\": {",
|
||||
" \"number\": \"555-0001\",",
|
||||
" \"type\": \"phone_number\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2700,7 +2745,8 @@
|
||||
" \"target_id\": \"{{uuid:generated_5}}\",",
|
||||
" \"target_type\": \"email_address\",",
|
||||
" \"type\": \"contact\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2717,7 +2763,8 @@
|
||||
" \"new\": {",
|
||||
" \"address\": \"test@example.com\",",
|
||||
" \"type\": \"email_address\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2742,7 +2789,8 @@
|
||||
" \"target_id\": \"{{uuid:generated_9}}\",",
|
||||
" \"target_type\": \"email_address\",",
|
||||
" \"type\": \"contact\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -2759,7 +2807,8 @@
|
||||
" \"new\": {",
|
||||
" \"address\": \"test2@example.com\",",
|
||||
" \"type\": \"email_address\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -2811,7 +2860,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
@ -2825,7 +2875,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'delete',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2843,6 +2894,7 @@
|
||||
" \"archived\": true,",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"kind\": \"delete\",",
|
||||
" \"old\": {",
|
||||
" \"archived\": false",
|
||||
" }",
|
||||
@ -2917,7 +2969,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -2938,7 +2991,8 @@
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'attachment'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -2973,7 +3027,8 @@
|
||||
" \"type\": \"type_metadata\"",
|
||||
" },",
|
||||
" \"type\": \"attachment\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -3039,7 +3094,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3053,7 +3109,8 @@
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3074,7 +3131,8 @@
|
||||
" \"price\": 99.0,",
|
||||
" \"order_id\": \"abc\",",
|
||||
" \"type\": \"order_line\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -3148,7 +3206,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3162,7 +3221,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3183,7 +3243,8 @@
|
||||
" \"price\": 99.0,",
|
||||
" \"order_id\": \"abc\",",
|
||||
" \"type\": \"order_line\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -3288,7 +3349,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3320,7 +3382,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'invoice'",
|
||||
")"
|
||||
]
|
||||
]
|
||||
@ -3386,7 +3449,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3399,7 +3463,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'account'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3418,7 +3483,8 @@
|
||||
" \"kind\": \"checking\",",
|
||||
" \"routing_number\": \"123456789\",",
|
||||
" \"type\": \"account\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -3511,7 +3577,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3525,7 +3592,8 @@
|
||||
" '{{uuid:generated_2}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3600,7 +3668,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3613,7 +3682,8 @@
|
||||
" '{{uuid:generated_5}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3656,7 +3726,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3669,7 +3740,8 @@
|
||||
" '{{uuid:generated_7}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3680,7 +3752,8 @@
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
" \"modified_by\",",
|
||||
" \"entity_type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
@ -3693,7 +3766,8 @@
|
||||
" '{{uuid:generated_8}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
@ -3712,7 +3786,8 @@
|
||||
" \"organization_id\": \"parent-org-id\",",
|
||||
" \"type\": \"order\",",
|
||||
" \"customer_id\": \"{{uuid:generated_0}}\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -3733,7 +3808,8 @@
|
||||
" \"last_name\": \"Person\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"organization_id\": \"{{uuid:generated_1}}\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -3752,7 +3828,8 @@
|
||||
" \"order_id\": \"{{uuid:generated_3}}\",",
|
||||
" \"type\": \"order_line\",",
|
||||
" \"organization_id\": \"parent-org-id\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
],
|
||||
[
|
||||
@ -3771,7 +3848,8 @@
|
||||
" \"organization_id\": \"explicit-org-id\",",
|
||||
" \"order_id\": \"{{uuid:generated_3}}\",",
|
||||
" \"type\": \"order_line\"",
|
||||
" }",
|
||||
" },",
|
||||
" \"kind\": \"create\"",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
|
||||
@ -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')",
|
||||
"))))"
|
||||
]
|
||||
]
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use serde_json::Value;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub fn compose(val: &mut Value, errors: &mut Vec<crate::drop::Error>) -> Result<(), String> {
|
||||
let _ = std::fs::write("/Users/awgneo/Repositories/thoughtpatterns/cellular/jspg/traits_debug_val.json", serde_json::to_string_pretty(val).unwrap());
|
||||
let mut traits = HashMap::new();
|
||||
let mut schemas = HashMap::new();
|
||||
|
||||
@ -74,7 +73,9 @@ fn resolve_in_place(
|
||||
return;
|
||||
}
|
||||
|
||||
let include_opt = current.as_object_mut().and_then(|obj| obj.remove("include"));
|
||||
let include_opt = current
|
||||
.as_object_mut()
|
||||
.and_then(|obj| obj.remove("include"));
|
||||
if let Some(include_val) = include_opt {
|
||||
if let Some(include_arr) = include_val.as_array() {
|
||||
let mut merged_props = serde_json::Map::new();
|
||||
@ -145,7 +146,10 @@ fn resolve_in_place(
|
||||
visited.remove(inc_name);
|
||||
|
||||
// Merge properties (host overrides trait)
|
||||
if let Some(target_props) = resolved_target.get("properties").and_then(|v| v.as_object()) {
|
||||
if let Some(target_props) = resolved_target
|
||||
.get("properties")
|
||||
.and_then(|v| v.as_object())
|
||||
{
|
||||
for (k, v) in target_props {
|
||||
if !merged_props.contains_key(k) {
|
||||
merged_props.insert(k.clone(), v.clone());
|
||||
@ -154,7 +158,10 @@ fn resolve_in_place(
|
||||
}
|
||||
|
||||
// Merge patternProperties (host overrides trait)
|
||||
if let Some(target_pat_props) = resolved_target.get("patternProperties").and_then(|v| v.as_object()) {
|
||||
if let Some(target_pat_props) = resolved_target
|
||||
.get("patternProperties")
|
||||
.and_then(|v| v.as_object())
|
||||
{
|
||||
for (k, v) in target_pat_props {
|
||||
if !merged_pattern_props.contains_key(k) {
|
||||
merged_pattern_props.insert(k.clone(), v.clone());
|
||||
@ -181,11 +188,19 @@ fn resolve_in_place(
|
||||
}
|
||||
|
||||
// Merge dependencies
|
||||
if let Some(target_deps) = resolved_target.get("dependencies").and_then(|v| v.as_object()) {
|
||||
if let Some(target_deps) = resolved_target
|
||||
.get("dependencies")
|
||||
.and_then(|v| v.as_object())
|
||||
{
|
||||
for (dep_prop, dep_val) in target_deps {
|
||||
if let Some(existing_val) = merged_dependencies.get_mut(dep_prop) {
|
||||
if let (Some(arr_existing), Some(arr_target)) = (existing_val.as_array_mut(), dep_val.as_array()) {
|
||||
let mut set: HashSet<String> = arr_existing.iter().filter_map(|x| x.as_str().map(String::from)).collect();
|
||||
if let (Some(arr_existing), Some(arr_target)) =
|
||||
(existing_val.as_array_mut(), dep_val.as_array())
|
||||
{
|
||||
let mut set: HashSet<String> = arr_existing
|
||||
.iter()
|
||||
.filter_map(|x| x.as_str().map(String::from))
|
||||
.collect();
|
||||
for x in arr_target {
|
||||
if let Some(s) = x.as_str() {
|
||||
if set.insert(s.to_string()) {
|
||||
@ -203,7 +218,13 @@ fn resolve_in_place(
|
||||
// Inherit other non-merged schemas/scalars if not defined in host (type, items, cases, family, format, etc.)
|
||||
if let Some(obj) = current.as_object_mut() {
|
||||
for (k, v) in resolved_target.as_object().unwrap() {
|
||||
if k != "properties" && k != "patternProperties" && k != "required" && k != "display" && k != "dependencies" && k != "include" {
|
||||
if k != "properties"
|
||||
&& k != "patternProperties"
|
||||
&& k != "required"
|
||||
&& k != "display"
|
||||
&& k != "dependencies"
|
||||
&& k != "include"
|
||||
{
|
||||
if !obj.contains_key(k) {
|
||||
obj.insert(k.clone(), v.clone());
|
||||
}
|
||||
@ -229,7 +250,10 @@ fn resolve_in_place(
|
||||
obj.insert("properties".to_string(), Value::Object(merged_props));
|
||||
}
|
||||
if !merged_pattern_props.is_empty() {
|
||||
obj.insert("patternProperties".to_string(), Value::Object(merged_pattern_props));
|
||||
obj.insert(
|
||||
"patternProperties".to_string(),
|
||||
Value::Object(merged_pattern_props),
|
||||
);
|
||||
}
|
||||
if !merged_required.is_empty() {
|
||||
let mut req_vec: Vec<Value> = merged_required.into_iter().map(Value::String).collect();
|
||||
@ -242,7 +266,10 @@ fn resolve_in_place(
|
||||
obj.insert("display".to_string(), Value::Array(disp_vec));
|
||||
}
|
||||
if !merged_dependencies.is_empty() {
|
||||
obj.insert("dependencies".to_string(), Value::Object(merged_dependencies));
|
||||
obj.insert(
|
||||
"dependencies".to_string(),
|
||||
Value::Object(merged_dependencies),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,47 +279,138 @@ fn resolve_in_place(
|
||||
if let Some(obj) = current.as_object_mut() {
|
||||
if let Some(props) = obj.get_mut("properties").and_then(|v| v.as_object_mut()) {
|
||||
for (k, v) in props {
|
||||
resolve_in_place(v, traits, schemas, errors, schema_id, &format!("{}/{}", path, k), visited);
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/{}", path, k),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(pat_props) = obj.get_mut("patternProperties").and_then(|v| v.as_object_mut()) {
|
||||
if let Some(pat_props) = obj
|
||||
.get_mut("patternProperties")
|
||||
.and_then(|v| v.as_object_mut())
|
||||
{
|
||||
for (k, v) in pat_props {
|
||||
resolve_in_place(v, traits, schemas, errors, schema_id, &format!("{}/{}", path, k), visited);
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/{}", path, k),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(items) = obj.get_mut("items") {
|
||||
resolve_in_place(items, traits, schemas, errors, schema_id, &format!("{}/items", path), visited);
|
||||
resolve_in_place(
|
||||
items,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/items", path),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(prefix_items) = obj.get_mut("prefixItems").and_then(|v| v.as_array_mut()) {
|
||||
for (i, v) in prefix_items.iter_mut().enumerate() {
|
||||
resolve_in_place(v, traits, schemas, errors, schema_id, &format!("{}/prefixItems/{}", path, i), visited);
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/prefixItems/{}", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(additional_props) = obj.get_mut("additionalProperties") {
|
||||
resolve_in_place(additional_props, traits, schemas, errors, schema_id, &format!("{}/additionalProperties", path), visited);
|
||||
resolve_in_place(
|
||||
additional_props,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/additionalProperties", path),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(one_of) = obj.get_mut("oneOf").and_then(|v| v.as_array_mut()) {
|
||||
for (i, v) in one_of.iter_mut().enumerate() {
|
||||
resolve_in_place(v, traits, schemas, errors, schema_id, &format!("{}/oneOf/{}", path, i), visited);
|
||||
resolve_in_place(
|
||||
v,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/oneOf/{}", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(contains) = obj.get_mut("contains") {
|
||||
resolve_in_place(contains, traits, schemas, errors, schema_id, &format!("{}/contains", path), visited);
|
||||
resolve_in_place(
|
||||
contains,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/contains", path),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(not) = obj.get_mut("not") {
|
||||
resolve_in_place(not, traits, schemas, errors, schema_id, &format!("{}/not", path), visited);
|
||||
resolve_in_place(
|
||||
not,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/not", path),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(cases) = obj.get_mut("cases").and_then(|v| v.as_array_mut()) {
|
||||
for (i, c_val) in cases.iter_mut().enumerate() {
|
||||
if let Some(c_obj) = c_val.as_object_mut() {
|
||||
if let Some(when) = c_obj.get_mut("when") {
|
||||
resolve_in_place(when, traits, schemas, errors, schema_id, &format!("{}/cases/{}/when", path, i), visited);
|
||||
resolve_in_place(
|
||||
when,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/cases/{}/when", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(then) = c_obj.get_mut("then") {
|
||||
resolve_in_place(then, traits, schemas, errors, schema_id, &format!("{}/cases/{}/then", path, i), visited);
|
||||
resolve_in_place(
|
||||
then,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/cases/{}/then", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
if let Some(else_) = c_obj.get_mut("else") {
|
||||
resolve_in_place(else_, traits, schemas, errors, schema_id, &format!("{}/cases/{}/else", path, i), visited);
|
||||
resolve_in_place(
|
||||
else_,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/cases/{}/else", path, i),
|
||||
visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +85,7 @@ impl DatabaseExecutor for MockExecutor {
|
||||
Ok("2026-03-10T00:00:00Z".to_string())
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
fn get_queries(&self) -> Vec<String> {
|
||||
MOCK_STATE.with(|state| state.borrow().captured_queries.clone())
|
||||
|
||||
@ -20,6 +20,7 @@ pub trait DatabaseExecutor: Send + Sync {
|
||||
/// Returns the current transaction timestamp
|
||||
fn timestamp(&self) -> Result<String, String>;
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
fn get_queries(&self) -> Vec<String>;
|
||||
|
||||
|
||||
@ -150,4 +150,5 @@ impl DatabaseExecutor for SpiExecutor {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -206,6 +206,7 @@ impl Database {
|
||||
self.executor.timestamp()
|
||||
}
|
||||
|
||||
|
||||
pub fn compile(&mut self, errors: &mut Vec<crate::drop::Error>) {
|
||||
// Phase 1: Registration
|
||||
self.collect_schemas(errors);
|
||||
|
||||
@ -946,9 +946,12 @@ impl Merger {
|
||||
Value::Object(old_vals)
|
||||
};
|
||||
|
||||
let entity_type_name = type_name.as_str().unwrap_or(&type_obj.name);
|
||||
|
||||
let mut notification = serde_json::Map::new();
|
||||
notification.insert("complete".to_string(), Value::Object(complete));
|
||||
notification.insert("new".to_string(), new_val_obj.clone());
|
||||
notification.insert("kind".to_string(), Value::String(change_kind.to_string()));
|
||||
|
||||
if old_val_obj != Value::Null {
|
||||
notification.insert("old".to_string(), old_val_obj.clone());
|
||||
@ -961,14 +964,15 @@ impl Merger {
|
||||
let mut notify_sql = None;
|
||||
if type_obj.historical && change_kind != "replace" {
|
||||
let change_sql = format!(
|
||||
"INSERT INTO agreego.change (\"old\", \"new\", entity_id, id, kind, modified_at, modified_by) VALUES ({}, {}, {}, {}, {}, {}, {})",
|
||||
"INSERT INTO agreego.change (\"old\", \"new\", \"entity_id\", \"id\", \"kind\", \"modified_at\", \"modified_by\", \"entity_type\") VALUES ({}, {}, {}, {}, {}, {}, {}, {})",
|
||||
Self::quote_literal(&old_val_obj),
|
||||
Self::quote_literal(&new_val_obj),
|
||||
Self::quote_literal(id_str),
|
||||
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().to_string())),
|
||||
Self::quote_literal(&Value::String(change_kind.to_string())),
|
||||
Self::quote_literal(&Value::String(timestamp.to_string())),
|
||||
Self::quote_literal(&Value::String(user_id.to_string()))
|
||||
Self::quote_literal(&Value::String(user_id.to_string())),
|
||||
Self::quote_literal(&Value::String(entity_type_name.to_string()))
|
||||
);
|
||||
|
||||
self.db.execute(&change_sql, None)?;
|
||||
|
||||
@ -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,6 +621,19 @@ impl<'a> Compiler<'a> {
|
||||
.get(table_to_alias)
|
||||
.or_else(|| type_aliases.get(&node.parent_alias))
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -632,6 +645,7 @@ impl<'a> Compiler<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_filter_alias(
|
||||
r#type: &crate::database::r#type::Type,
|
||||
|
||||
@ -1277,6 +1277,18 @@ fn test_dynamic_type_0_4() {
|
||||
crate::tests::runner::run_test_case(&path, 0, 4).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_type_0_5() {
|
||||
let path = format!("{}/fixtures/dynamicType.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 5).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_type_0_6() {
|
||||
let path = format!("{}/fixtures/dynamicType.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 6).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_property_names_0_0() {
|
||||
let path = format!("{}/fixtures/propertyNames.json", env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
@ -96,8 +96,10 @@ impl Case {
|
||||
let queries = db.executor.get_queries();
|
||||
if std::env::var("UPDATE_EXPECT").is_ok() {
|
||||
crate::tests::runner::update_sql_fixture(path, suite_idx, case_idx, &queries);
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
expect.assert_sql(&queries)
|
||||
}
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -128,8 +130,10 @@ impl Case {
|
||||
let queries = db.executor.get_queries();
|
||||
if std::env::var("UPDATE_EXPECT").is_ok() {
|
||||
crate::tests::runner::update_sql_fixture(path, suite_idx, case_idx, &queries);
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
expect.assert_sql(&queries)
|
||||
}
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
pub mod pattern;
|
||||
pub mod sql;
|
||||
pub mod drop;
|
||||
pub mod schema;
|
||||
|
||||
@ -1,132 +0,0 @@
|
||||
use super::Expect;
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Expect {
|
||||
/// Advanced SQL execution assertion algorithm ported from `assert.go`.
|
||||
/// This compares two arrays of strings, one containing {{uuid:name}} or {{timestamp}} placeholders,
|
||||
/// and the other containing actual executed database queries. It ensures that placeholder UUIDs
|
||||
/// are consistently mapped to the same actual UUIDs across all lines, and strictly validates line-by-line sequences.
|
||||
pub fn assert_pattern(&self, actual: &[String]) -> Result<(), String> {
|
||||
let patterns = match &self.sql {
|
||||
Some(s) => s,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
if patterns.len() != actual.len() {
|
||||
return Err(format!(
|
||||
"Length mismatch: expected {} SQL executions, got {}.\nActual Execution Log:\n{}",
|
||||
patterns.len(),
|
||||
actual.len(),
|
||||
actual.join("\n")
|
||||
));
|
||||
}
|
||||
|
||||
let ws_re = Regex::new(r"\s+").unwrap();
|
||||
|
||||
let types = HashMap::from([
|
||||
(
|
||||
"uuid",
|
||||
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
),
|
||||
(
|
||||
"timestamp",
|
||||
r"\d{4}-\d{2}-\d{2}(?:[ T])\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|\+\d{2}(?::\d{2})?)?",
|
||||
),
|
||||
("integer", r"-?\d+"),
|
||||
("float", r"-?\d+\.\d+"),
|
||||
("text", r"(?:''|[^'])*"),
|
||||
("json", r"(?:''|[^'])*"),
|
||||
]);
|
||||
|
||||
let mut seen: HashMap<String, String> = HashMap::new();
|
||||
let system_uuid = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
// Placeholder regex: {{type:name}} or {{type}}
|
||||
let ph_rx = Regex::new(r"\{\{([a-z]+)(?:[:]([^}]+))?\}\}").unwrap();
|
||||
|
||||
let clean_str = |s: &str| -> String {
|
||||
let mut s = ws_re.replace_all(s, " ").into_owned();
|
||||
for token in ["(", ")", ",", "{", "}", "\"", "=", "'"] {
|
||||
s = s.replace(&format!(" {}", token), token);
|
||||
s = s.replace(&format!("{} ", token), token);
|
||||
}
|
||||
s.trim().to_string()
|
||||
};
|
||||
|
||||
for (i, pattern_expect) in patterns.iter().enumerate() {
|
||||
let aline_raw = &actual[i];
|
||||
let aline = clean_str(aline_raw);
|
||||
|
||||
let pattern_str_raw = match pattern_expect {
|
||||
super::SqlExpectation::Single(s) => s.clone(),
|
||||
super::SqlExpectation::Multi(m) => m.join(" "),
|
||||
};
|
||||
|
||||
let pattern_str = clean_str(&pattern_str_raw);
|
||||
|
||||
let mut pp = regex::escape(&pattern_str);
|
||||
pp = pp.replace(r"\{\{", "{{").replace(r"\}\}", "}}");
|
||||
|
||||
let mut cap_names = HashMap::new(); // cg_X -> var_name
|
||||
let mut group_idx = 0;
|
||||
|
||||
let mut final_rx_str = String::new();
|
||||
let mut last_match = 0;
|
||||
|
||||
let pp_clone = pp.clone();
|
||||
for caps in ph_rx.captures_iter(&pp_clone) {
|
||||
let full_match = caps.get(0).unwrap();
|
||||
final_rx_str.push_str(&pp[last_match..full_match.start()]);
|
||||
|
||||
let type_name = caps.get(1).unwrap().as_str();
|
||||
let var_name = caps.get(2).map(|m| m.as_str());
|
||||
|
||||
if let Some(name) = var_name {
|
||||
if let Some(val) = seen.get(name) {
|
||||
final_rx_str.push_str(®ex::escape(val));
|
||||
} else {
|
||||
let type_pattern = types.get(type_name).unwrap_or(&".*?");
|
||||
let cg_name = format!("cg_{}", group_idx);
|
||||
final_rx_str.push_str(&format!("(?P<{}>{})", cg_name, type_pattern));
|
||||
cap_names.insert(cg_name, name.to_string());
|
||||
group_idx += 1;
|
||||
}
|
||||
} else {
|
||||
let type_pattern = types.get(type_name).unwrap_or(&".*?");
|
||||
final_rx_str.push_str(&format!("(?:{})", type_pattern));
|
||||
}
|
||||
|
||||
last_match = full_match.end();
|
||||
}
|
||||
final_rx_str.push_str(&pp[last_match..]);
|
||||
|
||||
let final_rx = match Regex::new(&format!("^{}$", final_rx_str)) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return Err(format!("Bad constructed regex: {} -> {}", final_rx_str, e)),
|
||||
};
|
||||
|
||||
if let Some(captures) = final_rx.captures(&aline) {
|
||||
for (cg_name, var_name) in cap_names {
|
||||
if let Some(m) = captures.name(&cg_name) {
|
||||
let matched_str = m.as_str();
|
||||
if matched_str != system_uuid {
|
||||
seen.insert(var_name, matched_str.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Line mismatched at execution sequence {}.\nExpected Pattern: {}\nActual SQL: {}\nRegex used: {}\nVariables Mapped: {:?}",
|
||||
i + 1,
|
||||
pattern_str,
|
||||
aline,
|
||||
final_rx_str,
|
||||
seen
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
use super::Expect;
|
||||
use regex::Regex;
|
||||
use sqlparser::ast::{Expr, Query, SelectItem, Statement, TableFactor};
|
||||
use sqlparser::dialect::PostgreSqlDialect;
|
||||
use sqlparser::parser::Parser;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
impl Expect {
|
||||
pub fn assert_sql(&self, actual: &[String]) -> Result<(), String> {
|
||||
@ -11,6 +12,7 @@ impl Expect {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
self.assert_pattern(actual)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -203,4 +205,132 @@ impl Expect {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Advanced SQL execution assertion algorithm ported from `assert.go`.
|
||||
/// This compares two arrays of strings, one containing {{uuid:name}} or {{timestamp}} placeholders,
|
||||
/// and the other containing actual executed database queries. It ensures that placeholder UUIDs
|
||||
/// are consistently mapped to the same actual UUIDs across all lines, and strictly validates line-by-line sequences.
|
||||
pub fn assert_pattern(&self, actual: &[String]) -> Result<(), String> {
|
||||
let patterns = match &self.sql {
|
||||
Some(s) => s,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
if patterns.len() != actual.len() {
|
||||
return Err(format!(
|
||||
"Length mismatch: expected {} SQL executions, got {}.\nActual Execution Log:\n{}",
|
||||
patterns.len(),
|
||||
actual.len(),
|
||||
actual.join("\n")
|
||||
));
|
||||
}
|
||||
|
||||
let ws_re = Regex::new(r"\s+").unwrap();
|
||||
|
||||
let types = HashMap::from([
|
||||
(
|
||||
"uuid",
|
||||
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
),
|
||||
(
|
||||
"timestamp",
|
||||
r"\d{4}-\d{2}-\d{2}(?:[ T])\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|\+\d{2}(?::\d{2})?)?",
|
||||
),
|
||||
("integer", r"-?\d+"),
|
||||
("float", r"-?\d+\.\d+"),
|
||||
("text", r"(?:''|[^'])*"),
|
||||
("json", r"(?:''|[^'])*"),
|
||||
]);
|
||||
|
||||
let mut seen: HashMap<String, String> = HashMap::new();
|
||||
let system_uuid = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
// Placeholder regex: {{type:name}} or {{type}}
|
||||
let ph_rx = Regex::new(r"\{\{([a-z]+)(?:[:]([^}]+))?\}\}").unwrap();
|
||||
|
||||
let clean_str = |s: &str| -> String {
|
||||
let mut s = ws_re.replace_all(s, " ").into_owned();
|
||||
for token in ["(", ")", ",", "{", "}", "\"", "=", "'"] {
|
||||
s = s.replace(&format!(" {}", token), token);
|
||||
s = s.replace(&format!("{} ", token), token);
|
||||
}
|
||||
s.trim().to_string()
|
||||
};
|
||||
|
||||
for (i, pattern_expect) in patterns.iter().enumerate() {
|
||||
let aline_raw = &actual[i];
|
||||
let formatted_actual = crate::tests::formatter::SqlFormatter::format(aline_raw).join(" ");
|
||||
let aline = clean_str(&formatted_actual);
|
||||
|
||||
let pattern_str_raw = match pattern_expect {
|
||||
super::SqlExpectation::Single(s) => s.clone(),
|
||||
super::SqlExpectation::Multi(m) => m.join(" "),
|
||||
};
|
||||
|
||||
let pattern_str = clean_str(&pattern_str_raw);
|
||||
|
||||
let mut pp = regex::escape(&pattern_str);
|
||||
pp = pp.replace(r"\{\{", "{{").replace(r"\}\}", "}}");
|
||||
|
||||
let mut cap_names = HashMap::new(); // cg_X -> var_name
|
||||
let mut group_idx = 0;
|
||||
|
||||
let mut final_rx_str = String::new();
|
||||
let mut last_match = 0;
|
||||
|
||||
let pp_clone = pp.clone();
|
||||
for caps in ph_rx.captures_iter(&pp_clone) {
|
||||
let full_match = caps.get(0).unwrap();
|
||||
final_rx_str.push_str(&pp[last_match..full_match.start()]);
|
||||
|
||||
let type_name = caps.get(1).unwrap().as_str();
|
||||
let var_name = caps.get(2).map(|m| m.as_str());
|
||||
|
||||
if let Some(name) = var_name {
|
||||
if let Some(val) = seen.get(name) {
|
||||
final_rx_str.push_str(®ex::escape(val));
|
||||
} else {
|
||||
let type_pattern = types.get(type_name).unwrap_or(&".*?");
|
||||
let cg_name = format!("cg_{}", group_idx);
|
||||
final_rx_str.push_str(&format!("(?P<{}>{})", cg_name, type_pattern));
|
||||
cap_names.insert(cg_name, name.to_string());
|
||||
group_idx += 1;
|
||||
}
|
||||
} else {
|
||||
let type_pattern = types.get(type_name).unwrap_or(&".*?");
|
||||
final_rx_str.push_str(&format!("(?:{})", type_pattern));
|
||||
}
|
||||
|
||||
last_match = full_match.end();
|
||||
}
|
||||
final_rx_str.push_str(&pp[last_match..]);
|
||||
|
||||
let final_rx = match Regex::new(&format!("^{}$", final_rx_str)) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return Err(format!("Bad constructed regex: {} -> {}", final_rx_str, e)),
|
||||
};
|
||||
|
||||
if let Some(captures) = final_rx.captures(&aline) {
|
||||
for (cg_name, var_name) in cap_names {
|
||||
if let Some(m) = captures.name(&cg_name) {
|
||||
let matched_str = m.as_str();
|
||||
if matched_str != system_uuid {
|
||||
seen.insert(var_name, matched_str.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Line mismatched at execution sequence {}.\nExpected Pattern: {}\nActual SQL: {}\nRegex used: {}\nVariables Mapped: {:?}",
|
||||
i + 1,
|
||||
pattern_str,
|
||||
aline,
|
||||
final_rx_str,
|
||||
seen
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ pub struct ValidationContext<'a> {
|
||||
pub extensible: bool,
|
||||
pub reporter: bool,
|
||||
pub overrides: HashSet<String>,
|
||||
pub parent: Option<&'a serde_json::Value>,
|
||||
pub parents: Vec<&'a serde_json::Value>,
|
||||
}
|
||||
|
||||
impl<'a> ValidationContext<'a> {
|
||||
@ -39,7 +39,7 @@ impl<'a> ValidationContext<'a> {
|
||||
extensible: effective_extensible,
|
||||
reporter,
|
||||
overrides,
|
||||
parent: None,
|
||||
parents: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,11 @@ impl<'a> ValidationContext<'a> {
|
||||
) -> Self {
|
||||
let effective_extensible = schema.extensible.unwrap_or(extensible);
|
||||
|
||||
let mut parents = self.parents.clone();
|
||||
if let Some(p) = parent_instance {
|
||||
parents.push(p);
|
||||
}
|
||||
|
||||
Self {
|
||||
db: self.db,
|
||||
root: self.root,
|
||||
@ -73,7 +78,7 @@ impl<'a> ValidationContext<'a> {
|
||||
extensible: effective_extensible,
|
||||
reporter,
|
||||
overrides,
|
||||
parent: parent_instance,
|
||||
parents,
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +90,7 @@ impl<'a> ValidationContext<'a> {
|
||||
HashSet::new(),
|
||||
self.extensible,
|
||||
reporter,
|
||||
self.parent,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -59,12 +59,13 @@ impl<'a> ValidationContext<'a> {
|
||||
};
|
||||
|
||||
let mut resolved = false;
|
||||
if let Some(parent) = self.parent {
|
||||
for parent in self.parents.iter().rev() {
|
||||
if let Some(obj) = parent.as_object() {
|
||||
if let Some(val) = obj.get(var_name) {
|
||||
if let Some(str_val) = val.as_str() {
|
||||
target_id = format!("{}{}", str_val, suffix);
|
||||
resolved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,7 +98,7 @@ impl<'a> ValidationContext<'a> {
|
||||
new_overrides,
|
||||
self.extensible,
|
||||
true, // Reporter mode
|
||||
self.parent,
|
||||
None,
|
||||
);
|
||||
shadow.root = &global_schema;
|
||||
result.merge(shadow.validate()?);
|
||||
|
||||
Reference in New Issue
Block a user