Repository navigation
schema-calc v0.1.0
The first release of Schema Calc: a compiler from bounded decimal equations to ordinary Draft 2020-12 JSON Schema, so a stock validator in any language can reject a one-cent error. Try it in any browser; nothing is sent to a server.
Check it without Schema Calc
Python 3 and jsonschema only, in an empty directory:
python3 -m pip install jsonschema==4.25.1
base=https://github.com/fMindstormer/schema-calc/releases/download/v0.1.0
for f in validate.py invoice.schema.json invoice.valid.json invoice.invalid.json; do curl -fLO "$base/$f"; done
python3 validate.py invoice.schema.json invoice.valid.json invoice.invalid.jsonACCEPT invoice.valid.json
REJECT invoice.invalid.json
Results
| invoice contract | total = subtotal + shipping - discount, 4 integer and 2 fractional digits |
| invoice schema | 41,232 B, from 284,300 B for the first construction, same input and bounds |
| same contract, tally encoding | 3,569 B schema, but the record grows from 75 to 676 B |
| generated corpus, each checked in Ajv 8.20.0 and jsonschema 4.25.1 | 24,469 flat and 24,473 tally checks |
| playground handoff (CI) | browser downloads validated in a fresh venv: accepted and one-cent records, both encodings |
Smallest is not fastest: against the larger mixed-radix schema, the packed default validates an invoice in about 6.25 µs instead of 5.19 µs in Ajv, and 24.98 ms instead of 1.58 ms in Python (measurements).
Files
invoice.schema.json is the compiled invoice contract; invoice.valid.json and invoice.invalid.json are the correct record and the one a cent off. validate.py is the standalone validator: it needs only jsonschema and never imports the compiler. schema-calc-0.1.0.zip is the source, with a MANIFEST.sha256 inside; schema-calc-0.1.0.zip.sha256 is its checksum and SHA256SUMS covers every file.
Scope
Sums and differences of nonnegative decimal strings: up to 8 fields, 8 equations and 12 digits. No multiplication, comparisons or nested objects yet. A research prototype; it is not published to npm. See the README for the computational model, the proof and the compression steps.
