Compare commits
20 Commits
lookup_fie
...
1.0.193
| Author | SHA1 | Date | |
|---|---|---|---|
| 3414a32bd6 | |||
| 06432cf0f5 | |||
| 0d4b7c3dec | |||
| b2f9fe387c | |||
| 020286d603 | |||
| 1619ca4400 | |||
| 580fa0bc9f | |||
| 2dfb4e68e4 | |||
| ae31230ef2 | |||
| ce542a31cc | |||
| 75296ab107 | |||
| 1a4b328b45 | |||
| c5e103c867 | |||
| a1b7bd4277 | |||
| 27db5109d4 | |||
| c071a959f7 | |||
| 8b672bd94b | |||
| 441b7e7455 | |||
| fbeb2eee22 | |||
| 350fe29fef |
22
GEMINI.md
22
GEMINI.md
@ -184,6 +184,24 @@ It evaluates as an **Independent Declarative Rules Engine**. Every `Case` block
|
|||||||
* **`array`**: Homogeneous collection of items matching the `items` schema. Validation is homogeneous, so strictness checking does not apply. `"extensible"` is not applicable at the `array` level (tuple-like `prefixItems` are removed).
|
* **`array`**: Homogeneous collection of items matching the `items` schema. Validation is homogeneous, so strictness checking does not apply. `"extensible"` is not applicable at the `array` level (tuple-like `prefixItems` are removed).
|
||||||
* **Inheritance Boundaries**: Strictness resets when crossing non-primitive `type` boundaries. A schema extending a strict parent remains strict unless it explicitly overrides with `"extensible": true`.
|
* **Inheritance Boundaries**: Strictness resets when crossing non-primitive `type` boundaries. A schema extending a strict parent remains strict unless it explicitly overrides with `"extensible": true`.
|
||||||
|
|
||||||
|
### Immutable Properties (`"immutable": true`)
|
||||||
|
To distinguish read-only hydrated endpoint references, computed properties, system-managed timestamps (`created_at`, `modified_at`), or audit fields from writable properties, JSPG introduces the universal `"immutable": true` schema keyword.
|
||||||
|
|
||||||
|
* **Developer Perspective**: Annotate properties in database schemas or trait definitions with `"immutable": true` when the property should be visible on reads (`jspg_query` / `.response`), but rejected or ignored on writes (`jspg_merge` / `.request`).
|
||||||
|
```json
|
||||||
|
"properties": {
|
||||||
|
"source": {
|
||||||
|
"family": "lite.organization",
|
||||||
|
"immutable": true,
|
||||||
|
"description": "Read-only hydrated member entity summary on a membership edge."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* **Behavior Across Pillars**:
|
||||||
|
* **Queryer (`jspg_query`)**: Hydrates and includes `immutable` properties in output read responses without restriction.
|
||||||
|
* **Validator (`jspg_validate`)**: Context-aware. Returns `IMMUTABLE_PROPERTY_VIOLATION` if an `immutable` property is supplied in a write/request payload (schema IDs not ending in `.response`). Response schemas (`.response`) permit `immutable` fields.
|
||||||
|
* **Merger (`jspg_merge`)**: Automatically skips `immutable` properties during object graph merging so client payloads can never mutate database columns or relationship edges.
|
||||||
|
|
||||||
### Format Leniency for Empty Strings
|
### Format Leniency for Empty Strings
|
||||||
To simplify frontend form validation, format validators specifically for `uuid`, `date-time`, and `email` explicitly allow empty strings (`""`), treating them as "present but unset".
|
To simplify frontend form validation, format validators specifically for `uuid`, `date-time`, and `email` explicitly allow empty strings (`""`), treating them as "present but unset".
|
||||||
|
|
||||||
@ -302,6 +320,7 @@ JSPG implements specific extensions to the Draft 2020-12 standard to support the
|
|||||||
* **Missing Type Ultimatum**: If an entity logically requires a discriminator and the JSON payload omits it, JSPG short-circuits branch execution entirely, bubbling a single, perfectly-pathed `MISSING_TYPE` error back to the UI natively to prevent confusing cascading failures.
|
* **Missing Type Ultimatum**: If an entity logically requires a discriminator and the JSON payload omits it, JSPG short-circuits branch execution entirely, bubbling a single, perfectly-pathed `MISSING_TYPE` error back to the UI natively to prevent confusing cascading failures.
|
||||||
* **Golden Match Context**: When exactly one structural candidate perfectly maps a discriminator, the Validator exclusively cascades that specific structural error context directly to the user, stripping away all noise generated by other parallel schemas.
|
* **Golden Match Context**: When exactly one structural candidate perfectly maps a discriminator, the Validator exclusively cascades that specific structural error context directly to the user, stripping away all noise generated by other parallel schemas.
|
||||||
* **Topological Array Pathing**: Instead of relying on explicit `$id` references or injected properties, array iteration paths are dynamically typed based on their compiler boundary constraints. If the array's `items` schema resolves to a topological table-backed entity (e.g., inheriting via a `family` macro tracked in the global DB catalog), the array locks paths and derives element indexes from their actual UUID paths (`array/widget-1/name`), natively enforcing database continuity. If evaluating isolated ad-hoc JSONB elements, strict numeric indexing is enforced natively (`array/1/name`) preventing synthetic payload manipulation.
|
* **Topological Array Pathing**: Instead of relying on explicit `$id` references or injected properties, array iteration paths are dynamically typed based on their compiler boundary constraints. If the array's `items` schema resolves to a topological table-backed entity (e.g., inheriting via a `family` macro tracked in the global DB catalog), the array locks paths and derives element indexes from their actual UUID paths (`array/widget-1/name`), natively enforcing database continuity. If evaluating isolated ad-hoc JSONB elements, strict numeric indexing is enforced natively (`array/1/name`) preventing synthetic payload manipulation.
|
||||||
|
* **Context-Aware Immutability Validation**: `jspg_validate` evaluates the target schema ID context. If the target schema ID does not end with `.response` (inbound write/request context), any property present in the payload marked with `"immutable": true` raises an `IMMUTABLE_PROPERTY_VIOLATION` error. Response schemas (`.response`) permit `immutable` fields for read hydration.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -316,6 +335,9 @@ The Merger provides an automated, high-performance graph synchronization engine.
|
|||||||
|
|
||||||
* **Caching Strategy**: The Merger leverages the native `compiled_edges` permanently cached onto the Schema AST via `OnceLock` to instantly resolve Foreign Key mapping graphs natively in absolute `O(1)` time. It additionally utilizes the concurrent `GLOBAL_JSPG` application memory (`DashMap`) to cache statically constructed SQL `SELECT` strings used during deduplication (`lookup_fields`) and difference tracking calculations.
|
* **Caching Strategy**: The Merger leverages the native `compiled_edges` permanently cached onto the Schema AST via `OnceLock` to instantly resolve Foreign Key mapping graphs natively in absolute `O(1)` time. It additionally utilizes the concurrent `GLOBAL_JSPG` application memory (`DashMap`) to cache statically constructed SQL `SELECT` strings used during deduplication (`lookup_fields`) and difference tracking calculations.
|
||||||
* **Deep Graph Merging**: The Merger walks arbitrary levels of deeply nested JSON schemas (e.g. tracking an `order`, its `customer`, and an array of its `lines`). It intelligently discovers the correct parent-to-child or child-to-parent Foreign Keys stored in the registry and automatically maps the UUIDs across the relationships during UPSERT.
|
* **Deep Graph Merging**: The Merger walks arbitrary levels of deeply nested JSON schemas (e.g. tracking an `order`, its `customer`, and an array of its `lines`). It intelligently discovers the correct parent-to-child or child-to-parent Foreign Keys stored in the registry and automatically maps the UUIDs across the relationships during UPSERT.
|
||||||
|
* **Immutable Property Filtering**: Properties declaring `"immutable": true` are filtered out during schema property traversal prior to edge classification or column assembly, guaranteeing client payloads cannot write or mutate read-only/computed properties or hydrated endpoint references.
|
||||||
|
* **Factual Creation Dependency Validation**: When `stage_entity` confirms `kind == "create"` via database lookup, `jspg_merge` evaluates `schema.obj.dependencies.get("created")`. If required creation fields are missing from `entity_fields`, `entity_objects`, or `entity_arrays`, `jspg_merge` halts and returns a structured `REQUIRED_FIELD_MISSING` `Drop`.
|
||||||
|
* **Structured Fail-Fast Error Propagation**: Internal merger operations return typed `Result<T, crate::drop::Error>` instances, allowing clean fail-fast `?` traversal and returning `Drop::with_errors(vec![err])` directly at the top-level API boundary on failure.
|
||||||
* **Prefix Foreign Key Matching**: Handles scenario where multiple relations point to the same table by using database Foreign Key constraint prefixes (`fk_`). For example, if a schema has `shipping_address` and `billing_address`, the merger resolves against `fk_shipping_address_entity` vs `fk_billing_address_entity` automatically to correctly route object properties.
|
* **Prefix Foreign Key Matching**: Handles scenario where multiple relations point to the same table by using database Foreign Key constraint prefixes (`fk_`). For example, if a schema has `shipping_address` and `billing_address`, the merger resolves against `fk_shipping_address_entity` vs `fk_billing_address_entity` automatically to correctly route object properties.
|
||||||
* **Dynamic Deduplication & Lookups**: If a nested object is provided without an `id`, the Merger utilizes custom `lookup_fields` declared directly in the schema registry JSON comments. It validates at setup compile-time that a corresponding unique index exists in PostgreSQL for these fields. When merging, it dynamically builds query predicates for any satisfied `lookup_fields` sets in the entity's type hierarchy (checking child-to-parent hierarchies order-independently and combining satisfied keys with `UNION` queries) to discover the correct UUID to perform an UPDATE, preventing data duplication.
|
* **Dynamic Deduplication & Lookups**: If a nested object is provided without an `id`, the Merger utilizes custom `lookup_fields` declared directly in the schema registry JSON comments. It validates at setup compile-time that a corresponding unique index exists in PostgreSQL for these fields. When merging, it dynamically builds query predicates for any satisfied `lookup_fields` sets in the entity's type hierarchy (checking child-to-parent hierarchies order-independently and combining satisfied keys with `UNION` queries) to discover the correct UUID to perform an UPDATE, preventing data duplication.
|
||||||
* **Hierarchical Table Inheritance**: The Punc system uses distributed table inheritance (e.g. `person` inherits `user` inherits `organization` inherits `entity`). The Merger splits the incoming JSON payload and performs atomic row updates across *all* relevant tables in the lineage map.
|
* **Hierarchical Table Inheritance**: The Punc system uses distributed table inheritance (e.g. `person` inherits `user` inherits `organization` inherits `entity`). The Merger splits the incoming JSON payload and performs atomic row updates across *all* relevant tables in the lineage map.
|
||||||
|
|||||||
@ -1027,16 +1027,31 @@
|
|||||||
"name": "user",
|
"name": "user",
|
||||||
"module": "test",
|
"module": "test",
|
||||||
"source": "test",
|
"source": "test",
|
||||||
"hierarchy": ["user"],
|
"hierarchy": [
|
||||||
"variations": ["user"],
|
"user"
|
||||||
"fields": ["id", "email"],
|
],
|
||||||
"lookup_fields": ["email"],
|
"variations": [
|
||||||
|
"user"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
"id",
|
||||||
|
"email"
|
||||||
|
],
|
||||||
|
"lookup_fields": [
|
||||||
|
"email"
|
||||||
|
],
|
||||||
"schemas": {
|
"schemas": {
|
||||||
"user": {
|
"user": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": { "type": "string", "format": "uuid" },
|
"id": {
|
||||||
"email": { "type": "string", "format": "email" }
|
"type": "string",
|
||||||
|
"format": "uuid"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "email"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1072,7 +1087,9 @@
|
|||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"table": "user",
|
"table": "user",
|
||||||
"columns": ["email"]
|
"columns": [
|
||||||
|
"email"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
@ -1082,16 +1099,31 @@
|
|||||||
"name": "user",
|
"name": "user",
|
||||||
"module": "test",
|
"module": "test",
|
||||||
"source": "test",
|
"source": "test",
|
||||||
"hierarchy": ["user"],
|
"hierarchy": [
|
||||||
"variations": ["user"],
|
"user"
|
||||||
"fields": ["id", "email"],
|
],
|
||||||
"lookup_fields": ["email"],
|
"variations": [
|
||||||
|
"user"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
"id",
|
||||||
|
"email"
|
||||||
|
],
|
||||||
|
"lookup_fields": [
|
||||||
|
"email"
|
||||||
|
],
|
||||||
"schemas": {
|
"schemas": {
|
||||||
"user": {
|
"user": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": { "type": "string", "format": "uuid" },
|
"id": {
|
||||||
"email": { "type": "string", "format": "email" }
|
"type": "string",
|
||||||
|
"format": "uuid"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "email"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,11 +120,18 @@
|
|||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"table": "person",
|
"table": "person",
|
||||||
"columns": ["first_name", "last_name", "date_of_birth", "pronouns"]
|
"columns": [
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"date_of_birth",
|
||||||
|
"pronouns"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table": "user",
|
"table": "user",
|
||||||
"columns": ["name"]
|
"columns": [
|
||||||
|
"name"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
@ -1206,7 +1213,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1216,7 +1224,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1226,7 +1235,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -1240,7 +1250,8 @@
|
|||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'IncompleteLast',",
|
" 'IncompleteLast',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -1316,7 +1327,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1343,7 +1354,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1353,7 +1365,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1363,7 +1376,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -1383,7 +1397,8 @@
|
|||||||
" 'LookupLast',",
|
" 'LookupLast',",
|
||||||
" 'they/them',",
|
" 'they/them',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -1469,14 +1484,14 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
" t1.id = '{{uuid:data.id}}'",
|
||||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1503,7 +1518,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1513,7 +1529,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1523,7 +1540,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -1543,7 +1561,8 @@
|
|||||||
" 'LookupLast',",
|
" 'LookupLast',",
|
||||||
" 'they/them',",
|
" 'they/them',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -1631,14 +1650,14 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
" t1.id = '{{uuid:data.id}}'",
|
||||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1648,7 +1667,7 @@
|
|||||||
" AND \"last_name\" = 'LookupLast'",
|
" AND \"last_name\" = 'LookupLast'",
|
||||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
" AND \"date_of_birth\" = '{{timestamp}}'",
|
||||||
" AND \"pronouns\" = 'they/them')",
|
" AND \"pronouns\" = 'they/them')",
|
||||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1672,7 +1691,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1684,7 +1704,8 @@
|
|||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'LookupName',",
|
" 'LookupName',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1694,7 +1715,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -1714,7 +1736,8 @@
|
|||||||
" 'LookupLast',",
|
" 'LookupLast',",
|
||||||
" 'they/them',",
|
" 'they/them',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -1802,14 +1825,14 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
" t1.id = '{{uuid:data.id}}'",
|
||||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1836,7 +1859,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1846,7 +1870,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1856,7 +1881,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:data.id}}',",
|
" '{{uuid:data.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -1874,7 +1900,8 @@
|
|||||||
" 'LookupLast',",
|
" 'LookupLast',",
|
||||||
" 'they/them',",
|
" 'they/them',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -1951,7 +1978,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -1975,7 +2002,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -1985,7 +2013,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:mocks.0.id}}',",
|
" '{{uuid:mocks.0.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -1995,7 +2024,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:mocks.0.id}}',",
|
" '{{uuid:mocks.0.id}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -2009,7 +2039,8 @@
|
|||||||
" '{{uuid:mocks.0.id}}',",
|
" '{{uuid:mocks.0.id}}',",
|
||||||
" 'NewLast',",
|
" 'NewLast',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2074,7 +2105,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -2098,7 +2129,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -2108,7 +2140,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '123',",
|
" '123',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -2118,7 +2151,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '123',",
|
" '123',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -2136,7 +2170,8 @@
|
|||||||
" 'Doe',",
|
" 'Doe',",
|
||||||
" NULL,",
|
" NULL,",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2226,7 +2261,8 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" '{{uuid:generated_1}}',",
|
" '{{uuid:generated_1}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -2236,7 +2272,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -2246,7 +2283,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -2262,7 +2300,8 @@
|
|||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'Smith',",
|
" 'Smith',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2306,7 +2345,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order\" (",
|
"INSERT INTO agreego.\"order\" (",
|
||||||
@ -2320,7 +2360,8 @@
|
|||||||
" '{{uuid:generated_3}}',",
|
" '{{uuid:generated_3}}',",
|
||||||
" 100,",
|
" 100,",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2413,7 +2454,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
@ -2435,7 +2476,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order\" (",
|
"INSERT INTO agreego.\"order\" (",
|
||||||
@ -2447,7 +2489,8 @@
|
|||||||
" 'abc',",
|
" 'abc',",
|
||||||
" 99,",
|
" 99,",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -2465,7 +2508,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order_line\" (",
|
"INSERT INTO agreego.\"order_line\" (",
|
||||||
@ -2481,7 +2525,8 @@
|
|||||||
" 99,",
|
" 99,",
|
||||||
" 'Widget',",
|
" 'Widget',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order_line\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2630,7 +2675,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -2640,7 +2686,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -2650,7 +2697,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -2664,7 +2712,8 @@
|
|||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'Test',",
|
" 'Test',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -2682,7 +2731,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'phone_number'",
|
" 'phone_number'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"phone_number\" (",
|
"INSERT INTO agreego.\"phone_number\" (",
|
||||||
@ -2690,7 +2740,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '555-0001'",
|
" '555-0001'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"phone_number\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2731,7 +2782,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'contact'",
|
" 'contact'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"relationship\" (",
|
"INSERT INTO agreego.\"relationship\" (",
|
||||||
@ -2745,7 +2797,8 @@
|
|||||||
" 'person',",
|
" 'person',",
|
||||||
" '{{uuid:generated_1}}',",
|
" '{{uuid:generated_1}}',",
|
||||||
" 'phone_number'",
|
" 'phone_number'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"relationship\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"contact\" (",
|
"INSERT INTO agreego.\"contact\" (",
|
||||||
@ -2753,7 +2806,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" true",
|
" true",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"contact\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2798,7 +2852,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'email_address'",
|
" 'email_address'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"email_address\" (",
|
"INSERT INTO agreego.\"email_address\" (",
|
||||||
@ -2806,7 +2861,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" 'test@example.com'",
|
" 'test@example.com'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"email_address\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2847,7 +2903,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'contact'",
|
" 'contact'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"relationship\" (",
|
"INSERT INTO agreego.\"relationship\" (",
|
||||||
@ -2861,7 +2918,8 @@
|
|||||||
" 'person',",
|
" 'person',",
|
||||||
" '{{uuid:generated_5}}',",
|
" '{{uuid:generated_5}}',",
|
||||||
" 'email_address'",
|
" 'email_address'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"relationship\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"contact\" (",
|
"INSERT INTO agreego.\"contact\" (",
|
||||||
@ -2869,7 +2927,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" false",
|
" false",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"contact\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2914,7 +2973,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'email_address'",
|
" 'email_address'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"email_address\" (",
|
"INSERT INTO agreego.\"email_address\" (",
|
||||||
@ -2922,7 +2982,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" 'test2@example.com'",
|
" 'test2@example.com'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"email_address\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -2963,7 +3024,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'contact'",
|
" 'contact'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"relationship\" (",
|
"INSERT INTO agreego.\"relationship\" (",
|
||||||
@ -2977,7 +3039,8 @@
|
|||||||
" 'person',",
|
" 'person',",
|
||||||
" '{{uuid:generated_9}}',",
|
" '{{uuid:generated_9}}',",
|
||||||
" 'email_address'",
|
" 'email_address'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"relationship\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"contact\" (",
|
"INSERT INTO agreego.\"contact\" (",
|
||||||
@ -2985,7 +3048,8 @@
|
|||||||
")",
|
")",
|
||||||
"VALUES (",
|
"VALUES (",
|
||||||
" false",
|
" false",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"contact\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3215,7 +3279,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||||
@ -3241,7 +3305,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -3251,7 +3316,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" 'abc-archived',",
|
" 'abc-archived',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -3261,7 +3327,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" 'abc-archived',",
|
" 'abc-archived',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -3271,7 +3338,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" 'abc-archived',",
|
" 'abc-archived',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3353,7 +3421,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'attachment'",
|
" 'attachment'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"attachment\" (",
|
"INSERT INTO agreego.\"attachment\" (",
|
||||||
@ -3373,7 +3442,8 @@
|
|||||||
" '{",
|
" '{",
|
||||||
" \"type\": \"type_metadata\"",
|
" \"type\": \"type_metadata\"",
|
||||||
" }'",
|
" }'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"attachment\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3480,7 +3550,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order_line\" (",
|
"INSERT INTO agreego.\"order_line\" (",
|
||||||
@ -3496,7 +3567,8 @@
|
|||||||
" 99,",
|
" 99,",
|
||||||
" 'Widget',",
|
" 'Widget',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order_line\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3568,7 +3640,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"order_line\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"order_line\" t2 ON t2.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
@ -3590,7 +3662,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order_line\" (",
|
"INSERT INTO agreego.\"order_line\" (",
|
||||||
@ -3606,7 +3679,8 @@
|
|||||||
" 99,",
|
" 99,",
|
||||||
" 'Widget',",
|
" 'Widget',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order_line\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3692,7 +3766,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
@ -3714,7 +3788,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'invoice'",
|
" 'invoice'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"invoice\" (",
|
"INSERT INTO agreego.\"invoice\" (",
|
||||||
@ -3746,7 +3821,8 @@
|
|||||||
" }',",
|
" }',",
|
||||||
" 200,",
|
" 200,",
|
||||||
" 'invoice'",
|
" 'invoice'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"invoice\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3808,7 +3884,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||||
"FROM agreego.\"entity\" t1",
|
"FROM agreego.\"entity\" t1",
|
||||||
"LEFT JOIN agreego.\"account\" t2 ON t2.id = t1.id",
|
"LEFT JOIN agreego.\"account\" t2 ON t2.id = t1.id",
|
||||||
"WHERE",
|
"WHERE",
|
||||||
@ -3830,7 +3906,8 @@
|
|||||||
" '{{timestamp}}',",
|
" '{{timestamp}}',",
|
||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'account'",
|
" 'account'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"account\" (",
|
"INSERT INTO agreego.\"account\" (",
|
||||||
@ -3844,7 +3921,8 @@
|
|||||||
" 'checking',",
|
" 'checking',",
|
||||||
" '123456789',",
|
" '123456789',",
|
||||||
" 'account'",
|
" 'account'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"account\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -3936,7 +4014,8 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" '{{uuid:generated_1}}',",
|
" '{{uuid:generated_1}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"organization\" (",
|
"INSERT INTO agreego.\"organization\" (",
|
||||||
@ -3946,7 +4025,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"organization\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"user\" (",
|
"INSERT INTO agreego.\"user\" (",
|
||||||
@ -3956,7 +4036,8 @@
|
|||||||
"VALUES (",
|
"VALUES (",
|
||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"user\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"person\" (",
|
"INSERT INTO agreego.\"person\" (",
|
||||||
@ -3970,7 +4051,8 @@
|
|||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" 'Person',",
|
" 'Person',",
|
||||||
" 'person'",
|
" 'person'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"person\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -4015,7 +4097,8 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'parent-org-id',",
|
" 'parent-org-id',",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order\" (",
|
"INSERT INTO agreego.\"order\" (",
|
||||||
@ -4027,7 +4110,8 @@
|
|||||||
" '{{uuid:generated_0}}',",
|
" '{{uuid:generated_0}}',",
|
||||||
" '{{uuid:generated_3}}',",
|
" '{{uuid:generated_3}}',",
|
||||||
" 'order'",
|
" 'order'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -4047,7 +4131,8 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'parent-org-id',",
|
" 'parent-org-id',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order_line\" (",
|
"INSERT INTO agreego.\"order_line\" (",
|
||||||
@ -4059,7 +4144,8 @@
|
|||||||
" '{{uuid:generated_4}}',",
|
" '{{uuid:generated_4}}',",
|
||||||
" '{{uuid:generated_3}}',",
|
" '{{uuid:generated_3}}',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order_line\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
@ -4103,7 +4189,8 @@
|
|||||||
" '00000000-0000-0000-0000-000000000000',",
|
" '00000000-0000-0000-0000-000000000000',",
|
||||||
" 'explicit-org-id',",
|
" 'explicit-org-id',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"entity\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"order_line\" (",
|
"INSERT INTO agreego.\"order_line\" (",
|
||||||
@ -4115,7 +4202,8 @@
|
|||||||
" '{{uuid:generated_6}}',",
|
" '{{uuid:generated_6}}',",
|
||||||
" '{{uuid:generated_3}}',",
|
" '{{uuid:generated_3}}',",
|
||||||
" 'order_line'",
|
" 'order_line'",
|
||||||
")"
|
")",
|
||||||
|
"RETURNING to_jsonb(\"order_line\".*)"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.change (",
|
"INSERT INTO agreego.change (",
|
||||||
|
|||||||
@ -873,5 +873,142 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "immutable property validation in request vs response context",
|
||||||
|
"database": {
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "item",
|
||||||
|
"schemas": {
|
||||||
|
"save_item.request": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string",
|
||||||
|
"immutable": "always"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"get_item.response": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string",
|
||||||
|
"immutable": "always"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tests": [
|
||||||
|
{
|
||||||
|
"description": "immutable property in request context causes IMMUTABLE_PROPERTY_VIOLATION",
|
||||||
|
"data": {
|
||||||
|
"id": "123",
|
||||||
|
"created_at": "2026-07-21T00:00:00Z"
|
||||||
|
},
|
||||||
|
"schema_id": "save_item.request",
|
||||||
|
"action": "validate",
|
||||||
|
"expect": {
|
||||||
|
"success": false,
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"code": "IMMUTABLE_PROPERTY_VIOLATION",
|
||||||
|
"values": {
|
||||||
|
"property_name": "created_at"
|
||||||
|
},
|
||||||
|
"details": {
|
||||||
|
"path": "created_at",
|
||||||
|
"schema": "save_item.request"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "immutable property in response context is allowed",
|
||||||
|
"data": {
|
||||||
|
"id": "123",
|
||||||
|
"created_at": "2026-07-21T00:00:00Z"
|
||||||
|
},
|
||||||
|
"schema_id": "get_item.response",
|
||||||
|
"action": "validate",
|
||||||
|
"expect": {
|
||||||
|
"success": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "immutable external vs always property validation",
|
||||||
|
"database": {
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "invoice",
|
||||||
|
"schemas": {
|
||||||
|
"save_invoice.request": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"immutable": "external"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string",
|
||||||
|
"immutable": "always"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tests": [
|
||||||
|
{
|
||||||
|
"description": "immutable external property in request context allowed when internal (punc.external = false)",
|
||||||
|
"data": {
|
||||||
|
"id": "123",
|
||||||
|
"status": "paid"
|
||||||
|
},
|
||||||
|
"schema_id": "save_invoice.request",
|
||||||
|
"action": "validate",
|
||||||
|
"expect": {
|
||||||
|
"success": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "immutable always property in request context rejected even when internal (punc.external = false)",
|
||||||
|
"data": {
|
||||||
|
"id": "123",
|
||||||
|
"created_at": "2026-07-21T00:00:00Z"
|
||||||
|
},
|
||||||
|
"schema_id": "save_invoice.request",
|
||||||
|
"action": "validate",
|
||||||
|
"expect": {
|
||||||
|
"success": false,
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"code": "IMMUTABLE_PROPERTY_VIOLATION",
|
||||||
|
"values": {
|
||||||
|
"property_name": "created_at"
|
||||||
|
},
|
||||||
|
"details": {
|
||||||
|
"path": "created_at",
|
||||||
|
"schema": "save_invoice.request"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -1739,10 +1739,10 @@
|
|||||||
" AND entity_1.created_at <= ($16 #>> '{}')::TIMESTAMPTZ",
|
" AND entity_1.created_at <= ($16 #>> '{}')::TIMESTAMPTZ",
|
||||||
" AND entity_1.created_at <> ($17 #>> '{}')::TIMESTAMPTZ",
|
" AND entity_1.created_at <> ($17 #>> '{}')::TIMESTAMPTZ",
|
||||||
" AND person_3.first_name ILIKE $18 #>> '{}'",
|
" AND person_3.first_name ILIKE $18 #>> '{}'",
|
||||||
" AND person_3.first_name > ($19 #>> '{)",
|
" AND person_3.first_name > ($19 #>> '{}')",
|
||||||
" AND person_3.first_name >= ($20 #>> '{)",
|
" AND person_3.first_name >= ($20 #>> '{}')",
|
||||||
" AND person_3.first_name < ($21 #>> '{)",
|
" AND person_3.first_name < ($21 #>> '{}')",
|
||||||
" AND person_3.first_name <= ($22 #>> '{)",
|
" AND person_3.first_name <= ($22 #>> '{}')",
|
||||||
" AND person_3.first_name NOT ILIKE $23 #>> '{}'",
|
" AND person_3.first_name NOT ILIKE $23 #>> '{}'",
|
||||||
" AND person_3.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))",
|
" AND person_3.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))",
|
||||||
" AND person_3.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))",
|
" AND person_3.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))",
|
||||||
|
|||||||
@ -13,6 +13,7 @@ pub struct MockState {
|
|||||||
pub query_responses: Vec<Result<Value, String>>,
|
pub query_responses: Vec<Result<Value, String>>,
|
||||||
pub execute_responses: Vec<Result<(), String>>,
|
pub execute_responses: Vec<Result<(), String>>,
|
||||||
pub mocks: Vec<Value>,
|
pub mocks: Vec<Value>,
|
||||||
|
pub punc_external: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -23,10 +24,12 @@ impl MockState {
|
|||||||
query_responses: Default::default(),
|
query_responses: Default::default(),
|
||||||
execute_responses: Default::default(),
|
execute_responses: Default::default(),
|
||||||
mocks: Default::default(),
|
mocks: Default::default(),
|
||||||
|
punc_external: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
thread_local! {
|
thread_local! {
|
||||||
pub static MOCK_STATE: RefCell<MockState> = RefCell::new(MockState::new());
|
pub static MOCK_STATE: RefCell<MockState> = RefCell::new(MockState::new());
|
||||||
@ -85,6 +88,10 @@ impl DatabaseExecutor for MockExecutor {
|
|||||||
Ok("2026-03-10T00:00:00Z".to_string())
|
Ok("2026-03-10T00:00:00Z".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn punc_external(&self) -> Result<bool, String> {
|
||||||
|
Ok(MOCK_STATE.with(|state| state.borrow().punc_external))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn get_queries(&self) -> Vec<String> {
|
fn get_queries(&self) -> Vec<String> {
|
||||||
MOCK_STATE.with(|state| state.borrow().captured_queries.clone())
|
MOCK_STATE.with(|state| state.borrow().captured_queries.clone())
|
||||||
@ -105,10 +112,21 @@ impl DatabaseExecutor for MockExecutor {
|
|||||||
s.query_responses.clear();
|
s.query_responses.clear();
|
||||||
s.execute_responses.clear();
|
s.execute_responses.clear();
|
||||||
s.mocks.clear();
|
s.mocks.clear();
|
||||||
|
s.punc_external = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl MockExecutor {
|
||||||
|
pub fn set_punc_external(&self, external: bool) {
|
||||||
|
MOCK_STATE.with(|state| {
|
||||||
|
state.borrow_mut().punc_external = external;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn parse_and_match_mocks(sql: &str, mocks: &[Value]) -> Option<Vec<Value>> {
|
fn parse_and_match_mocks(sql: &str, mocks: &[Value]) -> Option<Vec<Value>> {
|
||||||
let sql_upper = sql.to_uppercase();
|
let sql_upper = sql.to_uppercase();
|
||||||
|
|||||||
@ -20,6 +20,9 @@ pub trait DatabaseExecutor: Send + Sync {
|
|||||||
/// Returns the current transaction timestamp
|
/// Returns the current transaction timestamp
|
||||||
fn timestamp(&self) -> Result<String, String>;
|
fn timestamp(&self) -> Result<String, String>;
|
||||||
|
|
||||||
|
/// Returns true if the current execution context is marked as an external client API cue (punc.external = true)
|
||||||
|
fn punc_external(&self) -> Result<bool, String>;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn get_queries(&self) -> Vec<String>;
|
fn get_queries(&self) -> Vec<String>;
|
||||||
|
|
||||||
|
|||||||
@ -150,4 +150,26 @@ impl DatabaseExecutor for SpiExecutor {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn punc_external(&self) -> Result<bool, String> {
|
||||||
|
self.transact(|| {
|
||||||
|
Spi::connect(|client| {
|
||||||
|
let mut tup_table = client
|
||||||
|
.select(
|
||||||
|
"SELECT COALESCE(current_setting('punc.external', true), 'false')::boolean",
|
||||||
|
None,
|
||||||
|
&[],
|
||||||
|
)
|
||||||
|
.map_err(|e| format!("SPI Select Error: {}", e))?;
|
||||||
|
|
||||||
|
let row = tup_table
|
||||||
|
.next()
|
||||||
|
.ok_or("No setting returned from context".to_string())?;
|
||||||
|
let is_external: Option<bool> = row.get(1).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
Ok(is_external.unwrap_or(false))
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -149,6 +149,9 @@ pub struct SchemaObject {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub extensible: Option<bool>,
|
pub extensible: Option<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub immutable: Option<ImmutableMode>,
|
||||||
|
|
||||||
// Contains ALL structural fields perfectly flattened from the ENTIRE Database inheritance tree (e.g. `entity` fields like `id`) as well as local fields hidden inside conditional `cases` blocks.
|
// Contains ALL structural fields perfectly flattened from the ENTIRE Database inheritance tree (e.g. `entity` fields like `id`) as well as local fields hidden inside conditional `cases` blocks.
|
||||||
// This JSON exported array gives clients absolute deterministic visibility to O(1) validation and masking bounds without duplicating structural memory.
|
// This JSON exported array gives clients absolute deterministic visibility to O(1) validation and masking bounds without duplicating structural memory.
|
||||||
@ -260,6 +263,13 @@ pub fn is_primitive_type(t: &str) -> bool {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum ImmutableMode {
|
||||||
|
Always,
|
||||||
|
External,
|
||||||
|
}
|
||||||
|
|
||||||
impl SchemaObject {
|
impl SchemaObject {
|
||||||
pub fn get_discriminator_value(&self, dim: &str, schema_id: &str) -> Option<String> {
|
pub fn get_discriminator_value(&self, dim: &str, schema_id: &str) -> Option<String> {
|
||||||
let is_split = self
|
let is_split = self
|
||||||
@ -306,4 +316,12 @@ impl SchemaObject {
|
|||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_immutable(&self, is_external: bool) -> bool {
|
||||||
|
match self.immutable {
|
||||||
|
Some(ImmutableMode::Always) => true,
|
||||||
|
Some(ImmutableMode::External) => is_external,
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ pub fn jspg_setup(database: Json) -> Json {
|
|||||||
Json(serde_json::to_value(drop).unwrap())
|
Json(serde_json::to_value(drop).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern(volatile))]
|
||||||
pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
||||||
// Try to acquire a read lock to get a clone of the Engine Arc
|
// Try to acquire a read lock to get a clone of the Engine Arc
|
||||||
let engine_opt = {
|
let engine_opt = {
|
||||||
@ -74,7 +74,7 @@ pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern(volatile))]
|
||||||
pub fn jspg_merge_ordered(schema_id: &str, data: Json) -> Json {
|
pub fn jspg_merge_ordered(schema_id: &str, data: Json) -> Json {
|
||||||
let engine_opt = {
|
let engine_opt = {
|
||||||
let lock = GLOBAL_JSPG.read().unwrap();
|
let lock = GLOBAL_JSPG.read().unwrap();
|
||||||
|
|||||||
@ -6,8 +6,8 @@ pub mod cache;
|
|||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::database::r#type::Type;
|
use crate::database::r#type::Type;
|
||||||
use crate::drop::{Drop, Error, ErrorDetails};
|
use crate::drop::{Drop, Error, ErrorDetails};
|
||||||
use serde_json::Value;
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use serde_json::Value;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Merger {
|
pub struct Merger {
|
||||||
@ -31,9 +31,10 @@ impl Merger {
|
|||||||
None => {
|
None => {
|
||||||
return Drop::with_errors(vec![Error {
|
return Drop::with_errors(vec![Error {
|
||||||
code: "SCHEMA_NOT_FOUND".to_string(),
|
code: "SCHEMA_NOT_FOUND".to_string(),
|
||||||
values: Some(IndexMap::from([
|
values: Some(IndexMap::from([(
|
||||||
("schema".to_string(), schema_id.to_string()),
|
"schema".to_string(),
|
||||||
])),
|
schema_id.to_string(),
|
||||||
|
)])),
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
path: None,
|
path: None,
|
||||||
cause: None,
|
cause: None,
|
||||||
@ -48,47 +49,7 @@ impl Merger {
|
|||||||
|
|
||||||
let val_resolved = match result {
|
let val_resolved = match result {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(msg) => {
|
Err(err) => return Drop::with_errors(vec![err]),
|
||||||
let mut final_code = "MERGE_FAILED".to_string();
|
|
||||||
let mut final_message = msg.clone();
|
|
||||||
let mut final_cause = None;
|
|
||||||
|
|
||||||
if let Ok(Value::Object(map)) = serde_json::from_str::<Value>(&msg) {
|
|
||||||
if let (Some(Value::String(e_msg)), Some(Value::String(e_code))) =
|
|
||||||
(map.get("error"), map.get("code"))
|
|
||||||
{
|
|
||||||
final_message = e_msg.clone();
|
|
||||||
final_code = e_code.clone();
|
|
||||||
let mut cause_parts = Vec::new();
|
|
||||||
if let Some(Value::String(d)) = map.get("detail") {
|
|
||||||
if !d.is_empty() {
|
|
||||||
cause_parts.push(d.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(Value::String(h)) = map.get("hint") {
|
|
||||||
if !h.is_empty() {
|
|
||||||
cause_parts.push(h.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !cause_parts.is_empty() {
|
|
||||||
final_cause = Some(cause_parts.join("\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Drop::with_errors(vec![Error {
|
|
||||||
code: final_code,
|
|
||||||
values: Some(IndexMap::from([
|
|
||||||
("error".to_string(), final_message),
|
|
||||||
])),
|
|
||||||
details: ErrorDetails {
|
|
||||||
path: None,
|
|
||||||
cause: final_cause,
|
|
||||||
context: None,
|
|
||||||
schema: None,
|
|
||||||
},
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute the globally collected, pre-ordered notifications last!
|
// Execute the globally collected, pre-ordered notifications last!
|
||||||
@ -96,12 +57,10 @@ impl Merger {
|
|||||||
if let Err(e) = self.db.execute(¬ify_sql, None) {
|
if let Err(e) = self.db.execute(¬ify_sql, None) {
|
||||||
return Drop::with_errors(vec![Error {
|
return Drop::with_errors(vec![Error {
|
||||||
code: "MERGE_FAILED".to_string(),
|
code: "MERGE_FAILED".to_string(),
|
||||||
values: Some(IndexMap::from([
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
("error".to_string(), e.to_string()),
|
|
||||||
])),
|
|
||||||
details: ErrorDetails {
|
details: ErrorDetails {
|
||||||
path: None,
|
path: None,
|
||||||
cause: None,
|
cause: Some(e),
|
||||||
context: None,
|
context: None,
|
||||||
schema: None,
|
schema: None,
|
||||||
},
|
},
|
||||||
@ -144,7 +103,7 @@ impl Merger {
|
|||||||
notifications: &mut Vec<String>,
|
notifications: &mut Vec<String>,
|
||||||
parent_org_id: Option<String>,
|
parent_org_id: Option<String>,
|
||||||
is_child: bool,
|
is_child: bool,
|
||||||
) -> Result<Value, String> {
|
) -> Result<Value, Error> {
|
||||||
match data {
|
match data {
|
||||||
Value::Array(items) => {
|
Value::Array(items) => {
|
||||||
self.merge_array(schema, items, notifications, parent_org_id, is_child)
|
self.merge_array(schema, items, notifications, parent_org_id, is_child)
|
||||||
@ -159,10 +118,20 @@ impl Merger {
|
|||||||
if let Some(target_schema) = self.db.schemas.get(target_id) {
|
if let Some(target_schema) = self.db.schemas.get(target_id) {
|
||||||
schema = target_schema.clone();
|
schema = target_schema.clone();
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(Error {
|
||||||
|
code: "TARGET_SCHEMA_NOT_FOUND".to_string(),
|
||||||
|
values: Some(IndexMap::from([(
|
||||||
|
"target_id".to_string(),
|
||||||
|
target_id.clone(),
|
||||||
|
)])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
"Polymorphic mapped target '{}' not found in database registry",
|
"Polymorphic mapped target '{}' not found in database registry",
|
||||||
target_id
|
target_id
|
||||||
));
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if let Some(idx) = idx_opt {
|
} else if let Some(idx) = idx_opt {
|
||||||
if let Some(target_schema) = schema
|
if let Some(target_schema) = schema
|
||||||
@ -173,31 +142,72 @@ impl Merger {
|
|||||||
{
|
{
|
||||||
schema = Arc::clone(target_schema);
|
schema = Arc::clone(target_schema);
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(Error {
|
||||||
|
code: "ONE_OF_INDEX_NOT_FOUND".to_string(),
|
||||||
|
values: Some(IndexMap::from([("index".to_string(), idx.to_string())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
"Polymorphic index target '{}' not found in local oneOf array",
|
"Polymorphic index target '{}' not found in local oneOf array",
|
||||||
idx
|
idx
|
||||||
));
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(format!("Polymorphic mapped target has no path"));
|
return Err(Error {
|
||||||
|
code: "INVALID_POLYMORPHIC_TARGET".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Polymorphic mapped target has no path".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(Error {
|
||||||
|
code: "DISCRIMINATOR_MISMATCH".to_string(),
|
||||||
|
values: Some(IndexMap::from([
|
||||||
|
("discriminator".to_string(), disc.to_string()),
|
||||||
|
("value".to_string(), v.to_string()),
|
||||||
|
])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
"Polymorphic discriminator {}='{}' matched no compiled options",
|
"Polymorphic discriminator {}='{}' matched no compiled options",
|
||||||
disc, v
|
disc, v
|
||||||
));
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(Error {
|
||||||
|
code: "MISSING_DISCRIMINATOR".to_string(),
|
||||||
|
values: Some(IndexMap::from([(
|
||||||
|
"discriminator".to_string(),
|
||||||
|
disc.to_string(),
|
||||||
|
)])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
"Polymorphic merging failed: missing required discriminator '{}'",
|
"Polymorphic merging failed: missing required discriminator '{}'",
|
||||||
disc
|
disc
|
||||||
));
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.merge_object(schema, map, notifications, parent_org_id, is_child)
|
self.merge_object(schema, map, notifications, parent_org_id, is_child)
|
||||||
}
|
}
|
||||||
_ => Err("Invalid merge payload: root must be an Object or Array".to_string()),
|
_ => Err(Error {
|
||||||
|
code: "INVALID_MERGE_PAYLOAD".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Invalid merge payload: root must be an Object or Array".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +218,7 @@ impl Merger {
|
|||||||
notifications: &mut Vec<String>,
|
notifications: &mut Vec<String>,
|
||||||
parent_org_id: Option<String>,
|
parent_org_id: Option<String>,
|
||||||
is_child: bool,
|
is_child: bool,
|
||||||
) -> Result<Value, String> {
|
) -> Result<Value, Error> {
|
||||||
let mut item_schema = schema.clone();
|
let mut item_schema = schema.clone();
|
||||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &schema.obj.type_ {
|
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &schema.obj.type_ {
|
||||||
if t == "array" {
|
if t == "array" {
|
||||||
@ -239,22 +249,49 @@ impl Merger {
|
|||||||
notifications: &mut Vec<String>,
|
notifications: &mut Vec<String>,
|
||||||
parent_org_id: Option<String>,
|
parent_org_id: Option<String>,
|
||||||
is_child: bool,
|
is_child: bool,
|
||||||
) -> Result<Value, String> {
|
) -> Result<Value, Error> {
|
||||||
let queue_start = notifications.len();
|
let queue_start = notifications.len();
|
||||||
|
|
||||||
let type_name = match obj.get("type").and_then(|v| v.as_str()) {
|
let type_name = match obj.get("type").and_then(|v| v.as_str()) {
|
||||||
Some(t) => t.to_string(),
|
Some(t) => t.to_string(),
|
||||||
None => return Err("Missing required 'type' field on object".to_string()),
|
None => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "MISSING_TYPE".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Missing required 'type' field on object".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let type_def = match self.db.types.get(&type_name) {
|
let type_def = match self.db.types.get(&type_name) {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return Err(format!("Unknown entity type: {}", type_name)),
|
None => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "UNKNOWN_ENTITY_TYPE".to_string(),
|
||||||
|
values: Some(IndexMap::from([("type".to_string(), type_name.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!("Unknown entity type: {}", type_name)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let compiled_props = match schema.obj.compiled_properties.get() {
|
let compiled_props = match schema.obj.compiled_properties.get() {
|
||||||
Some(props) => props,
|
Some(props) => props,
|
||||||
None => return Err("Schema has no compiled properties for merging".to_string()),
|
None => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "UNCOMPILED_SCHEMA".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Schema has no compiled properties for merging".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut entity_fields = serde_json::Map::new();
|
let mut entity_fields = serde_json::Map::new();
|
||||||
@ -312,8 +349,22 @@ impl Merger {
|
|||||||
current_org_id = parent_org_id.clone();
|
current_org_id = parent_org_id.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_id = self.db.auth_user_id()?;
|
let user_id = self.db.auth_user_id().map_err(|e| Error {
|
||||||
let timestamp = self.db.timestamp()?;
|
code: "AUTH_USER_FAILED".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(e),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
})?;
|
||||||
|
let timestamp = self.db.timestamp().map_err(|e| Error {
|
||||||
|
code: "TIMESTAMP_FAILED".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(e),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut entity_change_kind = None;
|
let mut entity_change_kind = None;
|
||||||
let mut entity_fetched = None;
|
let mut entity_fetched = None;
|
||||||
@ -328,6 +379,33 @@ impl Merger {
|
|||||||
entity_replaces = replaces;
|
entity_replaces = replaces;
|
||||||
|
|
||||||
if entity_change_kind.as_deref() == Some("create") {
|
if entity_change_kind.as_deref() == Some("create") {
|
||||||
|
if let Some(deps) = &schema.obj.dependencies {
|
||||||
|
if let Some(crate::database::object::Dependency::Props(req_props)) = deps.get("created") {
|
||||||
|
for req in req_props {
|
||||||
|
if !entity_fields.contains_key(req)
|
||||||
|
&& !entity_objects.contains_key(req)
|
||||||
|
&& !entity_arrays.contains_key(req)
|
||||||
|
{
|
||||||
|
return Err(Error {
|
||||||
|
code: "REQUIRED_FIELD_MISSING".to_string(),
|
||||||
|
values: Some(IndexMap::from([
|
||||||
|
("property_name".to_string(), req.to_string()),
|
||||||
|
("entity_type".to_string(), type_name.clone()),
|
||||||
|
])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
path: Some(req.to_string()),
|
||||||
|
cause: Some(format!(
|
||||||
|
"Missing required creation field '{}' for entity {}",
|
||||||
|
req, type_name
|
||||||
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if is_child {
|
if is_child {
|
||||||
if !entity_fields.contains_key("organization_id") {
|
if !entity_fields.contains_key("organization_id") {
|
||||||
if let Some(ref org_id) = current_org_id {
|
if let Some(ref org_id) = current_org_id {
|
||||||
@ -430,7 +508,7 @@ impl Merger {
|
|||||||
entity_change_kind.as_deref().unwrap_or(""),
|
entity_change_kind.as_deref().unwrap_or(""),
|
||||||
&type_name,
|
&type_name,
|
||||||
type_def,
|
type_def,
|
||||||
&entity_fields,
|
&mut entity_fields,
|
||||||
entity_fetched.as_ref(),
|
entity_fetched.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@ -538,7 +616,7 @@ impl Merger {
|
|||||||
Option<serde_json::Map<String, Value>>,
|
Option<serde_json::Map<String, Value>>,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
),
|
),
|
||||||
String,
|
Error,
|
||||||
> {
|
> {
|
||||||
let type_name = type_def.name.as_str();
|
let type_name = type_def.name.as_str();
|
||||||
|
|
||||||
@ -673,7 +751,7 @@ impl Merger {
|
|||||||
&self,
|
&self,
|
||||||
entity_fields: &serde_json::Map<String, Value>,
|
entity_fields: &serde_json::Map<String, Value>,
|
||||||
entity_type: &crate::database::r#type::Type,
|
entity_type: &crate::database::r#type::Type,
|
||||||
) -> Result<Option<serde_json::Map<String, Value>>, String> {
|
) -> Result<Option<serde_json::Map<String, Value>>, Error> {
|
||||||
let id_val = entity_fields.get("id");
|
let id_val = entity_fields.get("id");
|
||||||
let entity_type_name = entity_type.name.as_str();
|
let entity_type_name = entity_type.name.as_str();
|
||||||
|
|
||||||
@ -709,7 +787,7 @@ impl Merger {
|
|||||||
let fetch_sql_template = if let Some(cached) = self.cache.get(entity_type_name) {
|
let fetch_sql_template = if let Some(cached) = self.cache.get(entity_type_name) {
|
||||||
cached
|
cached
|
||||||
} else {
|
} else {
|
||||||
let mut select_list = String::from("to_jsonb(t1.*)");
|
let mut select_list = String::from("COALESCE(to_jsonb(t1.*), '{}')");
|
||||||
let mut join_clauses = format!("FROM agreego.\"{}\" t1", entity_type.hierarchy[0]);
|
let mut join_clauses = format!("FROM agreego.\"{}\" t1", entity_type.hierarchy[0]);
|
||||||
|
|
||||||
for (i, table_name) in entity_type.hierarchy.iter().enumerate().skip(1) {
|
for (i, table_name) in entity_type.hierarchy.iter().enumerate().skip(1) {
|
||||||
@ -718,7 +796,7 @@ impl Merger {
|
|||||||
" LEFT JOIN agreego.\"{}\" {} ON {}.id = t1.id",
|
" LEFT JOIN agreego.\"{}\" {} ON {}.id = t1.id",
|
||||||
table_name, t_alias, t_alias
|
table_name, t_alias, t_alias
|
||||||
));
|
));
|
||||||
select_list.push_str(&format!(" || to_jsonb({}.*)", t_alias));
|
select_list.push_str(&format!(" || COALESCE(to_jsonb({}.*), '{{}}')", t_alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
let template = format!("SELECT {} {}", select_list, join_clauses);
|
let template = format!("SELECT {} {}", select_list, join_clauses);
|
||||||
@ -764,22 +842,53 @@ impl Merger {
|
|||||||
let fetched = match self.db.query(&final_sql, None) {
|
let fetched = match self.db.query(&final_sql, None) {
|
||||||
Ok(Value::Array(table)) => {
|
Ok(Value::Array(table)) => {
|
||||||
if table.len() > 1 {
|
if table.len() > 1 {
|
||||||
Err(format!(
|
Err(Error {
|
||||||
"TOO_MANY_LOOKUP_ROWS: Lookup for {} found too many existing rows",
|
code: "TOO_MANY_LOOKUP_ROWS".to_string(),
|
||||||
|
values: Some(IndexMap::from([(
|
||||||
|
"entity_type".to_string(),
|
||||||
|
entity_type_name.to_string(),
|
||||||
|
)])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
|
"Lookup for {} found too many existing rows",
|
||||||
entity_type_name
|
entity_type_name
|
||||||
))
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
})
|
||||||
} else if table.is_empty() {
|
} else if table.is_empty() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
let row = table.first().unwrap();
|
let row = table.first().unwrap();
|
||||||
match row {
|
match row {
|
||||||
Value::Object(map) => Ok(Some(map.clone())),
|
Value::Object(map) => Ok(Some(map.clone())),
|
||||||
other => Err(format!("Expected JSON object, got: {:?}", other)),
|
other => Err(Error {
|
||||||
|
code: "UNEXPECTED_QUERY_RESULT".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!("Expected JSON object, got: {:?}", other)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(_) => Err("Expected array from query in fetch_entity".to_string()),
|
Ok(_) => Err(Error {
|
||||||
Err(e) => Err(format!("SPI error in fetch_entity: {:?}", e)),
|
code: "UNEXPECTED_QUERY_RESULT".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Expected array from query in fetch_entity".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Err(e) => Err(Error {
|
||||||
|
code: "DATABASE_SPI_ERROR".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!("SPI error in fetch_entity: {:?}", e)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
}),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
Ok(fetched)
|
Ok(fetched)
|
||||||
@ -790,25 +899,44 @@ impl Merger {
|
|||||||
change_kind: &str,
|
change_kind: &str,
|
||||||
entity_type_name: &str,
|
entity_type_name: &str,
|
||||||
entity_type: &crate::database::r#type::Type,
|
entity_type: &crate::database::r#type::Type,
|
||||||
entity_fields: &serde_json::Map<String, Value>,
|
entity_fields: &mut serde_json::Map<String, Value>,
|
||||||
_entity_fetched: Option<&serde_json::Map<String, Value>>,
|
_entity_fetched: Option<&serde_json::Map<String, Value>>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), Error> {
|
||||||
if change_kind.is_empty() {
|
if change_kind.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let id_str = match entity_fields.get("id").and_then(|v| v.as_str()) {
|
let id_str = match entity_fields.get("id").and_then(|v| v.as_str()) {
|
||||||
Some(id) => id,
|
Some(id) => id.to_string(),
|
||||||
None => return Err("Missing 'id' for merge execution".to_string()),
|
None => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "MISSING_ENTITY_ID".to_string(),
|
||||||
|
values: None,
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some("Missing 'id' for merge execution".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let grouped_fields = match &entity_type.grouped_fields {
|
let grouped_fields = match &entity_type.grouped_fields {
|
||||||
Some(Value::Object(map)) => map,
|
Some(Value::Object(map)) => map,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!(
|
return Err(Error {
|
||||||
|
code: "MISSING_GROUPED_FIELDS".to_string(),
|
||||||
|
values: Some(IndexMap::from([(
|
||||||
|
"type".to_string(),
|
||||||
|
entity_type_name.to_string(),
|
||||||
|
)])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(format!(
|
||||||
"Grouped fields missing for type {}",
|
"Grouped fields missing for type {}",
|
||||||
entity_type_name
|
entity_type_name
|
||||||
));
|
)),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -822,7 +950,7 @@ impl Merger {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut entity_pairs = serde_json::Map::new();
|
let mut entity_pairs = serde_json::Map::new();
|
||||||
for (k, v) in entity_fields {
|
for (k, v) in entity_fields.iter() {
|
||||||
if table_fields.contains(k) {
|
if table_fields.contains(k) {
|
||||||
entity_pairs.insert(k.clone(), v.clone());
|
entity_pairs.insert(k.clone(), v.clone());
|
||||||
}
|
}
|
||||||
@ -856,12 +984,34 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sql = format!(
|
let sql = format!(
|
||||||
"INSERT INTO agreego.\"{}\" ({}) VALUES ({})",
|
"INSERT INTO agreego.\"{}\" ({}) VALUES ({}) RETURNING to_jsonb(\"{}\".*)",
|
||||||
table_name,
|
table_name,
|
||||||
columns.join(", "),
|
columns.join(", "),
|
||||||
values.join(", ")
|
values.join(", "),
|
||||||
|
table_name
|
||||||
);
|
);
|
||||||
self.db.execute(&sql, None)?;
|
match self.db.query(&sql, None) {
|
||||||
|
Ok(Value::Array(rows)) => {
|
||||||
|
if let Some(Value::Object(row_map)) = rows.into_iter().next() {
|
||||||
|
for (k, v) in row_map {
|
||||||
|
if !v.is_null() {
|
||||||
|
entity_fields.insert(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "DATABASE_SPI_ERROR".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(e),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
} else if change_kind == "update" || change_kind == "delete" {
|
} else if change_kind == "update" || change_kind == "delete" {
|
||||||
entity_pairs.remove("id");
|
entity_pairs.remove("id");
|
||||||
entity_pairs.remove("type");
|
entity_pairs.remove("type");
|
||||||
@ -888,12 +1038,34 @@ impl Merger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sql = format!(
|
let sql = format!(
|
||||||
"UPDATE agreego.\"{}\" SET {} WHERE id = {}",
|
"UPDATE agreego.\"{}\" SET {} WHERE id = {} RETURNING to_jsonb(\"{}\".*)",
|
||||||
table_name,
|
table_name,
|
||||||
set_clauses.join(", "),
|
set_clauses.join(", "),
|
||||||
Self::quote_literal(&Value::String(id_str.to_string()))
|
Self::quote_literal(&Value::String(id_str.to_string())),
|
||||||
|
table_name
|
||||||
);
|
);
|
||||||
self.db.execute(&sql, None)?;
|
match self.db.query(&sql, None) {
|
||||||
|
Ok(Value::Array(rows)) => {
|
||||||
|
if let Some(Value::Object(row_map)) = rows.into_iter().next() {
|
||||||
|
for (k, v) in row_map {
|
||||||
|
if !v.is_null() {
|
||||||
|
entity_fields.insert(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(Error {
|
||||||
|
code: "DATABASE_SPI_ERROR".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(e),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -909,7 +1081,7 @@ impl Merger {
|
|||||||
user_id: &str,
|
user_id: &str,
|
||||||
timestamp: &str,
|
timestamp: &str,
|
||||||
replaces_id: Option<&str>,
|
replaces_id: Option<&str>,
|
||||||
) -> Result<Option<String>, String> {
|
) -> Result<Option<String>, Error> {
|
||||||
let change_kind = match entity_change_kind {
|
let change_kind = match entity_change_kind {
|
||||||
Some(k) => k,
|
Some(k) => k,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
@ -1002,7 +1174,16 @@ impl Merger {
|
|||||||
Self::quote_literal(&Value::String(user_id.to_string()))
|
Self::quote_literal(&Value::String(user_id.to_string()))
|
||||||
);
|
);
|
||||||
|
|
||||||
self.db.execute(&change_sql, None)?;
|
if let Err(e) = self.db.execute(&change_sql, None) {
|
||||||
|
return Err(Error {
|
||||||
|
code: "DATABASE_SPI_ERROR".to_string(),
|
||||||
|
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||||
|
details: ErrorDetails {
|
||||||
|
cause: Some(e),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_obj.notify {
|
if type_obj.notify {
|
||||||
|
|||||||
@ -2519,6 +2519,30 @@ fn test_properties_12_0() {
|
|||||||
crate::tests::runner::run_test_case(&path, 12, 0).unwrap();
|
crate::tests::runner::run_test_case(&path, 12, 0).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_properties_13_0() {
|
||||||
|
let path = format!("{}/fixtures/properties.json", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
crate::tests::runner::run_test_case(&path, 13, 0).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_properties_13_1() {
|
||||||
|
let path = format!("{}/fixtures/properties.json", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
crate::tests::runner::run_test_case(&path, 13, 1).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_properties_14_0() {
|
||||||
|
let path = format!("{}/fixtures/properties.json", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
crate::tests::runner::run_test_case(&path, 14, 0).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_properties_14_1() {
|
||||||
|
let path = format!("{}/fixtures/properties.json", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
crate::tests::runner::run_test_case(&path, 14, 1).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_max_contains_0_0() {
|
fn test_max_contains_0_0() {
|
||||||
let path = format!("{}/fixtures/maxContains.json", env!("CARGO_MANIFEST_DIR"));
|
let path = format!("{}/fixtures/maxContains.json", env!("CARGO_MANIFEST_DIR"));
|
||||||
|
|||||||
@ -97,7 +97,14 @@ impl SqlFormatter {
|
|||||||
self.push_line("VALUES (");
|
self.push_line("VALUES (");
|
||||||
self.indent += 2;
|
self.indent += 2;
|
||||||
|
|
||||||
let vals = if suffix.ends_with(")") { &suffix[..suffix.len() - 1] } else { suffix };
|
let (vals, returning_clause) = if let Some(ret_idx) = suffix.rfind(") RETURNING ") {
|
||||||
|
(&suffix[..ret_idx], Some(&suffix[ret_idx + 2..]))
|
||||||
|
} else if suffix.ends_with(")") {
|
||||||
|
(&suffix[..suffix.len() - 1], None)
|
||||||
|
} else {
|
||||||
|
(suffix, None)
|
||||||
|
};
|
||||||
|
|
||||||
let mut val_tokens = Vec::new();
|
let mut val_tokens = Vec::new();
|
||||||
let mut curr = String::new();
|
let mut curr = String::new();
|
||||||
let mut in_str = false;
|
let mut in_str = false;
|
||||||
@ -119,7 +126,7 @@ impl SqlFormatter {
|
|||||||
for (i, val) in val_tokens.iter().enumerate() {
|
for (i, val) in val_tokens.iter().enumerate() {
|
||||||
let comma = if i < val_tokens.len() - 1 { "," } else { "" };
|
let comma = if i < val_tokens.len() - 1 { "," } else { "" };
|
||||||
|
|
||||||
if val.starts_with("'{") && val.ends_with("}'") {
|
if val.starts_with("'{") && val.ends_with("}'") && val.len() > 4 {
|
||||||
let inner = &val[1..val.len() - 1];
|
let inner = &val[1..val.len() - 1];
|
||||||
// Unescape single quotes from SQL strings
|
// Unescape single quotes from SQL strings
|
||||||
let unescaped = inner.replace("''", "'");
|
let unescaped = inner.replace("''", "'");
|
||||||
@ -146,6 +153,9 @@ impl SqlFormatter {
|
|||||||
}
|
}
|
||||||
self.indent -= 2;
|
self.indent -= 2;
|
||||||
self.push_line(")");
|
self.push_line(")");
|
||||||
|
if let Some(ret) = returning_clause {
|
||||||
|
self.push_line(ret);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.push_line(&s);
|
self.push_line(&s);
|
||||||
}
|
}
|
||||||
@ -168,10 +178,19 @@ impl SqlFormatter {
|
|||||||
self.indent -= 2;
|
self.indent -= 2;
|
||||||
|
|
||||||
if let Some(w) = where_idx {
|
if let Some(w) = where_idx {
|
||||||
|
let where_clause = &after_set[w + 7..];
|
||||||
|
if let Some(ret_idx) = where_clause.find(" RETURNING ") {
|
||||||
self.push_line("WHERE");
|
self.push_line("WHERE");
|
||||||
self.indent += 2;
|
self.indent += 2;
|
||||||
self.push_line(&after_set[w + 7..]);
|
self.push_line(&where_clause[..ret_idx]);
|
||||||
self.indent -= 2;
|
self.indent -= 2;
|
||||||
|
self.push_line(&where_clause[ret_idx + 1..]);
|
||||||
|
} else {
|
||||||
|
self.push_line("WHERE");
|
||||||
|
self.indent += 2;
|
||||||
|
self.push_line(where_clause);
|
||||||
|
self.indent -= 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.push_line(&s);
|
self.push_line(&s);
|
||||||
@ -341,7 +360,7 @@ impl SqlFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::SingleQuotedString(s), .. }) | Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::EscapedStringLiteral(s), .. }) => {
|
Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::SingleQuotedString(s), .. }) | Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::EscapedStringLiteral(s), .. }) => {
|
||||||
if s.starts_with('{') && s.ends_with('}') {
|
if s.starts_with('{') && s.ends_with('}') && s.len() > 2 {
|
||||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(s) {
|
if let Ok(json) = serde_json::from_str::<serde_json::Value>(s) {
|
||||||
if let Ok(pretty) = serde_json::to_string_pretty(&json) {
|
if let Ok(pretty) = serde_json::to_string_pretty(&json) {
|
||||||
let lines: Vec<&str> = pretty.split('\n').collect();
|
let lines: Vec<&str> = pretty.split('\n').collect();
|
||||||
|
|||||||
@ -16,6 +16,7 @@ pub struct ValidationContext<'a> {
|
|||||||
pub reporter: bool,
|
pub reporter: bool,
|
||||||
pub overrides: HashSet<String>,
|
pub overrides: HashSet<String>,
|
||||||
pub parents: Vec<&'a serde_json::Value>,
|
pub parents: Vec<&'a serde_json::Value>,
|
||||||
|
pub response: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ValidationContext<'a> {
|
impl<'a> ValidationContext<'a> {
|
||||||
@ -27,6 +28,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
overrides: HashSet<String>,
|
overrides: HashSet<String>,
|
||||||
extensible: bool,
|
extensible: bool,
|
||||||
reporter: bool,
|
reporter: bool,
|
||||||
|
response: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let effective_extensible = schema.extensible.unwrap_or(extensible);
|
let effective_extensible = schema.extensible.unwrap_or(extensible);
|
||||||
Self {
|
Self {
|
||||||
@ -40,6 +42,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
reporter,
|
reporter,
|
||||||
overrides,
|
overrides,
|
||||||
parents: Vec::new(),
|
parents: Vec::new(),
|
||||||
|
response,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +82,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
reporter,
|
reporter,
|
||||||
overrides,
|
overrides,
|
||||||
parents,
|
parents,
|
||||||
|
response: self.response,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,7 @@ impl Validator {
|
|||||||
let schema_opt = self.db.schemas.get(schema_id);
|
let schema_opt = self.db.schemas.get(schema_id);
|
||||||
|
|
||||||
if let Some(schema) = schema_opt {
|
if let Some(schema) = schema_opt {
|
||||||
|
let response = schema_id.ends_with(".response");
|
||||||
let ctx = ValidationContext::new(
|
let ctx = ValidationContext::new(
|
||||||
&self.db,
|
&self.db,
|
||||||
&schema,
|
&schema,
|
||||||
@ -56,6 +57,7 @@ impl Validator {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
response,
|
||||||
);
|
);
|
||||||
match ctx.validate_scoped() {
|
match ctx.validate_scoped() {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
|
|||||||
@ -179,6 +179,37 @@ impl<'a> ValidationContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.response {
|
||||||
|
let is_external = self.db.executor.punc_external().unwrap_or(false);
|
||||||
|
if let Some(compiled_props) = self.schema.compiled_properties.get() {
|
||||||
|
for (key, sub_schema) in compiled_props {
|
||||||
|
if sub_schema.is_immutable(is_external) && obj.contains_key(key) {
|
||||||
|
result.errors.push(ValidationError {
|
||||||
|
code: "IMMUTABLE_PROPERTY_VIOLATION".to_string(),
|
||||||
|
values: Some(IndexMap::from([
|
||||||
|
("property_name".to_string(), key.to_string()),
|
||||||
|
])),
|
||||||
|
path: self.join_path(key),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Some(props) = &self.schema.properties {
|
||||||
|
for (key, sub_schema) in props {
|
||||||
|
if sub_schema.is_immutable(is_external) && obj.contains_key(key) {
|
||||||
|
result.errors.push(ValidationError {
|
||||||
|
code: "IMMUTABLE_PROPERTY_VIOLATION".to_string(),
|
||||||
|
values: Some(IndexMap::from([
|
||||||
|
("property_name".to_string(), key.to_string()),
|
||||||
|
])),
|
||||||
|
path: self.join_path(key),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if let Some(props) = &self.schema.properties {
|
if let Some(props) = &self.schema.properties {
|
||||||
for (key, sub_schema) in props {
|
for (key, sub_schema) in props {
|
||||||
if self.overrides.contains(key) {
|
if self.overrides.contains(key) {
|
||||||
@ -228,6 +259,7 @@ impl<'a> ValidationContext<'a> {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
self.extensible,
|
self.extensible,
|
||||||
self.reporter,
|
self.reporter,
|
||||||
|
self.response,
|
||||||
);
|
);
|
||||||
|
|
||||||
result.merge(ctx.validate()?);
|
result.merge(ctx.validate()?);
|
||||||
|
|||||||
Reference in New Issue
Block a user