Compare commits
10 Commits
942520a36a
...
1.0.181
| Author | SHA1 | Date | |
|---|---|---|---|
| e25890461d | |||
| c4bf6bde58 | |||
| 1fedf5253c | |||
| 9ef59422b8 | |||
| b49b216b36 | |||
| 13b28387c2 | |||
| 5b8596f7bd | |||
| 6220a0964d | |||
| 6cd5bfea7e | |||
| a006d3f00a |
36
GEMINI.md
36
GEMINI.md
@ -229,6 +229,40 @@ Traits are reusable, non-generating schema fragments used to share properties an
|
||||
* **Scalars / Arrays / Items**: Host definitions completely override included traits.
|
||||
* The `"include"` keyword is stripped, and `"traits"` maps are omitted from serialization.
|
||||
|
||||
### Static Relation Constraints (Kind Constraints)
|
||||
|
||||
When modeling relational properties on a schema, a developer can define a specialized subset of a related table by applying static property constraints via the `const` or `enum` validation keywords.
|
||||
|
||||
For example, given a general `attachment` table containing a `kind` column (e.g. `'cover'`, `'thumbnail'`, `'document'`), you can define a `cover.attachment` schema that narrows the type using a static `const` assertion:
|
||||
|
||||
```json
|
||||
"cover.attachment": {
|
||||
"type": "attachment",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"type": "string",
|
||||
"const": "cover"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
A parent entity can then define a relationship using this constrained schema under a local property name (e.g. `cover_attachment`):
|
||||
|
||||
```json
|
||||
"cover_attachment": {
|
||||
"properties": {
|
||||
"cover_attachment": {
|
||||
"type": "cover.attachment"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
1. **Validation (L1)**: During payload validation (`jspg_validate`), any incoming object mapped to the constrained property is validated against the static rules (e.g. throwing `CONST_VIOLATED` if `kind` is not `"cover"`).
|
||||
2. **Query Generation (L0)**: When fetching data via `jspg_query`, the Queryer automatically detects the static constraint and compiles it into the SQL subquery's `WHERE` clause (e.g. adding `AND attachment_X.kind = 'cover'`). This produces a pre-filtered view of the related entities natively at the database level.
|
||||
|
||||
---
|
||||
|
||||
## 3. Database
|
||||
@ -314,6 +348,8 @@ The Queryer transforms Postgres into a pre-compiled Semantic Query Engine, desig
|
||||
* **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.
|
||||
* **Static Relation Constraints (Kind Constraints)**: When a relationship (such as a nested object or array) is defined with a schema that constrains a field value statically using a `const` or `enum` keyword (for example, `kind` constrained to `"cover"` in a `cover_attachment`), the Queryer automatically extracts these static assertions during AST compilation. It injects them directly as static filters into the SQL subquery's `WHERE` clause (e.g. `AND attachment.kind = 'cover'`), allowing developers to query pre-filtered subsets of related tables natively through the schema.
|
||||
* **Proxy Schema Dereferencing / Resolution**: To support punc endpoints that return non-polymorphic table-backed shapes (using `type: "full.X"` proxy schemas at the root response level), the Queryer compiler automatically dereferences non-table schema pointers to their target schemas prior to checking the types. This allows the Queryer to correctly resolve the table relationship edges pre-compiled on the full schema, while avoiding polluting the database registry with relations on ad-hoc punc response schemas during setup.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -227,8 +227,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -268,8 +268,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -347,8 +347,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -373,8 +373,8 @@
|
||||
{
|
||||
"code": "MULTIPLE_OF_VIOLATED",
|
||||
"values": {
|
||||
"multiple_of": "2",
|
||||
"value": "3"
|
||||
"value": "3",
|
||||
"multiple_of": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "0",
|
||||
@ -384,8 +384,8 @@
|
||||
{
|
||||
"code": "MULTIPLE_OF_VIOLATED",
|
||||
"values": {
|
||||
"multiple_of": "2",
|
||||
"value": "9"
|
||||
"value": "9",
|
||||
"multiple_of": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "2",
|
||||
@ -432,8 +432,8 @@
|
||||
{
|
||||
"code": "MULTIPLE_OF_VIOLATED",
|
||||
"values": {
|
||||
"multiple_of": "2",
|
||||
"value": "1"
|
||||
"value": "1",
|
||||
"multiple_of": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "0",
|
||||
|
||||
@ -62,8 +62,8 @@
|
||||
"code": "EDGE_MISSING",
|
||||
"values": {
|
||||
"parent_type": "org",
|
||||
"property_name": "missing_users",
|
||||
"child_type": "user"
|
||||
"child_type": "user",
|
||||
"property_name": "missing_users"
|
||||
},
|
||||
"details": {
|
||||
"path": "full.org/missing_users",
|
||||
@ -151,8 +151,8 @@
|
||||
{
|
||||
"code": "EDGE_MISSING",
|
||||
"values": {
|
||||
"child_type": "child",
|
||||
"parent_type": "parent",
|
||||
"child_type": "child",
|
||||
"property_name": "children"
|
||||
},
|
||||
"details": {
|
||||
@ -470,8 +470,8 @@
|
||||
{
|
||||
"code": "DATABASE_TYPE_PARSE_FAILED",
|
||||
"values": {
|
||||
"reason": "invalid type: sequence, expected a string",
|
||||
"type": "failure"
|
||||
"type": "failure",
|
||||
"reason": "invalid type: sequence, expected a string"
|
||||
},
|
||||
"details": {
|
||||
"context": "failure"
|
||||
|
||||
@ -227,8 +227,8 @@
|
||||
{
|
||||
"code": "DEPENDENCY_MISSING",
|
||||
"values": {
|
||||
"required_property": "bar",
|
||||
"property_name": "quux"
|
||||
"property_name": "quux",
|
||||
"required_property": "bar"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -386,8 +386,8 @@
|
||||
{
|
||||
"code": "DEPENDENCY_MISSING",
|
||||
"values": {
|
||||
"required_property": "foo'bar",
|
||||
"property_name": "foo\"bar"
|
||||
"property_name": "foo\"bar",
|
||||
"required_property": "foo'bar"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -829,8 +829,8 @@
|
||||
{
|
||||
"code": "MIN_PROPERTIES_VIOLATED",
|
||||
"values": {
|
||||
"limit": "4",
|
||||
"count": "2"
|
||||
"count": "2",
|
||||
"limit": "4"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
{
|
||||
"code": "EXCLUSIVE_MAXIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "3",
|
||||
"value": "3"
|
||||
"value": "3",
|
||||
"limit": "3"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
{
|
||||
"code": "EXCLUSIVE_MINIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1.1",
|
||||
"value": "1.1"
|
||||
"value": "1.1",
|
||||
"limit": "1.1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -259,74 +259,42 @@
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"age": {
|
||||
"type": [
|
||||
"integer.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"billing_address": {
|
||||
"type": [
|
||||
"address.filter",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"city",
|
||||
"$and",
|
||||
"$or"
|
||||
]
|
||||
},
|
||||
"gender": {
|
||||
"type": [
|
||||
"gender.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq",
|
||||
"$ne",
|
||||
"$of",
|
||||
"$nof"
|
||||
]
|
||||
},
|
||||
"birth_date": {
|
||||
"type": [
|
||||
"date.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": [
|
||||
"uuid.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"tags": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"ad_hoc": {
|
||||
@ -339,10 +307,6 @@
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -414,10 +378,6 @@
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"$and": {
|
||||
@ -469,20 +429,12 @@
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
],
|
||||
"compiledPropertyNames": [
|
||||
"kind",
|
||||
"$eq"
|
||||
]
|
||||
},
|
||||
"filter": {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -106,8 +106,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "2"
|
||||
"count": "2",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -144,8 +144,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "2"
|
||||
"count": "2",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -284,8 +284,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "3",
|
||||
"count": "4"
|
||||
"count": "4",
|
||||
"limit": "3"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -52,8 +52,8 @@
|
||||
{
|
||||
"code": "MAX_ITEMS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "3"
|
||||
"count": "3",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -43,8 +43,8 @@
|
||||
{
|
||||
"code": "MAX_LENGTH_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "3"
|
||||
"count": "3",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -109,8 +109,8 @@
|
||||
{
|
||||
"code": "MAX_LENGTH_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "3"
|
||||
"count": "3",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -139,8 +139,8 @@
|
||||
{
|
||||
"code": "MAX_PROPERTIES_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "3"
|
||||
"count": "3",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -190,8 +190,8 @@
|
||||
{
|
||||
"code": "MAX_PROPERTIES_VIOLATED",
|
||||
"values": {
|
||||
"limit": "0",
|
||||
"count": "1"
|
||||
"count": "1",
|
||||
"limit": "0"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -118,8 +118,8 @@
|
||||
{
|
||||
"code": "MAXIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "300",
|
||||
"value": "300.5"
|
||||
"value": "300.5",
|
||||
"limit": "300"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -239,8 +239,8 @@
|
||||
{
|
||||
"code": "DEPENDENCY_MISSING",
|
||||
"values": {
|
||||
"required_property": "base_dep",
|
||||
"property_name": "trigger"
|
||||
"property_name": "trigger",
|
||||
"required_property": "base_dep"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -169,8 +169,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -357,8 +357,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -463,8 +463,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "3",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "3"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -487,8 +487,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "3",
|
||||
"count": "1"
|
||||
"count": "1",
|
||||
"limit": "3"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -513,8 +513,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "3"
|
||||
"count": "3",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -657,8 +657,8 @@
|
||||
{
|
||||
"code": "CONTAINS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "2"
|
||||
"count": "2",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -108,8 +108,8 @@
|
||||
{
|
||||
"code": "MIN_ITEMS_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1",
|
||||
"count": "0"
|
||||
"count": "0",
|
||||
"limit": "1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -43,8 +43,8 @@
|
||||
{
|
||||
"code": "MIN_LENGTH_VIOLATED",
|
||||
"values": {
|
||||
"limit": "2",
|
||||
"count": "1"
|
||||
"count": "1",
|
||||
"limit": "2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -43,8 +43,8 @@
|
||||
{
|
||||
"code": "MINIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "1.1",
|
||||
"value": "0.6"
|
||||
"value": "0.6",
|
||||
"limit": "1.1"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -127,8 +127,8 @@
|
||||
{
|
||||
"code": "MINIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "-2",
|
||||
"value": "-2.0001"
|
||||
"value": "-2.0001",
|
||||
"limit": "-2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -149,8 +149,8 @@
|
||||
{
|
||||
"code": "MINIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "-2",
|
||||
"value": "-3"
|
||||
"value": "-3",
|
||||
"limit": "-2"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -148,8 +148,8 @@
|
||||
{
|
||||
"code": "MULTIPLE_OF_VIOLATED",
|
||||
"values": {
|
||||
"multiple_of": "0.0001",
|
||||
"value": "0.00751"
|
||||
"value": "0.00751",
|
||||
"multiple_of": "0.0001"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -156,8 +156,8 @@
|
||||
{
|
||||
"code": "MAXIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "50",
|
||||
"value": "60"
|
||||
"value": "60",
|
||||
"limit": "50"
|
||||
},
|
||||
"details": {
|
||||
"path": "max",
|
||||
|
||||
@ -200,8 +200,8 @@
|
||||
{
|
||||
"code": "MINIMUM_VIOLATED",
|
||||
"values": {
|
||||
"limit": "10",
|
||||
"value": "5"
|
||||
"value": "5",
|
||||
"limit": "10"
|
||||
},
|
||||
"details": {
|
||||
"path": "entities/entity-beta/value",
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
{
|
||||
"code": "PATTERN_VIOLATED",
|
||||
"values": {
|
||||
"value": "abc",
|
||||
"pattern": "^a*$"
|
||||
"pattern": "^a*$",
|
||||
"value": "abc"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -148,8 +148,8 @@
|
||||
{
|
||||
"code": "NO_FAMILY_MATCH",
|
||||
"values": {
|
||||
"value": "alien",
|
||||
"discriminator": "type"
|
||||
"discriminator": "type",
|
||||
"value": "alien"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -284,8 +284,8 @@
|
||||
{
|
||||
"code": "NO_FAMILY_MATCH",
|
||||
"values": {
|
||||
"value": "bot",
|
||||
"discriminator": "type"
|
||||
"discriminator": "type",
|
||||
"value": "bot"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -591,8 +591,8 @@
|
||||
{
|
||||
"code": "NO_ONEOF_MATCH",
|
||||
"values": {
|
||||
"value": "alien",
|
||||
"discriminator": "type"
|
||||
"discriminator": "type",
|
||||
"value": "alien"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
@ -931,8 +931,8 @@
|
||||
{
|
||||
"code": "NO_FAMILY_MATCH",
|
||||
"values": {
|
||||
"value": "unknown_panel",
|
||||
"discriminator": "kind"
|
||||
"discriminator": "kind",
|
||||
"value": "unknown_panel"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -431,8 +431,8 @@
|
||||
{
|
||||
"code": "MAX_LENGTH_VIOLATED",
|
||||
"values": {
|
||||
"limit": "3",
|
||||
"count": "6"
|
||||
"count": "6",
|
||||
"limit": "3"
|
||||
},
|
||||
"details": {
|
||||
"path": "",
|
||||
|
||||
@ -2461,11 +2461,13 @@
|
||||
"constraint": "fk_attachment_attachable_entity",
|
||||
"source_type": "attachment",
|
||||
"source_columns": [
|
||||
"attachable_id"
|
||||
"attachable_id",
|
||||
"attachable_type"
|
||||
],
|
||||
"destination_type": "entity",
|
||||
"destination_columns": [
|
||||
"id"
|
||||
"id",
|
||||
"type"
|
||||
],
|
||||
"prefix": "attachable"
|
||||
}
|
||||
@ -2547,10 +2549,7 @@
|
||||
"type": "pet",
|
||||
"properties": {
|
||||
"cover_attachment": {
|
||||
"type": [
|
||||
"attachment",
|
||||
"null"
|
||||
],
|
||||
"type": "attachment",
|
||||
"properties": {
|
||||
"kind": {
|
||||
"const": "cover"
|
||||
@ -2672,6 +2671,7 @@
|
||||
" NOT entity_3.archived",
|
||||
" AND attachment_4.kind = 'cover'",
|
||||
" AND attachment_4.attachable_id = entity_1.id",
|
||||
" LIMIT 1",
|
||||
" ),",
|
||||
" 'cover_attachments', (",
|
||||
" SELECT COALESCE(jsonb_agg(jsonb_build_object(",
|
||||
|
||||
@ -139,8 +139,8 @@
|
||||
{
|
||||
"code": "MAX_LENGTH_VIOLATED",
|
||||
"values": {
|
||||
"limit": "5",
|
||||
"count": "26"
|
||||
"count": "26",
|
||||
"limit": "5"
|
||||
},
|
||||
"details": {
|
||||
"path": "email",
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::database::schema::Schema;
|
||||
#[allow(unused_imports)]
|
||||
use crate::drop::{Error, ErrorDetails};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl Schema {
|
||||
@ -19,7 +19,7 @@ impl Schema {
|
||||
if !c.is_ascii_lowercase() && !c.is_ascii_digit() && c != '_' && c != '.' && c != '$' {
|
||||
errors.push(Error {
|
||||
code: "INVALID_IDENTIFIER".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("character".to_string(), c.to_string()),
|
||||
("field_name".to_string(), field_name.to_string()),
|
||||
("identifier".to_string(), id.to_string()),
|
||||
|
||||
@ -29,21 +29,10 @@ impl Schema {
|
||||
if db.types.contains_key(&base_type_name) {
|
||||
parent_type_name = Some(base_type_name);
|
||||
}
|
||||
} else if let Some(t_or_arr) = &self.obj.type_ {
|
||||
match t_or_arr {
|
||||
crate::database::object::SchemaTypeOrArray::Single(t) => {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
parent_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
}
|
||||
crate::database::object::SchemaTypeOrArray::Multiple(types) => {
|
||||
for t in types {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
parent_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &self.obj.type_ {
|
||||
// 3. Nested graphs trust their explicit struct pointer reference
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
parent_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,23 +46,13 @@ impl Schema {
|
||||
let mut is_array = false;
|
||||
|
||||
// Structurally unpack the inner target entity if the object maps to an array list
|
||||
if let Some(t_or_arr) = &prop_schema.obj.type_ {
|
||||
match t_or_arr {
|
||||
crate::database::object::SchemaTypeOrArray::Single(t) => {
|
||||
if t == "array" {
|
||||
is_array = true;
|
||||
if let Some(items) = &prop_schema.obj.items {
|
||||
target_schema = items.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::database::object::SchemaTypeOrArray::Multiple(types) => {
|
||||
if types.contains(&"array".to_string()) {
|
||||
is_array = true;
|
||||
if let Some(items) = &prop_schema.obj.items {
|
||||
target_schema = items.clone();
|
||||
}
|
||||
}
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
||||
&prop_schema.obj.type_
|
||||
{
|
||||
if t == "array" {
|
||||
is_array = true;
|
||||
if let Some(items) = &prop_schema.obj.items {
|
||||
target_schema = items.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,21 +60,11 @@ impl Schema {
|
||||
// Determine the physical Postgres table backing the nested child schema recursively
|
||||
if let Some(family) = &target_schema.obj.family {
|
||||
child_type_name = Some(family.split('.').next_back().unwrap_or(family).to_string());
|
||||
} else if let Some(t_or_arr) = &target_schema.obj.type_ {
|
||||
match t_or_arr {
|
||||
crate::database::object::SchemaTypeOrArray::Single(t) => {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
child_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
}
|
||||
crate::database::object::SchemaTypeOrArray::Multiple(types) => {
|
||||
for t in types {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
child_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
||||
&target_schema.obj.type_
|
||||
{
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
child_type_name = Some(t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
} else if let Some(arr) = &target_schema.obj.one_of {
|
||||
if let Some(first) = arr.first() {
|
||||
|
||||
@ -7,7 +7,6 @@ pub mod polymorphism;
|
||||
use crate::database::schema::Schema;
|
||||
use crate::drop::{Error, ErrorDetails};
|
||||
use indexmap::IndexMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Schema {
|
||||
pub fn compile(
|
||||
@ -40,7 +39,6 @@ impl Schema {
|
||||
}
|
||||
|
||||
let mut props = IndexMap::new();
|
||||
let mut inherited_edges = IndexMap::new();
|
||||
|
||||
// 1. Resolve INHERITANCE dependencies first
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &self.obj.type_ {
|
||||
@ -50,9 +48,6 @@ impl Schema {
|
||||
if let Some(p_props) = parent.obj.compiled_properties.get() {
|
||||
props.extend(p_props.clone());
|
||||
}
|
||||
if let Some(p_edges) = parent.obj.compiled_edges.get() {
|
||||
inherited_edges.extend(p_edges.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,7 +63,7 @@ impl Schema {
|
||||
if custom_type_count > 1 {
|
||||
errors.push(Error {
|
||||
code: "MULTIPLE_INHERITANCE_PROHIBITED".to_string(),
|
||||
values: Some(HashMap::from([("types".to_string(), types.join(", "))])),
|
||||
values: Some(IndexMap::from([("types".to_string(), types.join(", "))])),
|
||||
details: ErrorDetails {
|
||||
path: Some(path.clone()),
|
||||
schema: Some(root_id.to_string()),
|
||||
@ -81,12 +76,6 @@ impl Schema {
|
||||
if !crate::database::object::is_primitive_type(t) && !t.starts_with('$') {
|
||||
if let Some(parent) = db.schemas.get(t).cloned() {
|
||||
parent.as_ref().compile(db, t, t.clone(), errors);
|
||||
if let Some(p_props) = parent.obj.compiled_properties.get() {
|
||||
props.extend(p_props.clone());
|
||||
}
|
||||
if let Some(p_edges) = parent.obj.compiled_edges.get() {
|
||||
inherited_edges.extend(p_edges.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,10 +115,7 @@ impl Schema {
|
||||
let _ = self.obj.compiled_property_names.set(names);
|
||||
|
||||
// 5. Compute Edges natively
|
||||
let mut schema_edges = self.compile_edges(db, root_id, &path, &props, errors);
|
||||
for (k, v) in inherited_edges {
|
||||
schema_edges.entry(k).or_insert(v);
|
||||
}
|
||||
let schema_edges = self.compile_edges(db, root_id, &path, &props, errors);
|
||||
let _ = self.obj.compiled_edges.set(schema_edges);
|
||||
|
||||
// 5. Build our inline children properties recursively NOW! (Depth-first search)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::drop::{Error, ErrorDetails};
|
||||
use indexmap::IndexSet;
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use crate::database::schema::Schema;
|
||||
|
||||
impl Schema {
|
||||
@ -144,7 +144,7 @@ impl Schema {
|
||||
if options.contains_key(&val) {
|
||||
errors.push(Error {
|
||||
code: "POLYMORPHIC_COLLISION".to_string(),
|
||||
values: Some(HashMap::from([("value".to_string(), val.to_string())])),
|
||||
values: Some(IndexMap::from([("value".to_string(), val.to_string())])),
|
||||
details: ErrorDetails {
|
||||
path: Some(path.to_string()),
|
||||
schema: Some(root_id.to_string()),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use crate::drop::{Error, ErrorDetails};
|
||||
use serde_json::Value;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
pub fn compose(val: &mut Value, errors: &mut Vec<Error>) {
|
||||
let mut traits = HashMap::new();
|
||||
@ -114,7 +115,7 @@ fn resolve_in_place(
|
||||
if visited.contains(inc_name) {
|
||||
errors.push(Error {
|
||||
code: "CIRCULAR_INCLUDE_DETECTED".to_string(),
|
||||
values: Some(HashMap::from([(
|
||||
values: Some(IndexMap::from([(
|
||||
"include".to_string(),
|
||||
inc_name.to_string(),
|
||||
)])),
|
||||
@ -218,7 +219,7 @@ fn resolve_in_place(
|
||||
} else {
|
||||
errors.push(Error {
|
||||
code: "TRAIT_NOT_FOUND".to_string(),
|
||||
values: Some(HashMap::from([(
|
||||
values: Some(IndexMap::from([(
|
||||
"include".to_string(),
|
||||
inc_name.to_string(),
|
||||
)])),
|
||||
|
||||
@ -28,7 +28,7 @@ use serde_json::Value;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
use r#type::Type;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::drop::{Drop, Error, ErrorDetails};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@ -76,7 +76,7 @@ impl Database {
|
||||
Err(e) => {
|
||||
errors.push(Error {
|
||||
code: "DATABASE_ENUM_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("enum".to_string(), name.clone()),
|
||||
("reason".to_string(), e.to_string()),
|
||||
])),
|
||||
@ -104,7 +104,7 @@ impl Database {
|
||||
Err(e) => {
|
||||
errors.push(Error {
|
||||
code: "DATABASE_TYPE_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("type".to_string(), name.clone()),
|
||||
("reason".to_string(), e.to_string()),
|
||||
])),
|
||||
@ -136,7 +136,7 @@ impl Database {
|
||||
Err(e) => {
|
||||
errors.push(Error {
|
||||
code: "DATABASE_RELATION_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("relation".to_string(), constraint.clone()),
|
||||
("reason".to_string(), e.to_string()),
|
||||
])),
|
||||
@ -164,7 +164,7 @@ impl Database {
|
||||
Err(e) => {
|
||||
errors.push(Error {
|
||||
code: "DATABASE_PUNC_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("punc".to_string(), name.clone()),
|
||||
("reason".to_string(), e.to_string()),
|
||||
])),
|
||||
@ -461,7 +461,7 @@ impl Database {
|
||||
|
||||
errors.push(Error {
|
||||
code: "EDGE_MISSING".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("parent_type".to_string(), parent_type.to_string()),
|
||||
("child_type".to_string(), child_type.to_string()),
|
||||
("property_name".to_string(), prop_name.to_string()),
|
||||
@ -563,7 +563,7 @@ impl Database {
|
||||
|
||||
errors.push(Error {
|
||||
code: "AMBIGUOUS_TYPE_RELATIONS".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("parent_type".to_string(), parent_type.to_string()),
|
||||
("child_type".to_string(), child_type.to_string()),
|
||||
("property_name".to_string(), prop_name.to_string()),
|
||||
|
||||
@ -57,13 +57,13 @@ impl Drop {
|
||||
}
|
||||
}
|
||||
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Error {
|
||||
pub code: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub values: Option<HashMap<String, String>>,
|
||||
pub values: Option<IndexMap<String, String>>,
|
||||
pub details: ErrorDetails,
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::database::Database;
|
||||
use crate::database::r#type::Type;
|
||||
use crate::drop::{Drop, Error, ErrorDetails};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Merger {
|
||||
@ -31,7 +31,7 @@ impl Merger {
|
||||
None => {
|
||||
return Drop::with_errors(vec![Error {
|
||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("schema".to_string(), schema_id.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -78,7 +78,7 @@ impl Merger {
|
||||
|
||||
return Drop::with_errors(vec![Error {
|
||||
code: final_code,
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), final_message),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -96,7 +96,7 @@ impl Merger {
|
||||
if let Err(e) = self.db.execute(¬ify_sql, None) {
|
||||
return Drop::with_errors(vec![Error {
|
||||
code: "MERGE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), e.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
|
||||
@ -87,29 +87,13 @@ impl<'a> Compiler<'a> {
|
||||
.next_back()
|
||||
.unwrap_or(family_target);
|
||||
resolved_type = self.db.types.get(base_type_name);
|
||||
} else if let Some(t_or_arr) = &items.obj.type_ {
|
||||
match t_or_arr {
|
||||
crate::database::object::SchemaTypeOrArray::Single(t) => {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
resolved_type = self
|
||||
.db
|
||||
.types
|
||||
.get(&t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
}
|
||||
crate::database::object::SchemaTypeOrArray::Multiple(types) => {
|
||||
for t in types {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
resolved_type = self
|
||||
.db
|
||||
.types
|
||||
.get(&t.split('.').next_back().unwrap_or(t).to_string());
|
||||
if resolved_type.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &items.obj.type_
|
||||
{
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
resolved_type = self
|
||||
.db
|
||||
.types
|
||||
.get(&t.split('.').next_back().unwrap_or(t).to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,6 +121,21 @@ impl<'a> Compiler<'a> {
|
||||
}
|
||||
|
||||
fn compile_reference(&mut self, node: Node<'a>) -> Result<(String, String), String> {
|
||||
// Handle Direct Refs via type pointer first
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &node.schema.obj.type_ {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
if !self.db.types.contains_key(t) {
|
||||
// If it's just an ad-hoc struct ref, we should resolve it
|
||||
if let Some(target_schema) = self.db.schemas.get(t).cloned() {
|
||||
let mut ref_node = node.clone();
|
||||
ref_node.schema = target_schema.clone();
|
||||
ref_node.schema_id = Some(t.clone());
|
||||
return self.compile_node(ref_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if this schema represents a Database Entity
|
||||
let mut resolved_type = None;
|
||||
|
||||
@ -152,25 +151,12 @@ impl<'a> Compiler<'a> {
|
||||
.next_back()
|
||||
.unwrap_or(family_target);
|
||||
resolved_type = self.db.types.get(base_type_name);
|
||||
} else if let Some(t_or_arr) = &node.schema.obj.type_ {
|
||||
match t_or_arr {
|
||||
crate::database::object::SchemaTypeOrArray::Single(t) => {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
let base_type_name = t.split('.').next_back().unwrap_or(t).to_string();
|
||||
resolved_type = self.db.types.get(&base_type_name);
|
||||
}
|
||||
}
|
||||
crate::database::object::SchemaTypeOrArray::Multiple(types) => {
|
||||
for t in types {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
let base_type_name = t.split('.').next_back().unwrap_or(t).to_string();
|
||||
resolved_type = self.db.types.get(&base_type_name);
|
||||
if resolved_type.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
||||
&node.schema.obj.type_
|
||||
{
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
let base_type_name = t.split('.').next_back().unwrap_or(t).to_string();
|
||||
resolved_type = self.db.types.get(&base_type_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -179,16 +165,9 @@ impl<'a> Compiler<'a> {
|
||||
return self.compile_entity(type_def, node.clone(), false);
|
||||
}
|
||||
|
||||
// Handle Direct Refs via type pointer
|
||||
// Fallback error if the schema pointer was unresolved
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &node.schema.obj.type_ {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
// If it's just an ad-hoc struct ref, we should resolve it
|
||||
if let Some(target_schema) = self.db.schemas.get(t).cloned() {
|
||||
let mut ref_node = node.clone();
|
||||
ref_node.schema = target_schema.clone();
|
||||
ref_node.schema_id = Some(t.clone());
|
||||
return self.compile_node(ref_node);
|
||||
}
|
||||
return Err(format!("Unresolved schema type pointer: {}", t));
|
||||
}
|
||||
}
|
||||
@ -261,7 +240,7 @@ impl<'a> Compiler<'a> {
|
||||
};
|
||||
|
||||
// 3. Build WHERE clauses
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node)?;
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node.clone())?;
|
||||
|
||||
let selection = if is_array {
|
||||
format!("COALESCE(jsonb_agg({}), '[]'::jsonb)", jsonb_obj_sql)
|
||||
@ -269,11 +248,38 @@ impl<'a> Compiler<'a> {
|
||||
jsonb_obj_sql
|
||||
};
|
||||
|
||||
let mut limit_clause = "";
|
||||
if !is_array {
|
||||
let is_reverse = if let Some(prop_ref) = &node.property_name {
|
||||
let prop = prop_ref.as_str();
|
||||
if let Some(parent_schema) = &node.parent_schema {
|
||||
if let Some(compiled_edges) = parent_schema.obj.compiled_edges.get() {
|
||||
if let Some(edge) = compiled_edges.get(prop) {
|
||||
!edge.forward
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if is_reverse {
|
||||
limit_clause = " LIMIT 1";
|
||||
}
|
||||
}
|
||||
|
||||
let full_sql = format!(
|
||||
"(SELECT {} FROM {} WHERE {})",
|
||||
"(SELECT {} FROM {} WHERE {}{})",
|
||||
selection,
|
||||
from_clauses.join(" "),
|
||||
where_clauses.join(" AND ")
|
||||
where_clauses.join(" AND "),
|
||||
limit_clause
|
||||
);
|
||||
|
||||
Ok((
|
||||
@ -469,9 +475,6 @@ impl<'a> Compiler<'a> {
|
||||
Some(crate::database::object::SchemaTypeOrArray::Single(s)) => {
|
||||
!crate::database::object::is_primitive_type(s)
|
||||
}
|
||||
Some(crate::database::object::SchemaTypeOrArray::Multiple(v)) => {
|
||||
v.iter().any(|s| !crate::database::object::is_primitive_type(s))
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
@ -645,9 +648,6 @@ impl<'a> Compiler<'a> {
|
||||
if edge.forward && relation.source_columns.len() > 1 {
|
||||
poly_col = Some(&relation.source_columns[1]); // e.g., target_type
|
||||
table_to_alias = &relation.source_type; // e.g., relationship
|
||||
} else if !edge.forward && relation.destination_columns.len() > 1 {
|
||||
poly_col = Some(&relation.destination_columns[1]); // e.g., source_type
|
||||
table_to_alias = &relation.destination_type; // e.g., relationship
|
||||
}
|
||||
|
||||
if let Some(col) = poly_col {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::database::Database;
|
||||
use crate::drop::{Drop, Error, ErrorDetails};
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod compiler;
|
||||
@ -33,7 +33,7 @@ impl Queryer {
|
||||
Err(msg) => {
|
||||
return Drop::with_errors(vec![Error {
|
||||
code: "FILTER_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), msg.clone()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -140,7 +140,7 @@ impl Queryer {
|
||||
}
|
||||
Err(e) => Err(Drop::with_errors(vec![Error {
|
||||
code: "QUERY_COMPILATION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), e.clone()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -169,7 +169,7 @@ impl Queryer {
|
||||
}
|
||||
Ok(other) => Drop::with_errors(vec![Error {
|
||||
code: "QUERY_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), format!("Expected array from generic query, got: {:?}", other)),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -181,7 +181,7 @@ impl Queryer {
|
||||
}]),
|
||||
Err(e) => Drop::with_errors(vec![Error {
|
||||
code: "QUERY_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), e.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
|
||||
@ -180,6 +180,9 @@ impl SqlFormatter {
|
||||
|
||||
fn format_query(&mut self, query: &Query) {
|
||||
self.format_set_expr(&query.body);
|
||||
if let Some(limit_clause) = &query.limit_clause {
|
||||
self.push_line(&format!("{}", limit_clause.to_string().trim()));
|
||||
}
|
||||
}
|
||||
|
||||
fn format_set_expr(&mut self, set_expr: &SetExpr) {
|
||||
|
||||
@ -157,10 +157,7 @@ fn test_library_api() {
|
||||
}
|
||||
},
|
||||
"name": { "type": ["string.condition", "null"] },
|
||||
"target": {
|
||||
"type": ["target_schema.filter", "null"],
|
||||
"compiledPropertyNames": ["value", "$and", "$or"]
|
||||
},
|
||||
"target": { "type": ["target_schema.filter", "null"] },
|
||||
"type": { "type": ["string.condition", "null"] }
|
||||
},
|
||||
"type": "filter"
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct ValidationError {
|
||||
pub code: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub values: Option<HashMap<String, String>>,
|
||||
pub values: Option<IndexMap<String, String>>,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
pub mod context;
|
||||
pub mod error;
|
||||
@ -92,7 +93,7 @@ impl Validator {
|
||||
} else {
|
||||
Drop::with_errors(vec![Error {
|
||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("schema".to_string(), schema_id.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
@ -18,7 +19,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MIN_ITEMS_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), arr.len().to_string()),
|
||||
("limit".to_string(), min.to_string()),
|
||||
])),
|
||||
@ -30,7 +31,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAX_ITEMS_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), arr.len().to_string()),
|
||||
("limit".to_string(), max.to_string()),
|
||||
])),
|
||||
@ -77,7 +78,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if _match_count < min {
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONTAINS_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), _match_count.to_string()),
|
||||
("limit".to_string(), min.to_string()),
|
||||
])),
|
||||
@ -89,7 +90,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONTAINS_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), _match_count.to_string()),
|
||||
("limit".to_string(), max.to_string()),
|
||||
])),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::validator::Validator;
|
||||
use crate::validator::context::ValidationContext;
|
||||
@ -19,7 +19,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !Validator::check_type(t, current) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "INVALID_TYPE".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("expected".to_string(), t.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
@ -37,7 +37,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !valid {
|
||||
result.errors.push(ValidationError {
|
||||
code: "INVALID_TYPE".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("expected".to_string(), format!("{:?}", types)),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
@ -51,7 +51,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !equals(current, const_val) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONST_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("expected".to_string(), format!("{:?}", const_val)),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
@ -74,7 +74,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !found {
|
||||
result.errors.push(ValidationError {
|
||||
code: "ENUM_MISMATCH".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("expected".to_string(), format!("{:?}", enum_vals)),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::database::object::{is_primitive_type, SchemaTypeOrArray};
|
||||
use crate::database::schema::Schema;
|
||||
@ -75,7 +75,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !result.evaluated_keys.contains(key) && !self.overrides.contains(key) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "STRICT_PROPERTY_VIOLATION".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("property_name".to_string(), key.to_string()),
|
||||
])),
|
||||
path: self.join_path(key),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
@ -21,7 +21,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if should && let Err(e) = f(current) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "FORMAT_MISMATCH".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("format".to_string(), self.schema.format.clone().unwrap_or_default()),
|
||||
("error".to_string(), e.to_string()),
|
||||
])),
|
||||
@ -35,7 +35,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "FORMAT_MISMATCH".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("format".to_string(), self.schema.format.clone().unwrap_or_default()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
use crate::validator::result::ValidationResult;
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
pub mod array;
|
||||
pub mod cases;
|
||||
@ -64,7 +64,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if self.depth > 100 {
|
||||
Err(ValidationError {
|
||||
code: "RECURSION_LIMIT_EXCEEDED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("limit".to_string(), 100.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
@ -16,7 +16,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MINIMUM_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), num.to_string()),
|
||||
("limit".to_string(), min.to_string()),
|
||||
])),
|
||||
@ -28,7 +28,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAXIMUM_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), num.to_string()),
|
||||
("limit".to_string(), max.to_string()),
|
||||
])),
|
||||
@ -40,7 +40,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "EXCLUSIVE_MINIMUM_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), num.to_string()),
|
||||
("limit".to_string(), ex_min.to_string()),
|
||||
])),
|
||||
@ -52,7 +52,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "EXCLUSIVE_MAXIMUM_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), num.to_string()),
|
||||
("limit".to_string(), ex_max.to_string()),
|
||||
])),
|
||||
@ -64,7 +64,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if (val - val.round()).abs() > f64::EPSILON {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MULTIPLE_OF_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), num.to_string()),
|
||||
("multiple_of".to_string(), multiple_of.to_string()),
|
||||
])),
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashSet;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
@ -38,7 +39,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONST_VIOLATED".to_string(), // Aligning with original const override errors natively
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("value".to_string(), type_str.to_string()),
|
||||
])),
|
||||
path: self.join_path("type"),
|
||||
@ -49,7 +50,7 @@ impl<'a> ValidationContext<'a> {
|
||||
// Because it's a global entity target, the payload must structurally provide a discriminator natively
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_TYPE".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("expected".to_string(), expected_type.to_string()),
|
||||
])),
|
||||
path: self.path.clone(), // Empty boundary
|
||||
@ -104,7 +105,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MIN_PROPERTIES_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), obj.len().to_string()),
|
||||
("limit".to_string(), min.to_string()),
|
||||
])),
|
||||
@ -117,7 +118,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAX_PROPERTIES_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), obj.len().to_string()),
|
||||
("limit".to_string(), max.to_string()),
|
||||
])),
|
||||
@ -131,7 +132,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if field == "type" {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_TYPE".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("field_name".to_string(), "type".to_string()),
|
||||
])),
|
||||
path: self.join_path(field),
|
||||
@ -139,7 +140,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "REQUIRED_FIELD_MISSING".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("field_name".to_string(), field.to_string()),
|
||||
])),
|
||||
path: self.join_path(field),
|
||||
@ -158,7 +159,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !obj.contains_key(req_prop) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "DEPENDENCY_MISSING".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("property_name".to_string(), prop.to_string()),
|
||||
("required_property".to_string(), req_prop.to_string()),
|
||||
])),
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
use crate::validator::result::ValidationResult;
|
||||
@ -55,10 +53,10 @@ impl<'a> ValidationContext<'a> {
|
||||
return self.execute_polymorph(options, result);
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "UNCOMPILED_ONEOF".to_string(),
|
||||
values: None,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
code: "UNCOMPILED_ONEOF".to_string(),
|
||||
values: None,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
@ -110,9 +108,10 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_COMPILED_SCHEMA".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
("target_id".to_string(), target_id.to_string()),
|
||||
])),
|
||||
values: Some(IndexMap::from([(
|
||||
"target_id".to_string(),
|
||||
target_id.to_string(),
|
||||
)])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -132,9 +131,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_COMPILED_SCHEMA".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
("index".to_string(), idx.to_string()),
|
||||
])),
|
||||
values: Some(IndexMap::from([("index".to_string(), idx.to_string())])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -144,14 +141,12 @@ impl<'a> ValidationContext<'a> {
|
||||
}
|
||||
} else {
|
||||
let values = if let Some(d) = self.schema.compiled_discriminator.get() {
|
||||
Some(HashMap::from([
|
||||
Some(IndexMap::from([
|
||||
("discriminator".to_string(), d.to_string()),
|
||||
("value".to_string(), val.to_string()),
|
||||
]))
|
||||
} else {
|
||||
Some(HashMap::from([
|
||||
("primitive".to_string(), val.to_string()),
|
||||
]))
|
||||
Some(IndexMap::from([("primitive".to_string(), val.to_string())]))
|
||||
};
|
||||
result.errors.push(ValidationError {
|
||||
code: if self.schema.family.is_some() {
|
||||
@ -168,9 +163,10 @@ impl<'a> ValidationContext<'a> {
|
||||
if let Some(d) = self.schema.compiled_discriminator.get() {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_TYPE".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
("discriminator".to_string(), d.to_string()),
|
||||
])),
|
||||
values: Some(IndexMap::from([(
|
||||
"discriminator".to_string(),
|
||||
d.to_string(),
|
||||
)])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
@ -17,7 +17,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MIN_LENGTH_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), s.chars().count().to_string()),
|
||||
("limit".to_string(), min.to_string()),
|
||||
])),
|
||||
@ -29,7 +29,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAX_LENGTH_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("count".to_string(), s.chars().count().to_string()),
|
||||
("limit".to_string(), max.to_string()),
|
||||
])),
|
||||
@ -40,7 +40,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !compiled_re.0.is_match(s) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "PATTERN_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pattern".to_string(), self.schema.pattern.clone().unwrap_or_default()),
|
||||
("value".to_string(), s.to_string()),
|
||||
])),
|
||||
@ -53,7 +53,7 @@ impl<'a> ValidationContext<'a> {
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "PATTERN_VIOLATED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pattern".to_string(), pattern.to_string()),
|
||||
("value".to_string(), s.to_string()),
|
||||
])),
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::database::object::{is_primitive_type, SchemaTypeOrArray};
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
use crate::validator::result::ValidationResult;
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
impl<'a> ValidationContext<'a> {
|
||||
pub(crate) fn validate_type(
|
||||
@ -76,7 +76,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if !resolved {
|
||||
result.errors.push(ValidationError {
|
||||
code: "DYNAMIC_TYPE_RESOLUTION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pointer".to_string(), t.clone()),
|
||||
("discriminator".to_string(), var_name.to_string()),
|
||||
])),
|
||||
@ -109,7 +109,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if t.starts_with('$') {
|
||||
result.errors.push(ValidationError {
|
||||
code: "DYNAMIC_TYPE_RESOLUTION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pointer".to_string(), target_id.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
@ -117,7 +117,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else if self.schema.is_proxy() {
|
||||
result.errors.push(ValidationError {
|
||||
code: "PROXY_TYPE_RESOLUTION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pointer".to_string(), target_id.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
@ -125,7 +125,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "INHERITANCE_RESOLUTION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("pointer".to_string(), target_id.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user