-
Notifications
You must be signed in to change notification settings - Fork 3
Description
First, I am really pleased to see some effort going into making Haystack more usable in the TypeScript / JavaScript world. So huge thanks for taking on the challenge. That said I see the current format as a partial solution to the problem you set out to conquer.
While Hayson achieves to use standard client side JSON encoding / decoding libraries it is hard to use standard client side JSON Validation libraries JSON Schema to process the JSON returned.
Current Hayson from README.md:
"cols": [
"id",
"area",
"dis",
"geoAddr",
"geoCoord",
"geoCountry",
"geoPostalCode",
"geoState",
"geoStreet",
"hq",
"metro",
"occupiedEnd",
"occupiedStart",
"primaryFunction",
"regionRef",
"site",
"store",
"storeNum",
"tz",
"weatherRef",
"yearBuilt",
"mod"
],
"rows": [
{
"id": {
"_kind": "ref",
"val": "p:demo:r:25aa2abd-c365ce5b",
"dis": "Headquarters"
},
"area": {
"_kind": "number",
"val": 140797,
"unit": "ft²"
}
}
]
I was surprised to see each row a key+value mapping instead of an object. How does a paranoid client easily verify that properly formed data is returned from the server? Is the client expected to parse cols to get a list of fields that are required and at run-time lookup each row "key" in an associative array to get the validation rules to apply to part of the "value" and then based on a value within that "value" do another lookup to see how to validate the rest of it? Why require so much run-time processing for validation when static validation rules are faster and easier to manage? Hayson comes so close to the finish line and then stops short of a victory :)
It is common to relate an entry in an array to a class in the code implementation and to code validation there. How would you write the row class without "magic" methods (borrowing the PHP term) / __getattr__ style Python method). What would the Typescript interface look like for row?
Dynamic validation may be possible in languages like JavaScript and Python but is far more ugly / difficult to code in languages like C# / Java.
See Swagger / OpenAPI for how great JSON+JSON-Schema can be when paired. If easy interoperability is a goal for Haystack API then this is likely the gold metal finish.