hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit 9d40dc38cc120a7fb073c3a7e2eef16fa0c66476
parent b025df0653f17364b4b7b1245f91779c769746f1
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 03:35:35 +0000

spec: bind quantity and money representations

Diffstat:
Aschemas/hyf_v1_jev/domain_manifest.json | 30++++++++++++++++++++++++++++++
Aschemas/hyf_v1_jev/examples/invalid/money.bad_basis.json | 7+++++++
Aschemas/hyf_v1_jev/examples/invalid/quantity.bad_dimension.json | 8++++++++
Aschemas/hyf_v1_jev/examples/invalid/quantity.known_without_value.json | 8++++++++
Aschemas/hyf_v1_jev/examples/invalid/quantity.overflow.json | 8++++++++
Aschemas/hyf_v1_jev/examples/valid/money.known.json | 15+++++++++++++++
Aschemas/hyf_v1_jev/examples/valid/money.unknown.json | 3+++
Aschemas/hyf_v1_jev/examples/valid/quantity.approximate.json | 9+++++++++
Aschemas/hyf_v1_jev/examples/valid/quantity.exact.json | 9+++++++++
Aschemas/hyf_v1_jev/examples/valid/quantity.unknown.json | 3+++
Aschemas/hyf_v1_jev/money.schema.json | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aschemas/hyf_v1_jev/quantity.schema.json | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/test_hyf.mojo | 38++++++++++++++++++++++++++++++++++++++
13 files changed, 285 insertions(+), 0 deletions(-)

diff --git a/schemas/hyf_v1_jev/domain_manifest.json b/schemas/hyf_v1_jev/domain_manifest.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "spec_id": "hyf_v1_jev", + "family": "domain_representations", + "bindings": [ + { + "schema": "quantity.schema.json", + "valid": [ + "examples/valid/quantity.exact.json", + "examples/valid/quantity.approximate.json", + "examples/valid/quantity.unknown.json" + ], + "invalid": [ + "examples/invalid/quantity.known_without_value.json", + "examples/invalid/quantity.overflow.json", + "examples/invalid/quantity.bad_dimension.json" + ] + }, + { + "schema": "money.schema.json", + "valid": [ + "examples/valid/money.known.json", + "examples/valid/money.unknown.json" + ], + "invalid": [ + "examples/invalid/money.bad_basis.json" + ] + } + ] +} diff --git a/schemas/hyf_v1_jev/examples/invalid/money.bad_basis.json b/schemas/hyf_v1_jev/examples/invalid/money.bad_basis.json @@ -0,0 +1,7 @@ +{ + "state": "known", + "amount": "100", + "scale": 2, + "currency": "CAD", + "basis": "per_kg_approx" +} diff --git a/schemas/hyf_v1_jev/examples/invalid/quantity.bad_dimension.json b/schemas/hyf_v1_jev/examples/invalid/quantity.bad_dimension.json @@ -0,0 +1,8 @@ +{ + "state": "known", + "value": "1", + "scale": 0, + "unit": "kg", + "dimension": "weight", + "qualifier": "exact" +} diff --git a/schemas/hyf_v1_jev/examples/invalid/quantity.known_without_value.json b/schemas/hyf_v1_jev/examples/invalid/quantity.known_without_value.json @@ -0,0 +1,8 @@ +{ + "state": "known", + "value": "1", + "scale": "high", + "unit": "kg", + "dimension": "mass", + "qualifier": "exact" +} diff --git a/schemas/hyf_v1_jev/examples/invalid/quantity.overflow.json b/schemas/hyf_v1_jev/examples/invalid/quantity.overflow.json @@ -0,0 +1,8 @@ +{ + "state": "known", + "value": "99999999999999999999999", + "scale": 0, + "unit": "kg", + "dimension": "mass", + "qualifier": "exact" +} diff --git a/schemas/hyf_v1_jev/examples/valid/money.known.json b/schemas/hyf_v1_jev/examples/valid/money.known.json @@ -0,0 +1,15 @@ +{ + "state": "known", + "amount": "350", + "scale": 2, + "currency": "CAD", + "basis": "per_unit", + "fees": [ + { + "kind": "delivery", + "amount": "500", + "scale": 2, + "currency": "CAD" + } + ] +} diff --git a/schemas/hyf_v1_jev/examples/valid/money.unknown.json b/schemas/hyf_v1_jev/examples/valid/money.unknown.json @@ -0,0 +1,3 @@ +{ + "state": "unknown" +} diff --git a/schemas/hyf_v1_jev/examples/valid/quantity.approximate.json b/schemas/hyf_v1_jev/examples/valid/quantity.approximate.json @@ -0,0 +1,9 @@ +{ + "state": "known", + "value": "80", + "scale": 0, + "unit": "lb", + "dimension": "mass", + "qualifier": "approximate", + "original_expression": "about 80 lb" +} diff --git a/schemas/hyf_v1_jev/examples/valid/quantity.exact.json b/schemas/hyf_v1_jev/examples/valid/quantity.exact.json @@ -0,0 +1,9 @@ +{ + "state": "known", + "value": "8000", + "scale": 2, + "unit": "kg", + "dimension": "mass", + "qualifier": "exact", + "original_expression": "80 kg" +} diff --git a/schemas/hyf_v1_jev/examples/valid/quantity.unknown.json b/schemas/hyf_v1_jev/examples/valid/quantity.unknown.json @@ -0,0 +1,3 @@ +{ + "state": "unknown" +} diff --git a/schemas/hyf_v1_jev/money.schema.json b/schemas/hyf_v1_jev/money.schema.json @@ -0,0 +1,83 @@ +{ + "$comment": "canonical domain Money/PriceCondition; unknown is distinct from zero", + "type": "object", + "properties": { + "state": { + "type": "string", + "enum": [ + "known", + "unknown" + ] + }, + "amount": { + "type": [ + "string", + "null" + ], + "maxLength": 19 + }, + "scale": { + "type": [ + "integer", + "null" + ], + "minimum": 0, + "maximum": 9 + }, + "currency": { + "type": [ + "string", + "null" + ] + }, + "basis": { + "type": [ + "string", + "null" + ], + "enum": [ + "per_unit", + "per_pack", + "per_order", + "unknown", + null + ] + }, + "fees": { + "type": [ + "array", + "null" + ], + "items": { + "type": "object", + "properties": { + "kind": { + "type": "string" + }, + "amount": { + "type": "string", + "maxLength": 19 + }, + "scale": { + "type": "integer", + "minimum": 0 + }, + "currency": { + "type": "string" + } + }, + "required": [ + "kind", + "amount", + "scale", + "currency" + ], + "additionalProperties": false + } + } + }, + "required": [ + "state" + ], + "additionalProperties": false +} diff --git a/schemas/hyf_v1_jev/quantity.schema.json b/schemas/hyf_v1_jev/quantity.schema.json @@ -0,0 +1,64 @@ +{ + "$comment": "canonical domain Quantity; wire carries reported value/unit/qualifier, normalization derives scale/dimension", + "type": "object", + "properties": { + "state": { + "type": "string", + "enum": [ + "known", + "unknown" + ] + }, + "value": { + "type": [ + "string", + "null" + ], + "maxLength": 19 + }, + "scale": { + "type": [ + "integer", + "null" + ], + "minimum": 0, + "maximum": 9 + }, + "unit": { + "type": [ + "string", + "null" + ] + }, + "dimension": { + "type": [ + "string", + "null" + ], + "enum": [ + "mass", + "volume", + "count", + "unknown", + null + ] + }, + "qualifier": { + "type": "string", + "enum": [ + "exact", + "approximate" + ] + }, + "original_expression": { + "type": [ + "string", + "null" + ] + } + }, + "required": [ + "state" + ], + "additionalProperties": false +} diff --git a/tests/test_hyf.mojo b/tests/test_hyf.mojo @@ -1065,5 +1065,43 @@ def test_wire_operation_schemas_accept_valid_and_reject_invalid() raises: assert_true(validated >= 6) +def test_domain_representation_schemas_accept_valid_and_reject_invalid() raises: + var manifest = _wire_schema_json("domain_manifest.json") + assert_equal(manifest["spec_id"].string_value(), "hyf_v1_jev") + var valid_count = 0 + for binding in manifest["bindings"].array_items(): + var schema = _wire_schema_json(binding["schema"].string_value()) + for rel in binding["valid"].array_items(): + var doc = loads( + ( + _dir_of_current_file() + / ".." + / "schemas" + / "hyf_v1_jev" + / rel.string_value() + ).read_text() + ) + assert_true( + validate(doc, schema).valid, + "valid domain example failed schema: " + rel.string_value(), + ) + valid_count += 1 + for rel in binding["invalid"].array_items(): + var doc = loads( + ( + _dir_of_current_file() + / ".." + / "schemas" + / "hyf_v1_jev" + / rel.string_value() + ).read_text() + ) + assert_true( + not validate(doc, schema).valid, + "invalid domain example unexpectedly passed: " + rel.string_value(), + ) + assert_equal(valid_count, 5) + + def main() raises: TestSuite.discover_tests[__functions_in_module()]().run()