-
Notifications
You must be signed in to change notification settings - Fork 15
Description
This is a bit of a pain point on one of my projects, the solid-react-sdk. We provide examples of how to do certain things, such as notification creation or file / game creation. In these cases we want to do two things:
- Fetch "objects" or object-like structures as defined by a shape (in our case, shex)
- Validate that these objects are what they say they are
Right now, these means a lot of common, repeated loops.
What we've done so far is create JSON structures representing a simple version of a shape. This isn't great practice, but you may see why we do this soon. We need to loop over something in order to create multiple ldflex expressions, one per property in the shape, then execute and combine together into one JS object.
These JSON structures are not good practice, since they are separate from the actual shapes, not used for validation, and are custom. That being said, it's more difficult to loop over ShEx or Shacl shapes and check each predicate name, for various reasons.
We also have to validate the data first - usually we do this with ShEx (though we have put together some Shacl experiments as well) and it's a bit of a pain as we have to fetch the data twice - the ShEx validator fetches once, as it takes a path as a param and does the fetch internally, and returns the valid paths, not the valid data. Then we use LDFlex to fetch the valid document URLs to build our objects as described above.
In a perfect world, I would like to be able to do something like
solid.data[subject].shape('<IRI to shape>')
and have it return me a JS object contain the fields, or throw an error if it fails validation
In an even more perfect world I could do this with a list of subjects and get an array of JS objects that all pass validation :)