-
Notifications
You must be signed in to change notification settings - Fork 28
Does Scripting need a dataType attribute for Property, Action, and Event #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes - I am thinking how could we simplify this and how much should we push to the scripts to handle. Some comments.
I prefer to have input from a full stack implementation experience based on a stable TD in order to decide which design is best and which use cases will be supported in scripting. |
I would say this is even a bug in the FPWD, as we had this before and it is quite essential to define the data type of a Property, as its value/state must be handled by the runtime.
In Thus, I assume that I hope with this everyone can implement this aspect of the FPWD for the PlugFest. Note that in the TD-TF, this part is being changed to the JSON Schema Ontology version anyway, which is different from the example above. |
@mkovatsc |
BTW ThingPropertyInit already supports semantic types on the property. What other types do we still need there, based on what universal type system? |
The "semantic types" are for adding vocabulary items to the Our problem is that JavaScript does not provide a declarative mechanism for variables. We could pass some kind of prototype with sample values, but how to pass restrictions like minimum and maximum? At the moment, the idea is to use the TD definitions and pass them to the WoT Runtime to instantiate the right type and being able to do validation and reject before bothering the script with invalid inputData. |
Right, but it does provide procedural one. Besides, we also heed to other languages in the API design, so it is safer to bet on procedural methods.
No, the purpose of the ExposedThing interface is to programmatically define a Thing and a TD. If it is for just assembling a TD from fragments, then please use a string manipulation library and let's forget the scripting API. |
What I am saying is that for now we do not have a better solution than passing the TD definition, because JavaScript does not have a declarative way to specify a prototype. What we need are sufficient descriptors that can be passed in the Thing*Init objects. defineProperty() comes with insufficient descriptors. JSON Schema is again only close, since it has the vocabulary, but is JSON and not a JS object that we can pass. |
But then let's carry that idea to the end and use TD to define a Thing object entirely, instead of specifying some parts with TD fragments and other parts with functions of the API... |
Okay, two options:
I like the second option more. Is using JSON Schema as JS obejcts a possibility? In the TD, we use a Linked Data version ("JSON Schema Ontology") of JSON Schema that can generate normal JSON Schema. |
I am fine with Declarative would be the first approach, e.g.: typedef USVString ThingDescription;
Promise<ExposedThing> create(ThingDescription description); Of course the name However, if the TD would support including or linking the code for those handlers in the TD (analogously how web pages include scripts), then we would not even need any scripting API. This would resemble the current web model most. It would also simplify the deployment model, as we'll only talk about fetching/consuming a TD... and we could leverage a lot of work from the Web Platform. Just my 2 cents. |
The other way is to specify a fully procedural API, i.e. everything initialized with standardized items, instead of TD fragments. Whatever is specified in the TD, is translated to dictionaries etc in the Scripting API. |
Your Web page analogy misses the aspect of server-side code, which is the problem we are discussing for ExposedThings. Scripts in TDs would only be code-on-demand that is shipped to the WoT Client. |
No, it doesn't miss. If the TD of a server contains [handler] code or links to code that can be fetched, then a WoT runtime can instantiate an ExposedThing just based on the model (TD).
I'm not sure I understand that. Could you explain more or give an example? |
Code enclosed or linked from HTML documents is code that is shipped to the client and executed there (REST "code-on-demand"). Server code stays on the server and most want to hide it -- just provide a RESTful interface, the server implementation is no client's business (also REST "layered system"). The TD is definitely analogous to HTML: it contains metadata, some of which can be information similar to HTML content, and links and forms that describe how to formulate requests for the application. Putting server-side code in the TD breaks the HTML analogy; we end up with something like PHP or JSP -- could be a nice concept to follow! At the moment I see a lot of half-baked concepts put together, which confuses us and definitely people on the outside and future users. If I find the time, I can try to separate the different approach we are currently using. |
The gain in permitting scripts in a TD would be:
We have shortly discussed the subject on today's TD call and there were no obvious heavy counter-arguments; we agreed to discuss this topic at TPAC. |
It's just a different target. The analogy is in extending a declarative markup with scripts, not in the deployment pattern. So I would not call it a break. You're right that scripts would be part of TD's meant for server Things and client Things will not have scripts/links. Earlier we've been discussing the possibility of including manifest-like information with TDs. Similarly, scripts could be included as well, linked from the TD. It is true this would only help ExposedThing interface, which IMHO has less priority than the client interface. One could always encapsulate an exposed Thing's implementation and just serve the WoT interface. Later on we might open up and standardize how to build exposed Things, how to make protocol bindings etc, but first we need to get ConsumedThing right. |
The TD description provides along with the interaction name (for property, action, and event) also a fieldName for the according input or output datatype (see Property, Action, Event).
The current scripting API does not have such an attribute.
I think having these information is useful and needed. Let's suppose to have a TD that is created based on the following type for RGB
Based on this information additional consistency checks can be applied and would refuse arrays of 4 items or with wrong ranges such as.
[-1, 22, 34, 800]
Hence ThingPropertyInit besides
name
and other attributes should also haveoutputData
attribute. Similarly inits for actions and events....The text was updated successfully, but these errors were encountered: