Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e362f2168 | |||
| 9fffc7707f | |||
| c5d652c6fd | |||
| d2cdd680ed | |||
| 6f1c0d7ee9 | |||
| 25bbf2b564 | |||
| c8cc4cbde8 | |||
| 5af2399e3b | |||
| 1d56bae9a5 | |||
| 813e9ff3c2 | |||
| 7e28eb2645 | |||
| 5133283795 | |||
| d41209e7c1 | |||
| 03c60f5156 | |||
| 1dfd53e53c | |||
| 532bd8da43 | |||
| 271828ebe9 | |||
| 8c430d42e3 | |||
| 4cc5245336 | |||
| c71e99527d | |||
| 843891f67e | |||
| 8bb7085f76 | |||
| ea03584bbd | |||
| 3736c9d8f0 | |||
| ccca9129b2 | |||
| 333fc69735 | |||
| b0fc6c12ef | |||
| 0d14162ef4 | |||
| b755bc6dbd | |||
| 56775c8c1b | |||
| a32cb3a4da | |||
| 9cefc225fc |
@ -16,7 +16,7 @@ url = "2.5.8"
|
||||
fluent-uri = "0.3.2"
|
||||
idna = "1.1.0"
|
||||
percent-encoding = "2.3.2"
|
||||
uuid = { version = "1.20.0", features = ["v4", "serde"] }
|
||||
uuid = { version = "1.20.0", features = ["v7", "serde"] }
|
||||
chrono = { version = "0.4.43", features = ["serde"] }
|
||||
json-pointer = "0.3.4"
|
||||
indexmap = { version = "2.13.0", features = ["serde"] }
|
||||
|
||||
34
GEMINI.md
34
GEMINI.md
@ -175,11 +175,42 @@ In the Punc architecture, filters are automatically synthesized, strongly-typed
|
||||
|
||||
* **Conditions**: A condition schema is the contract defining the mathematical operations allowed on a primitive field. For example, a `string.condition` allows `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`, `$of` (IN), and `$nof` (NOT IN).
|
||||
* **Enum Conditions**: When JSPG synthesizes an enum, it dynamically generates an `<enum>.condition` (e.g., `address_kind.condition`). This strongly-typed condition perfectly mirrors the operations of a `string.condition`, but strictly limits the arrays and inputs of `$eq`, `$ne`, `$of`, and `$nof` to the exact variations defined by that Enum. This context ensures that UI generators know exactly when to render `<Select>` dropdowns instead of generic `<Text>` boxes.
|
||||
* **Pre-compiled Condition and Filter Mapping**: To prevent redundant double-wrapping of search structures, any schema property whose type is already a `.condition` or `.filter` type (such as `"string.condition"` or `"$kind.filter"`) maps directly to itself during filter synthesis rather than receiving a redundant `.filter` suffix.
|
||||
* **Filters**: A filter schema (e.g., `person.filter`) is an object containing condition properties used to filter entities. It natively supports structural composition:
|
||||
* **Inherited Properties**: Filters automatically inherit all valid database columns from their base type schema, immediately converting them to their respective `.condition` schemas.
|
||||
* **Relational Proxies**: If a table has a foreign key to another table, the filter automatically generates a proxy property pointing to the related entity's filter (e.g., the `person` filter automatically gains an `organization` property that points to `organization.filter`), allowing infinitely deep nested queries natively.
|
||||
* **Logical Operators (`$and`, `$or`)**: Every filter automatically includes `$and` and `$or` arrays, which recursively accept the exact same filter schema, allowing complex logical grouping.
|
||||
* **Ad-Hoc Extensions (`ad_hoc`)**: Fields stored purely in JSONB bubbles that lack formal database columns can still be queried using the `ad_hoc` object, which passes standard, unvalidated string conditions.
|
||||
* Ad-Hoc Extensions (`ad_hoc`)**: Fields stored purely in JSONB bubbles that lack formal database columns can still be queried using the `ad_hoc` object, which passes standard, unvalidated string conditions.
|
||||
|
||||
### Trait-Based Schema Composition (`traits` & `include`)
|
||||
Traits are reusable, non-generating schema fragments used to share properties and relationships horizontally across multiple schemas. They do not generate separate Go/Dart classes.
|
||||
|
||||
* **Traits Namespace**: Defined in a sibling `"traits"` block next to `"schemas"` inside table comments:
|
||||
```json
|
||||
"traits": {
|
||||
"emailable": {
|
||||
"properties": {
|
||||
"email_addresses": {
|
||||
"type": "array",
|
||||
"items": { "type": "contact", "properties": { "target": { "type": "email_address" } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
* **Include Keyword**: Schemas or traits can use the `"include"` array to compose traits or other schemas:
|
||||
```json
|
||||
"full.person": {
|
||||
"type": "person",
|
||||
"include": ["contactable", "owner"]
|
||||
}
|
||||
```
|
||||
* **Resolution and Merging**: During `Database::new()`, includes are resolved and merged at the raw JSON level:
|
||||
* **`properties` / `patternProperties`**: Map keys from the host schema override/shadow included traits.
|
||||
* **`required` / `display`**: Lists are merged and deduped.
|
||||
* **`dependencies`**: Merged by combining and deduping lists.
|
||||
* **Scalars / Arrays / Items**: Host definitions completely override included traits.
|
||||
* The `"include"` keyword is stripped, and `"traits"` maps are omitted from serialization.
|
||||
|
||||
---
|
||||
|
||||
@ -265,6 +296,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.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -791,8 +791,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"invoice",
|
||||
"entity"
|
||||
"entity",
|
||||
"invoice"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -867,8 +867,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"invoice_line",
|
||||
"entity"
|
||||
"entity",
|
||||
"invoice_line"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@ -70,6 +70,10 @@
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@ -181,6 +185,17 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"uuid.condition": {
|
||||
"type": "condition",
|
||||
"properties": {
|
||||
"$eq": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,6 +259,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -258,6 +274,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -278,6 +295,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -325,6 +343,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": [
|
||||
"uuid.condition",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"first_name": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
@ -396,6 +420,7 @@
|
||||
"string.condition": {},
|
||||
"integer.condition": {},
|
||||
"date.condition": {},
|
||||
"uuid.condition": {},
|
||||
"search": {},
|
||||
"search.filter": {
|
||||
"type": "filter",
|
||||
@ -441,7 +466,7 @@
|
||||
},
|
||||
"filter": {
|
||||
"type": [
|
||||
"$kind.filter.filter",
|
||||
"$kind.filter",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
|
||||
@ -110,8 +110,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"activity",
|
||||
"entity"
|
||||
"entity",
|
||||
"activity"
|
||||
],
|
||||
"variations": [
|
||||
"activity",
|
||||
@ -166,9 +166,9 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"invoice",
|
||||
"entity",
|
||||
"activity",
|
||||
"entity"
|
||||
"invoice"
|
||||
],
|
||||
"variations": [
|
||||
"invoice"
|
||||
@ -237,8 +237,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"attachment",
|
||||
"entity"
|
||||
"entity",
|
||||
"attachment"
|
||||
],
|
||||
"variations": [
|
||||
"attachment"
|
||||
|
||||
@ -219,8 +219,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"organization",
|
||||
"entity"
|
||||
"entity",
|
||||
"organization"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -262,9 +262,9 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"user",
|
||||
"entity",
|
||||
"organization",
|
||||
"entity"
|
||||
"user"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -359,10 +359,10 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"person",
|
||||
"user",
|
||||
"entity",
|
||||
"organization",
|
||||
"entity"
|
||||
"user",
|
||||
"person"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -445,8 +445,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"order",
|
||||
"entity"
|
||||
"entity",
|
||||
"order"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -504,8 +504,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"order_line",
|
||||
"entity"
|
||||
"entity",
|
||||
"order_line"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -548,8 +548,8 @@
|
||||
"name": "relationship",
|
||||
"relationship": true,
|
||||
"hierarchy": [
|
||||
"relationship",
|
||||
"entity"
|
||||
"entity",
|
||||
"relationship"
|
||||
],
|
||||
"fields": [
|
||||
"source_id",
|
||||
@ -611,9 +611,9 @@
|
||||
"name": "contact",
|
||||
"relationship": true,
|
||||
"hierarchy": [
|
||||
"contact",
|
||||
"entity",
|
||||
"relationship",
|
||||
"entity"
|
||||
"contact"
|
||||
],
|
||||
"fields": [
|
||||
"is_primary",
|
||||
@ -683,8 +683,8 @@
|
||||
{
|
||||
"name": "phone_number",
|
||||
"hierarchy": [
|
||||
"phone_number",
|
||||
"entity"
|
||||
"entity",
|
||||
"phone_number"
|
||||
],
|
||||
"fields": [
|
||||
"number",
|
||||
@ -741,8 +741,8 @@
|
||||
{
|
||||
"name": "email_address",
|
||||
"hierarchy": [
|
||||
"email_address",
|
||||
"entity"
|
||||
"entity",
|
||||
"email_address"
|
||||
],
|
||||
"fields": [
|
||||
"address",
|
||||
@ -834,8 +834,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"attachment",
|
||||
"entity"
|
||||
"entity",
|
||||
"attachment"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -887,8 +887,8 @@
|
||||
{
|
||||
"name": "account",
|
||||
"hierarchy": [
|
||||
"account",
|
||||
"entity"
|
||||
"entity",
|
||||
"account"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -1031,8 +1031,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"invoice",
|
||||
"entity"
|
||||
"entity",
|
||||
"invoice"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -1107,8 +1107,8 @@
|
||||
}
|
||||
},
|
||||
"hierarchy": [
|
||||
"invoice_line",
|
||||
"entity"
|
||||
"entity",
|
||||
"invoice_line"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
@ -1260,6 +1260,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"IncompleteFirst\",",
|
||||
" \"last_name\": \"IncompleteLast\",",
|
||||
@ -1308,10 +1309,10 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" (\"first_name\" = 'LookupFirst'",
|
||||
" AND \"last_name\" = 'LookupLast'",
|
||||
@ -1319,17 +1320,62 @@
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" contact_id = 'abc-contact'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
" \"created_at\",",
|
||||
" \"created_by\",",
|
||||
" \"id\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
" \"contact_id\",",
|
||||
" \"date_of_birth\",",
|
||||
" \"first_name\",",
|
||||
" \"id\",",
|
||||
" \"last_name\",",
|
||||
" \"pronouns\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'abc-contact',",
|
||||
" '{{timestamp}}',",
|
||||
" 'LookupFirst',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1342,39 +1388,45 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"id\": \"{{uuid:generated_0}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -1410,10 +1462,10 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
" OR (\"first_name\" = 'LookupFirst'",
|
||||
@ -1422,17 +1474,62 @@
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" contact_id = 'abc-contact'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
" \"created_at\",",
|
||||
" \"created_by\",",
|
||||
" \"id\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
" \"contact_id\",",
|
||||
" \"date_of_birth\",",
|
||||
" \"first_name\",",
|
||||
" \"id\",",
|
||||
" \"last_name\",",
|
||||
" \"pronouns\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'abc-contact',",
|
||||
" '{{timestamp}}',",
|
||||
" 'LookupFirst',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1445,41 +1542,46 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" }',",
|
||||
" '{",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"id\": \"{{uuid:data.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"abc-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"contact_id\": \"old-contact\"",
|
||||
" },",
|
||||
" \"replaces\": \"{{uuid:data.id}}\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1513,10 +1615,10 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
" OR (\"first_name\" = 'LookupFirst'",
|
||||
@ -1525,22 +1627,109 @@
|
||||
" AND \"pronouns\" = 'they/them'))"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
" \"created_at\",",
|
||||
" \"created_by\",",
|
||||
" \"id\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
" \"date_of_birth\",",
|
||||
" \"first_name\",",
|
||||
" \"id\",",
|
||||
" \"last_name\",",
|
||||
" \"pronouns\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{timestamp}}',",
|
||||
" 'LookupFirst',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
" \"old\",",
|
||||
" \"new\",",
|
||||
" \"entity_id\",",
|
||||
" \"id\",",
|
||||
" \"kind\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"contact_id\": \"old-contact\",",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" '{{uuid:data.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"id\": \"{{uuid:data.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"first_name\": \"LookupFirst\",",
|
||||
" \"last_name\": \"LookupLast\",",
|
||||
" \"date_of_birth\": \"{{timestamp}}\",",
|
||||
" \"pronouns\": \"they/them\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"replaces\": \"{{uuid:data.id}}\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
]
|
||||
@ -1569,26 +1758,64 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:mocks.0.id}}')"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"person\" SET",
|
||||
" first_name = 'NewFirst',",
|
||||
" last_name = 'NewLast'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
" \"created_at\",",
|
||||
" \"created_by\",",
|
||||
" \"id\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = '{{uuid:mocks.0.id}}'"
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
" \"first_name\",",
|
||||
" \"id\",",
|
||||
" \"last_name\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'NewFirst',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'NewLast',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1601,10 +1828,7 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
" \"first_name\": \"OldFirst\",",
|
||||
" \"last_name\": \"OldLast\"",
|
||||
" }',",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
@ -1612,18 +1836,21 @@
|
||||
" }',",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'update',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"id\": \"{{uuid:mocks.0.id}}\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
@ -1631,10 +1858,6 @@
|
||||
" \"first_name\": \"NewFirst\",",
|
||||
" \"last_name\": \"NewLast\",",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"first_name\": \"OldFirst\",",
|
||||
" \"last_name\": \"OldLast\"",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -1658,10 +1881,10 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '123')"
|
||||
],
|
||||
@ -1749,6 +1972,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"John\",",
|
||||
" \"last_name\": \"Doe\",",
|
||||
@ -1930,6 +2154,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"total\": 100.0,",
|
||||
" \"id\": \"{{uuid:generated_3}}\",",
|
||||
@ -1949,6 +2174,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"Bob\",",
|
||||
" \"last_name\": \"Smith\",",
|
||||
@ -1994,8 +2220,8 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"order\" t1",
|
||||
"JOIN agreego.\"entity\" t2 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"order\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = 'abc'",
|
||||
" OR (\"id\" = 'abc'))"
|
||||
@ -2114,6 +2340,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"total\": 99.0,",
|
||||
" \"id\": \"abc\",",
|
||||
@ -2131,6 +2358,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"product\": \"Widget\",",
|
||||
" \"price\": 99.0,",
|
||||
@ -2619,6 +2847,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"Relation\",",
|
||||
" \"last_name\": \"Test\",",
|
||||
@ -2638,6 +2867,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"is_primary\": true,",
|
||||
" \"source_id\": \"{{uuid:generated_0}}\",",
|
||||
@ -2663,6 +2893,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"number\": \"555-0001\",",
|
||||
" \"id\": \"{{uuid:generated_1}}\",",
|
||||
@ -2680,6 +2911,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"is_primary\": false,",
|
||||
" \"source_id\": \"{{uuid:generated_0}}\",",
|
||||
@ -2705,6 +2937,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"address\": \"test@example.com\",",
|
||||
" \"id\": \"{{uuid:generated_5}}\",",
|
||||
@ -2722,6 +2955,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"is_primary\": false,",
|
||||
" \"source_id\": \"{{uuid:generated_0}}\",",
|
||||
@ -2747,6 +2981,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"address\": \"test2@example.com\",",
|
||||
" \"id\": \"{{uuid:generated_9}}\",",
|
||||
@ -2788,20 +3023,62 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"FROM agreego.\"person\" t1",
|
||||
"JOIN agreego.\"user\" t2 ON ",
|
||||
"JOIN agreego.\"organization\" t3 ON ",
|
||||
"JOIN agreego.\"entity\" t4 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"organization\" t2 ON ",
|
||||
"JOIN agreego.\"user\" t3 ON ",
|
||||
"JOIN agreego.\"person\" t4 ON ",
|
||||
"WHERE",
|
||||
" t1.id = 'abc-archived')"
|
||||
],
|
||||
[
|
||||
"UPDATE agreego.\"entity\" SET",
|
||||
" archived = true,",
|
||||
" modified_at = '{{timestamp}}',",
|
||||
" modified_by = '00000000-0000-0000-0000-000000000000'",
|
||||
"WHERE",
|
||||
" id = 'abc-archived'"
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
" \"archived\",",
|
||||
" \"created_at\",",
|
||||
" \"created_by\",",
|
||||
" \"id\",",
|
||||
" \"modified_at\",",
|
||||
" \"modified_by\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" true,",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'abc-archived',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
" \"id\",",
|
||||
" \"type\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2814,37 +3091,33 @@
|
||||
" \"modified_by\"",
|
||||
")",
|
||||
"VALUES (",
|
||||
" '{",
|
||||
" \"archived\": false",
|
||||
" }',",
|
||||
" NULL,",
|
||||
" '{",
|
||||
" \"archived\": true,",
|
||||
" \"type\": \"person\"",
|
||||
" }',",
|
||||
" 'abc-archived',",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'delete',",
|
||||
" 'create',",
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000'",
|
||||
")"
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"archived\": true,",
|
||||
" \"id\": \"abc-archived\",",
|
||||
" \"type\": \"person\",",
|
||||
" \"first_name\": \"ArchivedFirst\",",
|
||||
" \"last_name\": \"ArchivedLast\",",
|
||||
" \"archived\": true,",
|
||||
" \"created_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"created_at\": \"{{timestamp}}\",",
|
||||
" \"modified_by\": \"00000000-0000-0000-0000-000000000000\",",
|
||||
" \"modified_at\": \"{{timestamp}}\"",
|
||||
" },",
|
||||
" \"new\": {",
|
||||
" \"archived\": true,",
|
||||
" \"type\": \"person\"",
|
||||
" },",
|
||||
" \"old\": {",
|
||||
" \"archived\": false",
|
||||
" }",
|
||||
"}'))"
|
||||
]
|
||||
@ -2943,6 +3216,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"flags\": [",
|
||||
" \"urgent\",",
|
||||
@ -3058,6 +3332,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"product\": \"Widget\",",
|
||||
" \"price\": 99.0,",
|
||||
@ -3101,8 +3376,8 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"order_line\" t1",
|
||||
"JOIN agreego.\"entity\" t2 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"order_line\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.lines.0.id}}')"
|
||||
],
|
||||
@ -3167,6 +3442,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"product\": \"Widget\",",
|
||||
" \"price\": 99.0,",
|
||||
@ -3224,8 +3500,8 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"invoice\" t1",
|
||||
"JOIN agreego.\"entity\" t2 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"invoice\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
" OR (\"id\" = '{{uuid:data.id}}'))"
|
||||
@ -3341,8 +3617,8 @@
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"FROM agreego.\"account\" t1",
|
||||
"JOIN agreego.\"entity\" t2 ON ",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"JOIN agreego.\"account\" t2 ON ",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}')"
|
||||
],
|
||||
@ -3404,6 +3680,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"kind\": \"checking\",",
|
||||
" \"routing_number\": \"123456789\",",
|
||||
@ -3698,6 +3975,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"organization_id\": \"parent-org-id\",",
|
||||
" \"id\": \"{{uuid:generated_3}}\",",
|
||||
@ -3717,6 +3995,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"first_name\": \"Const\",",
|
||||
" \"last_name\": \"Person\",",
|
||||
@ -3738,6 +4017,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"order_id\": \"{{uuid:generated_3}}\",",
|
||||
" \"id\": \"{{uuid:generated_4}}\",",
|
||||
@ -3757,6 +4037,7 @@
|
||||
],
|
||||
[
|
||||
"(SELECT pg_notify('entity', '{",
|
||||
" \"kind\": \"create\",",
|
||||
" \"complete\": {",
|
||||
" \"organization_id\": \"explicit-org-id\",",
|
||||
" \"order_id\": \"{{uuid:generated_3}}\",",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
191
fixtures/traits.json
Normal file
191
fixtures/traits.json
Normal file
@ -0,0 +1,191 @@
|
||||
[
|
||||
{
|
||||
"description": "Granular trait composition and list merging",
|
||||
"database": {
|
||||
"types": [
|
||||
{
|
||||
"name": "person",
|
||||
"schemas": {
|
||||
"full.person": {
|
||||
"type": "object",
|
||||
"include": ["emailable", "phonable"],
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
},
|
||||
"required": ["name"]
|
||||
}
|
||||
},
|
||||
"traits": {
|
||||
"emailable": {
|
||||
"properties": {
|
||||
"email": { "type": "string" }
|
||||
},
|
||||
"required": ["email"],
|
||||
"display": ["email"]
|
||||
},
|
||||
"phonable": {
|
||||
"properties": {
|
||||
"phone": { "type": "string" }
|
||||
},
|
||||
"required": ["phone"],
|
||||
"display": ["phone"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "valid person with name, email, and phone passes",
|
||||
"schema_id": "full.person",
|
||||
"action": "validate",
|
||||
"data": {
|
||||
"name": "Jane Doe",
|
||||
"email": "jane@example.com",
|
||||
"phone": "555-1234"
|
||||
},
|
||||
"expect": {
|
||||
"success": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "missing email fails validation",
|
||||
"schema_id": "full.person",
|
||||
"action": "validate",
|
||||
"data": {
|
||||
"name": "Jane Doe",
|
||||
"phone": "555-1234"
|
||||
},
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "REQUIRED_FIELD_MISSING",
|
||||
"details": {
|
||||
"path": "email"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Local property shadowing",
|
||||
"database": {
|
||||
"types": [
|
||||
{
|
||||
"name": "person",
|
||||
"schemas": {
|
||||
"full.person": {
|
||||
"type": "object",
|
||||
"include": ["emailable"],
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"maxLength": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"traits": {
|
||||
"emailable": {
|
||||
"properties": {
|
||||
"email": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "local maxLength overrides trait properties",
|
||||
"schema_id": "full.person",
|
||||
"action": "validate",
|
||||
"data": {
|
||||
"email": "longerthanfive@example.com"
|
||||
},
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "MAX_LENGTH_VIOLATED",
|
||||
"details": {
|
||||
"path": "email"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Missing trait compiler error",
|
||||
"database": {
|
||||
"types": [
|
||||
{
|
||||
"name": "person",
|
||||
"schemas": {
|
||||
"full.person": {
|
||||
"type": "object",
|
||||
"include": ["nonexistent_trait"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "emits TRAIT_NOT_FOUND compile error",
|
||||
"action": "compile",
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "TRAIT_NOT_FOUND"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Circular inclusion compiler error",
|
||||
"database": {
|
||||
"types": [
|
||||
{
|
||||
"name": "person",
|
||||
"schemas": {
|
||||
"full.person": {
|
||||
"type": "object",
|
||||
"include": ["trait_a"]
|
||||
}
|
||||
},
|
||||
"traits": {
|
||||
"trait_a": {
|
||||
"include": ["trait_b"]
|
||||
},
|
||||
"trait_b": {
|
||||
"include": ["trait_a"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"description": "emits CIRCULAR_INCLUDE_DETECTED compile error",
|
||||
"action": "compile",
|
||||
"expect": {
|
||||
"success": false,
|
||||
"errors": [
|
||||
{
|
||||
"code": "CIRCULAR_INCLUDE_DETECTED"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
12
src/database/action.rs
Normal file
12
src/database/action.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Action {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub punc: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub navigate: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub launch: Option<String>,
|
||||
}
|
||||
@ -141,6 +141,8 @@ impl Schema {
|
||||
if let Some(fmt) = &schema.obj.format {
|
||||
if fmt == "date-time" {
|
||||
return Some(vec!["date.condition".to_string()]);
|
||||
} else if fmt == "uuid" {
|
||||
return Some(vec!["uuid.condition".to_string()]);
|
||||
}
|
||||
}
|
||||
Some(vec!["string.condition".to_string()])
|
||||
@ -157,7 +159,9 @@ impl Schema {
|
||||
},
|
||||
"null" => None,
|
||||
custom => {
|
||||
if db.enums.contains_key(custom) {
|
||||
if custom.ends_with(".condition") || custom.ends_with(".filter") {
|
||||
Some(vec![custom.to_string()])
|
||||
} else if db.enums.contains_key(custom) {
|
||||
Some(vec![format!("{}.condition", custom)])
|
||||
} else {
|
||||
// Assume anything else is a Relational cross-boundary that already has its own .filter dynamically built
|
||||
|
||||
419
src/database/compose/mod.rs
Normal file
419
src/database/compose/mod.rs
Normal file
@ -0,0 +1,419 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub fn compose(val: &mut Value, errors: &mut Vec<crate::drop::Error>) -> Result<(), String> {
|
||||
let mut traits = HashMap::new();
|
||||
let mut schemas = HashMap::new();
|
||||
|
||||
// 1. Gather all traits and schemas from enums, types, and puncs arrays
|
||||
let arrays = ["enums", "types", "puncs"];
|
||||
for arr_name in &arrays {
|
||||
if let Some(arr) = val.get(arr_name).and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
if let Some(item_traits) = item.get("traits").and_then(|v| v.as_object()) {
|
||||
for (name, trait_val) in item_traits {
|
||||
traits.insert(name.clone(), trait_val.clone());
|
||||
}
|
||||
}
|
||||
if let Some(item_schemas) = item.get("schemas").and_then(|v| v.as_object()) {
|
||||
for (name, schema_val) in item_schemas {
|
||||
schemas.insert(name.clone(), schema_val.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Resolve inclusions recursively in all schema objects
|
||||
for arr_name in &arrays {
|
||||
if let Some(arr) = val.get_mut(arr_name).and_then(|v| v.as_array_mut()) {
|
||||
for item in arr {
|
||||
if let Some(item_schemas) = item.get_mut("schemas").and_then(|v| v.as_object_mut()) {
|
||||
for (schema_id, schema_val) in item_schemas {
|
||||
let mut visited = HashSet::new();
|
||||
resolve_in_place(
|
||||
schema_val,
|
||||
&traits,
|
||||
&schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
schema_id,
|
||||
&mut visited,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Strip the "traits" block from each item in enums, types, puncs so it doesn't serialize
|
||||
for arr_name in &arrays {
|
||||
if let Some(arr) = val.get_mut(arr_name).and_then(|v| v.as_array_mut()) {
|
||||
for item in arr {
|
||||
if let Some(obj) = item.as_object_mut() {
|
||||
obj.remove("traits");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolve_in_place(
|
||||
current: &mut Value,
|
||||
traits: &HashMap<String, Value>,
|
||||
schemas: &HashMap<String, Value>,
|
||||
errors: &mut Vec<crate::drop::Error>,
|
||||
schema_id: &str,
|
||||
path: &str,
|
||||
visited: &mut HashSet<String>,
|
||||
) {
|
||||
if !current.is_object() {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
let mut merged_required = HashSet::new();
|
||||
let mut merged_display = HashSet::new();
|
||||
let mut merged_dependencies = serde_json::Map::new();
|
||||
let mut merged_pattern_props = serde_json::Map::new();
|
||||
|
||||
// Read current values first to let host override included properties
|
||||
if let Some(req) = current.get("required").and_then(|v| v.as_array()) {
|
||||
for r in req {
|
||||
if let Some(s) = r.as_str() {
|
||||
merged_required.insert(s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(disp) = current.get("display").and_then(|v| v.as_array()) {
|
||||
for d in disp {
|
||||
if let Some(s) = d.as_str() {
|
||||
merged_display.insert(s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(deps) = current.get("dependencies").and_then(|v| v.as_object()) {
|
||||
for (k, v) in deps {
|
||||
merged_dependencies.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
if let Some(pat_props) = current.get("patternProperties").and_then(|v| v.as_object()) {
|
||||
for (k, v) in pat_props {
|
||||
merged_pattern_props.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
if let Some(props) = current.get("properties").and_then(|v| v.as_object()) {
|
||||
for (k, v) in props {
|
||||
merged_props.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for inc in include_arr {
|
||||
if let Some(inc_name) = inc.as_str() {
|
||||
if visited.contains(inc_name) {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "CIRCULAR_INCLUDE_DETECTED".to_string(),
|
||||
message: format!("Circular inclusion detected for '{}'", inc_name),
|
||||
details: crate::drop::ErrorDetails {
|
||||
schema: Some(schema_id.to_string()),
|
||||
path: Some(path.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
let target_opt = traits.get(inc_name).or_else(|| schemas.get(inc_name));
|
||||
if let Some(target_val) = target_opt {
|
||||
let mut resolved_target = target_val.clone();
|
||||
visited.insert(inc_name.to_string());
|
||||
resolve_in_place(
|
||||
&mut resolved_target,
|
||||
traits,
|
||||
schemas,
|
||||
errors,
|
||||
schema_id,
|
||||
&format!("{}/include/{}", path, inc_name),
|
||||
visited,
|
||||
);
|
||||
visited.remove(inc_name);
|
||||
|
||||
// Merge properties (host overrides trait)
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge patternProperties (host overrides trait)
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge required
|
||||
if let Some(target_req) = resolved_target.get("required").and_then(|v| v.as_array()) {
|
||||
for r in target_req {
|
||||
if let Some(s) = r.as_str() {
|
||||
merged_required.insert(s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge display
|
||||
if let Some(target_disp) = resolved_target.get("display").and_then(|v| v.as_array()) {
|
||||
for d in target_disp {
|
||||
if let Some(s) = d.as_str() {
|
||||
merged_display.insert(s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge dependencies
|
||||
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();
|
||||
for x in arr_target {
|
||||
if let Some(s) = x.as_str() {
|
||||
if set.insert(s.to_string()) {
|
||||
arr_existing.push(Value::String(s.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
merged_dependencies.insert(dep_prop.clone(), dep_val.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 !obj.contains_key(k) {
|
||||
obj.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "TRAIT_NOT_FOUND".to_string(),
|
||||
message: format!("Trait or schema '{}' not found for inclusion", inc_name),
|
||||
details: crate::drop::ErrorDetails {
|
||||
schema: Some(schema_id.to_string()),
|
||||
path: Some(path.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(obj) = current.as_object_mut() {
|
||||
if !merged_props.is_empty() {
|
||||
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),
|
||||
);
|
||||
}
|
||||
if !merged_required.is_empty() {
|
||||
let mut req_vec: Vec<Value> = merged_required.into_iter().map(Value::String).collect();
|
||||
req_vec.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap()));
|
||||
obj.insert("required".to_string(), Value::Array(req_vec));
|
||||
}
|
||||
if !merged_display.is_empty() {
|
||||
let mut disp_vec: Vec<Value> = merged_display.into_iter().map(Value::String).collect();
|
||||
disp_vec.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap()));
|
||||
obj.insert("display".to_string(), Value::Array(disp_vec));
|
||||
}
|
||||
if !merged_dependencies.is_empty() {
|
||||
obj.insert(
|
||||
"dependencies".to_string(),
|
||||
Value::Object(merged_dependencies),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively process children
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(items) = obj.get_mut("items") {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(additional_props) = obj.get_mut("additionalProperties") {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(contains) = obj.get_mut("contains") {
|
||||
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,
|
||||
);
|
||||
}
|
||||
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,
|
||||
);
|
||||
}
|
||||
if let Some(then) = c_obj.get_mut("then") {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
pub mod action;
|
||||
pub mod compile;
|
||||
pub mod compose;
|
||||
pub mod edge;
|
||||
pub mod r#enum;
|
||||
pub mod executors;
|
||||
@ -40,7 +42,7 @@ pub struct Database {
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new(val: &serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
pub fn new(mut val: serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
let mut db = Self {
|
||||
enums: IndexMap::new(),
|
||||
types: IndexMap::new(),
|
||||
@ -55,101 +57,115 @@ impl Database {
|
||||
|
||||
let mut errors = Vec::new();
|
||||
|
||||
if let Some(arr) = val.get("enums").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Enum>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.enums.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_ENUM_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database enum '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Err(e) = compose::compose(&mut val, &mut errors) {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "COMPOSE_FAILED".to_string(),
|
||||
message: format!("Fatal error during trait composition: {}", e),
|
||||
details: crate::drop::ErrorDetails::default(),
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("types").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Type>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.types.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_TYPE_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database type '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("relations").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Relation>(item.clone()) {
|
||||
Ok(def) => {
|
||||
if db.types.contains_key(&def.source_type)
|
||||
&& db.types.contains_key(&def.destination_type)
|
||||
{
|
||||
db.relations.insert(def.constraint.clone(), def);
|
||||
if let serde_json::Value::Object(mut map) = val {
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("enums") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Enum>(item) {
|
||||
Ok(def) => {
|
||||
db.enums.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_ENUM_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database enum '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let constraint = item
|
||||
.get("constraint")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_RELATION_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database relation '{}': {}", constraint, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(constraint)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("types") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Type>(item) {
|
||||
Ok(def) => {
|
||||
db.types.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_TYPE_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database type '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(arr) = val.get("puncs").and_then(|v| v.as_array()) {
|
||||
for item in arr {
|
||||
match serde_json::from_value::<Punc>(item.clone()) {
|
||||
Ok(def) => {
|
||||
db.puncs.insert(def.name.clone(), def);
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("relations") {
|
||||
for item in arr {
|
||||
let constraint = item
|
||||
.get("constraint")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Relation>(item) {
|
||||
Ok(def) => {
|
||||
if db.types.contains_key(&def.source_type)
|
||||
&& db.types.contains_key(&def.destination_type)
|
||||
{
|
||||
db.relations.insert(def.constraint.clone(), def);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_RELATION_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database relation '{}': {}", constraint, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(constraint)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_PUNC_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database punc '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(serde_json::Value::Array(arr)) = map.remove("puncs") {
|
||||
for item in arr {
|
||||
let name = item
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
match serde_json::from_value::<Punc>(item) {
|
||||
Ok(def) => {
|
||||
db.puncs.insert(def.name.clone(), def);
|
||||
}
|
||||
Err(e) => {
|
||||
errors.push(crate::drop::Error {
|
||||
code: "DATABASE_PUNC_PARSE_FAILED".to_string(),
|
||||
message: format!("Failed to parse database punc '{}': {}", name, e),
|
||||
details: crate::drop::ErrorDetails {
|
||||
context: Some(serde_json::json!(name)),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,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);
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
use crate::database::action::Action;
|
||||
use crate::database::schema::Schema;
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
@ -219,14 +220,6 @@ pub enum SchemaTypeOrArray {
|
||||
Multiple(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Action {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub navigate: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub punc: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Dependency {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use crate::database::action::Action;
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -22,14 +23,3 @@ pub struct Sidebar {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub priority: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Action {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub punc: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub navigate: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub present: Option<String>,
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ pub struct Jspg {
|
||||
}
|
||||
|
||||
impl Jspg {
|
||||
pub fn new(database_val: &serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
pub fn new(database_val: serde_json::Value) -> (Self, crate::drop::Drop) {
|
||||
let (database_instance, drop) = Database::new(database_val);
|
||||
let database = Arc::new(database_instance);
|
||||
let validator = Validator::new(database.clone());
|
||||
|
||||
@ -45,7 +45,7 @@ fn jspg_failure() -> JsonB {
|
||||
|
||||
#[cfg_attr(not(test), pg_extern(strict))]
|
||||
pub fn jspg_setup(database: Json) -> Json {
|
||||
let (new_jspg, drop) = crate::jspg::Jspg::new(&database.0);
|
||||
let (new_jspg, drop) = crate::jspg::Jspg::new(database.0);
|
||||
let new_arc = Arc::new(new_jspg);
|
||||
|
||||
// 3. ATOMIC SWAP
|
||||
|
||||
@ -138,7 +138,9 @@ impl Merger {
|
||||
is_child: bool,
|
||||
) -> Result<Value, String> {
|
||||
match data {
|
||||
Value::Array(items) => self.merge_array(schema, items, notifications, parent_org_id, is_child),
|
||||
Value::Array(items) => {
|
||||
self.merge_array(schema, items, notifications, parent_org_id, is_child)
|
||||
}
|
||||
Value::Object(map) => {
|
||||
if let Some(options) = schema.obj.compiled_options.get() {
|
||||
if let Some(disc) = schema.obj.compiled_discriminator.get() {
|
||||
@ -210,7 +212,13 @@ impl Merger {
|
||||
|
||||
let mut resolved_items = Vec::new();
|
||||
for item in items {
|
||||
let resolved = self.merge_internal(item_schema.clone(), item, notifications, parent_org_id.clone(), is_child)?;
|
||||
let resolved = self.merge_internal(
|
||||
item_schema.clone(),
|
||||
item,
|
||||
notifications,
|
||||
parent_org_id.clone(),
|
||||
is_child,
|
||||
)?;
|
||||
resolved_items.push(resolved);
|
||||
}
|
||||
Ok(Value::Array(resolved_items))
|
||||
@ -340,7 +348,10 @@ impl Merger {
|
||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||
let parent_is_source = edge.forward;
|
||||
|
||||
let org_id_to_pass = entity_fields.get("organization_id").and_then(|v| v.as_str()).map(|s| s.to_string());
|
||||
let org_id_to_pass = entity_fields
|
||||
.get("organization_id")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string());
|
||||
if parent_is_source {
|
||||
let mut merged_relative = match self.merge_internal(
|
||||
rel_schema.clone(),
|
||||
@ -443,7 +454,10 @@ impl Merger {
|
||||
}
|
||||
}
|
||||
|
||||
let org_id_to_pass = entity_fields.get("organization_id").and_then(|v| v.as_str()).map(|s| s.to_string());
|
||||
let org_id_to_pass = entity_fields
|
||||
.get("organization_id")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string());
|
||||
let mut relative_responses = Vec::new();
|
||||
for relative_item_val in relative_arr {
|
||||
if let Value::Object(mut relative_item) = relative_item_val {
|
||||
@ -574,7 +588,7 @@ impl Merger {
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
let id_val = if entity_id.is_empty() {
|
||||
Value::String(uuid::Uuid::new_v4().to_string())
|
||||
Value::String(uuid::Uuid::now_v7().to_string())
|
||||
} else {
|
||||
Value::String(entity_id.to_string())
|
||||
};
|
||||
@ -777,13 +791,8 @@ impl Merger {
|
||||
}
|
||||
};
|
||||
|
||||
let mut execute_order: Vec<String> = entity_type.hierarchy.clone();
|
||||
if change_kind == "create" {
|
||||
execute_order.reverse();
|
||||
}
|
||||
|
||||
for table_name in execute_order {
|
||||
let table_fields = match grouped_fields.get(&table_name).and_then(|v| v.as_array()) {
|
||||
for table_name in &entity_type.hierarchy {
|
||||
let table_fields = match grouped_fields.get(table_name).and_then(|v| v.as_array()) {
|
||||
Some(arr) => arr
|
||||
.iter()
|
||||
.filter_map(|v| v.as_str().map(|s| s.to_string()))
|
||||
@ -947,6 +956,7 @@ impl Merger {
|
||||
};
|
||||
|
||||
let mut notification = serde_json::Map::new();
|
||||
notification.insert("kind".to_string(), Value::String(change_kind.to_string()));
|
||||
notification.insert("complete".to_string(), Value::Object(complete));
|
||||
notification.insert("new".to_string(), new_val_obj.clone());
|
||||
|
||||
@ -961,11 +971,11 @@ 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\") 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(uuid::Uuid::now_v7().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()))
|
||||
|
||||
@ -213,6 +213,7 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
let mut case_node = node.clone();
|
||||
case_node.parent_alias = base_alias.clone();
|
||||
case_node.property_name = None;
|
||||
let arc_aliases = std::sync::Arc::new(table_aliases.clone());
|
||||
case_node.parent_type_aliases = Some(arc_aliases);
|
||||
case_node.parent_type = Some(r#type);
|
||||
@ -602,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 = "";
|
||||
@ -620,7 +621,21 @@ impl<'a> Compiler<'a> {
|
||||
.get(table_to_alias)
|
||||
.or_else(|| type_aliases.get(&node.parent_alias))
|
||||
{
|
||||
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"));
|
||||
@ -1499,6 +1511,12 @@ fn test_queryer_0_14() {
|
||||
crate::tests::runner::run_test_case(&path, 0, 14).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_queryer_0_15() {
|
||||
let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 15).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polymorphism_0_0() {
|
||||
let path = format!("{}/fixtures/polymorphism.json", env!("CARGO_MANIFEST_DIR"));
|
||||
@ -2141,6 +2159,36 @@ fn test_items_15_2() {
|
||||
crate::tests::runner::run_test_case(&path, 15, 2).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_traits_0_0() {
|
||||
let path = format!("{}/fixtures/traits.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_traits_0_1() {
|
||||
let path = format!("{}/fixtures/traits.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 1).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_traits_1_0() {
|
||||
let path = format!("{}/fixtures/traits.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 1, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_traits_2_0() {
|
||||
let path = format!("{}/fixtures/traits.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_traits_3_0() {
|
||||
let path = format!("{}/fixtures/traits.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enum_0_0() {
|
||||
let path = format!("{}/fixtures/enum.json", env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
@ -44,7 +44,7 @@ fn test_library_api() {
|
||||
{
|
||||
"name": "source_schema",
|
||||
"variations": ["source_schema"],
|
||||
"hierarchy": ["source_schema", "entity"],
|
||||
"hierarchy": ["entity", "source_schema"],
|
||||
"schemas": {
|
||||
"source_schema": {
|
||||
"type": "object",
|
||||
@ -60,7 +60,7 @@ fn test_library_api() {
|
||||
{
|
||||
"name": "target_schema",
|
||||
"variations": ["target_schema"],
|
||||
"hierarchy": ["target_schema", "entity"],
|
||||
"hierarchy": ["entity", "target_schema"],
|
||||
"schemas": {
|
||||
"target_schema": {
|
||||
"type": "object",
|
||||
@ -109,7 +109,7 @@ fn test_library_api() {
|
||||
"field_types": null,
|
||||
"fields": [],
|
||||
"grouped_fields": null,
|
||||
"hierarchy": ["source_schema", "entity"],
|
||||
"hierarchy": ["entity", "source_schema"],
|
||||
"historical": false,
|
||||
"id": "",
|
||||
"longevity": null,
|
||||
@ -174,7 +174,7 @@ fn test_library_api() {
|
||||
"field_types": null,
|
||||
"fields": [],
|
||||
"grouped_fields": null,
|
||||
"hierarchy": ["target_schema", "entity"],
|
||||
"hierarchy": ["entity", "target_schema"],
|
||||
"historical": false,
|
||||
"id": "",
|
||||
"longevity": null,
|
||||
|
||||
@ -42,7 +42,7 @@ fn get_cached_file(path: &str) -> CompiledSuite {
|
||||
|
||||
let mut compiled_suites = Vec::new();
|
||||
for suite in suites {
|
||||
let (db, drop) = crate::database::Database::new(&suite.database);
|
||||
let (db, drop) = crate::database::Database::new(suite.database.clone());
|
||||
let compiled_db = if drop.errors.is_empty() {
|
||||
Ok(Arc::new(db))
|
||||
} else {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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