chore: JSPG Engine tuple decoupling and core routing optimizations

This commit is contained in:
2026-04-13 22:41:32 -04:00
parent 665a821bf9
commit 0017c598e1
57 changed files with 5510 additions and 5166 deletions

View File

@ -5,93 +5,147 @@
"types": [
{
"name": "entity",
"variations": ["entity", "organization", "person", "bot"],
"schemas": [
{
"$id": "entity",
"variations": [
"entity",
"organization",
"person",
"bot"
],
"schemas": {
"entity": {
"type": "object",
"properties": {
"type": { "type": "string" },
"id": { "type": "string" }
"type": {
"type": "string"
},
"id": {
"type": "string"
}
}
}
]
}
},
{
"name": "organization",
"variations": ["organization", "person"],
"schemas": [
{
"$id": "organization",
"variations": [
"organization",
"person"
],
"schemas": {
"organization": {
"type": "entity",
"properties": {
"name": { "type": "string" }
"name": {
"type": "string"
}
}
}
]
}
},
{
"name": "person",
"variations": ["person"],
"schemas": [
{
"$id": "person",
"variations": [
"person"
],
"schemas": {
"person": {
"type": "organization",
"properties": {
"first_name": { "type": "string" }
"first_name": {
"type": "string"
}
}
}
]
}
},
{
"name": "bot",
"variations": ["bot"],
"schemas": [
{
"$id": "bot",
"variations": [
"bot"
],
"schemas": {
"bot": {
"type": "entity",
"properties": {
"model": { "type": "string" }
"model": {
"type": "string"
}
}
}
]
}
}
],
"schemas": [
{
"$id": "family_entity",
"schemas": {
"family_entity": {
"$family": "entity"
}
]
}
},
"tests": [
{
"description": "Matches base entity",
"schema_id": "family_entity",
"data": { "type": "entity", "id": "1" },
"data": {
"type": "entity",
"id": "1"
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Matches descendant person natively",
"schema_id": "family_entity",
"data": { "type": "person", "id": "2", "first_name": "Bob" },
"data": {
"type": "person",
"id": "2",
"first_name": "Bob"
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Missing type fails out immediately",
"schema_id": "family_entity",
"data": { "id": "3", "first_name": "Bob" },
"data": {
"id": "3",
"first_name": "Bob"
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "MISSING_TYPE", "details": { "path": "" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "MISSING_TYPE",
"details": {
"path": ""
}
}
]
}
},
{
"description": "Alias matching failure",
"schema_id": "family_entity",
"data": { "type": "alien", "id": "4" },
"data": {
"type": "alien",
"id": "4"
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "NO_FAMILY_MATCH", "details": { "path": "" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "NO_FAMILY_MATCH",
"details": {
"path": ""
}
}
]
}
}
]
},
@ -101,95 +155,125 @@
"types": [
{
"name": "entity",
"variations": ["entity", "organization", "person", "bot"],
"schemas": [
{
"$id": "entity",
"variations": [
"entity",
"organization",
"person",
"bot"
],
"schemas": {
"entity": {
"type": "object",
"properties": {
"type": { "type": "string" }
"type": {
"type": "string"
}
}
},
{
"$id": "light.entity",
"light.entity": {
"type": "entity",
"properties": {
"kind": { "type": "string" }
"kind": {
"type": "string"
}
}
}
]
}
},
{
"name": "organization",
"variations": ["organization", "person"],
"schemas": [
{
"$id": "organization",
"variations": [
"organization",
"person"
],
"schemas": {
"organization": {
"type": "entity"
},
{
"$id": "light.organization",
"light.organization": {
"type": "light.entity"
}
]
}
},
{
"name": "person",
"variations": ["person"],
"schemas": [
{
"$id": "person",
"variations": [
"person"
],
"schemas": {
"person": {
"type": "organization"
},
{
"$id": "light.person",
"light.person": {
"type": "light.organization"
}
]
}
},
{
"name": "bot",
"variations": ["bot"],
"schemas": [
{
"$id": "bot",
"variations": [
"bot"
],
"schemas": {
"bot": {
"type": "entity"
},
{
"$id": "light.bot",
"light.bot": {
"type": "light.entity"
}
]
}
}
],
"schemas": [
{
"$id": "family_light_org",
"schemas": {
"family_light_org": {
"$family": "light.organization"
}
]
}
},
"tests": [
{
"description": "Matches light.organization exact matrix target",
"schema_id": "family_light_org",
"data": { "type": "organization", "kind": "light" },
"data": {
"type": "organization",
"kind": "light"
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Matches descendant light.person through matrix evaluation",
"schema_id": "family_light_org",
"data": { "type": "person", "kind": "light" },
"data": {
"type": "person",
"kind": "light"
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Structurally fails to route bot (bot is not descendant of organization)",
"schema_id": "family_light_org",
"data": { "type": "bot", "kind": "light" },
"data": {
"type": "bot",
"kind": "light"
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "NO_FAMILY_MATCH", "details": { "path": "" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "NO_FAMILY_MATCH",
"details": {
"path": ""
}
}
]
}
}
]
},
@ -199,72 +283,112 @@
"types": [
{
"name": "widget",
"variations": ["widget"],
"schemas": [
{
"$id": "widget",
"variations": [
"widget"
],
"schemas": {
"widget": {
"type": "object",
"properties": {
"type": { "type": "string" }
"type": {
"type": "string"
}
}
},
{
"$id": "stock.widget",
"stock.widget": {
"type": "widget",
"properties": {
"kind": { "type": "string" },
"amount": { "type": "integer" }
"kind": {
"type": "string"
},
"amount": {
"type": "integer"
}
}
},
{
"$id": "super_stock.widget",
"super_stock.widget": {
"type": "stock.widget",
"properties": {
"super_amount": { "type": "integer" }
"super_amount": {
"type": "integer"
}
}
}
]
}
}
],
"schemas": [
{
"$id": "family_widget",
"schemas": {
"family_widget": {
"$family": "widget"
},
{
"$id": "family_stock_widget",
"family_stock_widget": {
"$family": "stock.widget"
}
]
}
},
"tests": [
{
"description": "Base widget resolves stock widget horizontally",
"schema_id": "family_widget",
"data": { "type": "widget", "kind": "stock", "amount": 5 },
"data": {
"type": "widget",
"kind": "stock",
"amount": 5
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Base widget resolves nested super stock widget natively via descendants crawl",
"schema_id": "family_widget",
"data": { "type": "widget", "kind": "super_stock", "amount": 5, "super_amount": 10 },
"data": {
"type": "widget",
"kind": "super_stock",
"amount": 5,
"super_amount": 10
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "stock.widget explicit family resolves nested super stock via fast path",
"schema_id": "family_stock_widget",
"data": { "type": "widget", "kind": "super_stock", "amount": 5, "super_amount": 10 },
"data": {
"type": "widget",
"kind": "super_stock",
"amount": 5,
"super_amount": 10
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "stock.widget fails when presented an invalid payload constraint",
"schema_id": "family_stock_widget",
"data": { "type": "widget", "kind": "super_stock", "amount": 5, "super_amount": "not_an_int" },
"data": {
"type": "widget",
"kind": "super_stock",
"amount": 5,
"super_amount": "not_an_int"
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "INVALID_TYPE", "details": { "path": "super_amount" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "INVALID_TYPE",
"details": {
"path": "super_amount"
}
}
]
}
}
]
},
@ -274,212 +398,241 @@
"types": [
{
"name": "entity",
"variations": ["entity", "person", "bot"],
"schemas": [
{
"$id": "entity",
"variations": [
"entity",
"person",
"bot"
],
"schemas": {
"entity": {
"type": "object",
"properties": {
"type": { "type": "string" }
"type": {
"type": "string"
}
}
}
]
}
},
{
"name": "person",
"variations": ["person"],
"schemas": [
{
"$id": "person",
"variations": [
"person"
],
"schemas": {
"person": {
"type": "entity"
},
{
"$id": "full.person",
"full.person": {
"type": "person",
"properties": {
"kind": { "type": "string" },
"age": { "type": "integer" }
"kind": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": ["age"]
"required": [
"age"
]
}
]
}
},
{
"name": "bot",
"variations": ["bot"],
"schemas": [
{
"$id": "bot",
"variations": [
"bot"
],
"schemas": {
"bot": {
"type": "entity"
},
{
"$id": "full.bot",
"full.bot": {
"type": "bot",
"properties": {
"kind": { "type": "string" },
"version": { "type": "string" }
"kind": {
"type": "string"
},
"version": {
"type": "string"
}
},
"required": ["version"]
"required": [
"version"
]
}
}
}
],
"schemas": {
"oneOf_union": {
"oneOf": [
{
"type": "full.person"
},
{
"type": "full.bot"
}
]
}
],
"schemas": [
{
"$id": "oneOf_union",
"oneOf": [
{ "type": "full.person" },
{ "type": "full.bot" }
]
}
]
}
},
"tests": [
{
"description": "Throws MISSING_TYPE if discriminator matches neither",
"schema_id": "oneOf_union",
"data": { "kind": "full", "age": 5 },
"data": {
"kind": "full",
"age": 5
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "MISSING_TYPE", "details": { "path": "" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "MISSING_TYPE",
"details": {
"path": ""
}
}
]
}
},
{
"description": "Golden match throws pure structural error exclusively on person",
"schema_id": "oneOf_union",
"data": { "type": "person", "kind": "full", "age": "five" },
"data": {
"type": "person",
"kind": "full",
"age": "five"
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "INVALID_TYPE", "details": { "path": "age" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "INVALID_TYPE",
"details": {
"path": "age"
}
}
]
}
},
{
"description": "Golden matches perfectly",
"schema_id": "oneOf_union",
"data": { "type": "person", "kind": "full", "age": 5 },
"data": {
"type": "person",
"kind": "full",
"age": 5
},
"action": "validate",
"expect": { "success": true }
"expect": {
"success": true
}
},
{
"description": "Fails nicely with NO_ONEOF_MATCH",
"schema_id": "oneOf_union",
"data": { "type": "alien", "kind": "full", "age": 5 },
"data": {
"type": "alien",
"kind": "full",
"age": 5
},
"action": "validate",
"expect": { "success": false, "errors": [ { "code": "NO_ONEOF_MATCH", "details": { "path": "" } } ] }
"expect": {
"success": false,
"errors": [
{
"code": "NO_ONEOF_MATCH",
"details": {
"path": ""
}
}
]
}
}
]
},
{
"description": "JSONB Field Bubble oneOf Discrimination (Promoted IDs)",
"database": {
"schemas": [
{
"$id": "metadata",
"schemas": {
"metadata": {
"type": "object",
"properties": {
"type": { "type": "string" }
"type": {
"type": "string"
}
}
},
{
"$id": "invoice.metadata",
"invoice.metadata": {
"type": "metadata",
"properties": {
"invoice_id": { "type": "integer" }
"invoice_id": {
"type": "integer"
}
},
"required": ["invoice_id"]
"required": [
"invoice_id"
]
},
{
"$id": "payment.metadata",
"payment.metadata": {
"type": "metadata",
"properties": {
"payment_id": { "type": "integer" }
"payment_id": {
"type": "integer"
}
},
"required": ["payment_id"]
"required": [
"payment_id"
]
},
{
"$id": "oneOf_bubble",
"oneOf_bubble": {
"oneOf": [
{ "type": "invoice.metadata" },
{ "type": "payment.metadata" }
{
"type": "invoice.metadata"
},
{
"type": "payment.metadata"
}
]
}
]
}
},
"tests": [
{
"description": "Extracts golden match natively from explicit JSONB type discriminator",
"schema_id": "oneOf_bubble",
"data": { "type": "invoice.metadata", "invoice_id": "nan" },
"data": {
"type": "invoice.metadata",
"invoice_id": "nan"
},
"action": "validate",
"expect": {
"success": false,
"errors": [ { "code": "INVALID_TYPE", "details": { "path": "invoice_id" } } ]
"errors": [
{
"code": "INVALID_TYPE",
"details": {
"path": "invoice_id"
}
}
]
}
},
{
"description": "Valid payload succeeds perfectly in JSONB universe",
"schema_id": "oneOf_bubble",
"data": { "type": "payment.metadata", "payment_id": 123 },
"action": "validate",
"expect": { "success": true }
}
]
},
{
"description": "Standard JSON Schema oneOf",
"database": {
"schemas": [
{
"$id": "oneOf_scalars",
"oneOf": [
{ "type": "integer" },
{ "minimum": 2 }
]
"data": {
"type": "payment.metadata",
"payment_id": 123
},
{
"$id": "oneOf_dedupe",
"oneOf": [
{
"type": "object",
"properties": {
"shared": { "type": "integer" }
},
"required": ["shared"]
},
{
"type": "object",
"properties": {
"shared": { "type": "integer" },
"extra": { "type": "string" }
},
"required": ["shared", "extra"]
}
]
}
]
},
"tests": [
{
"description": "Valid exclusively against first scalar choice",
"schema_id": "oneOf_scalars",
"data": 1,
"action": "validate",
"expect": { "success": true }
},
{
"description": "Fails mathematically if matches both schemas natively",
"schema_id": "oneOf_scalars",
"data": 3,
"action": "validate",
"expect": { "success": false }
},
{
"description": "Deduper merges shared errors dynamically exactly like JSON Schema",
"schema_id": "oneOf_dedupe",
"data": { "shared": "nan" },
"action": "validate",
"expect": {
"success": false,
"errors": [
{ "code": "NO_ONEOF_MATCH", "details": { "path": "" } },
{ "code": "INVALID_TYPE", "details": { "path": "shared" } }
]
"success": true
}
}
]