Description
The Thing Description (TD) uses a formal, and hence well-defined model that describes Things. Among other details, Things can have metadata attributes such as name
and id
, semantic metadata attributes such as @context
and @type
(obviously using JSON-LD keywords), interaction definitions in the structured attributes properties
, actions
, and events
, and finally links to other Things or metadata documents in the structured attribute links
.
This formal model and instances of the descriptions are the basis to instantiate software objects in a JavaScript runtime that act as object API to interact with the corresponding Thing. Since not all Things are the same, the object API needs to provide introspection, to check the values of the metadata attributes and which interactions are available. It would be most intuitive, when the software object has the same structure as the TD model. Most of this can easily be defined in WebIDL, as we have a list of identifiers.
Problem 1: the semantic attribute identifiers contain an @
character, and hence are no valid identifiers for JavaScript. The solution should be to access them with the bracket notation, e.g., myThing["@type"]
to introspect the semantic attribute @type
. To my understanding, this would be done using a readonly maplike<key_type, value_type>;
definition for the WebIDL interface
. Others say "named getter" would do the trick. Please clarify. What we lose is the definition of which semantic attributes are to be expected (e.g., @context
and @type
). However, semantic attributes were made purely optional based on community feedback, so maplike
should be fine, no?
Furthermore, the Thing Description must be extensible to be able to evolve other time and to adapt to the many different IoT ecosystems. For this, we allow domain-specific vocabularies, which can easily be imported in the TD document through the JSON-LD @context
keyword. This would add additional semantic attributes that usually would be of the form prefix:term
or could be a full IRI. The colon (:
) also makes them invalid JavaScript identifiers, and hence we also need maplike
for them.
Problem 2: There is a perceived risk of a security leak for some, as the WebIDL does not restrict what attributes will be part of the object API. Yet I fail to see the actual risk here: TDs are well defined and can be validated through multiple mechanisms such as JSON Schema, Shapes/SHACL, or even custom validators of the runtime that also knows which feature exactly is supported. The Scripting API can define a MUST be validated before instantiating the API object. Furthermore, the maplike mechanism defines which types are allowed: key_type
is always a string, value_type
is always a JSON data type -- never a function/callback/Promise/etc.
Summary:
- Does
maplike
enable introspection for the object API?
interface ConsumedThing {
readonly attribute DOMString name;
/* business as usual continues... */
/* introspection for extensible metadata attributes */
readonly maplike<USVString, value_type>;
};
- How to best constrain the
value_type
to JSON data types only? - Can there be a security risk when the API objects are generated from JSON documents that can further be validated against a formal model?