-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Description
We currently have a lot of schema mapping heuristics, only some of which are documented.
I've made a pass through the code to make a list:
- Singletons can be rendered on collections, they are just wrapped in an array
- Arrays can be rendered on singletons. If the singleton is not the root object, then the first item is rendered (and the rest are preserved, but not shown). If the singleton is the root object, then the array is rendered:
- on the collection with
property=main - If none found, on the first writable collection
- If none found, the first item is rendered instead, just like any other object.
- on the collection with
- Superfluous properties are retained, and even reachable from expressions.
- Nested objects with only one property that is the same as the parent property are "unwrapped". This means that
{foo: {foo: 5}}when rendered on thefooproperty is the same as rendering{foo: 5}. - Primitives can be rendered on objects.
- If the object contains a property with the same name, it is rendered there.
- Failing that, the first writable primitive property
- FFS, there is even a ...scoring function!
- Objects can be rendered on primitives. What is rendered?
- If
Symbol.toPrimitiveexists, it is invoked and the return value is rendered. - If it's a plain object, we render one of its properties on the primitive (preserving the rest):
- If there is only one property, we choose that
- If there is a property that is the same as the primitive's property, we choose that
- If there is a
valueorcontentproperty, we choose that - Failing that, any property with the same datatype.
- If
- Some of the rules above are not applied if the node is a helper variable, i.e. a
<meta>.
As discussed with @karger, not all of these heuristics are useful, and some end up making Mavo's behavior rather unpredictable. Which ones should we drop, and which ones are useful enough to be worth their complexity?
Consider cases where we are rendering data we don't control (e.g. via an API), or the user doesn't have full sense of the data schema (like the shopping list)