You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): implement Thing-level data schema mapping extraction (#1499)
* feat(core): implement Thing-level data schema mapping extraction
* refactor(core/consumed-thing): simplify valuePath extraction
* refactor(core/comsumed-thing): derive type interactionType from Thing
* refactor(core): introduce DataSchemaMapping type
Make InteractionOutput accepts a DataSchemaMapping object instead of a
strig for the value path. This allows to extend the mapping in the future
with more properties if needed.
* refactor(core/interaction-output): clean up comments and un-wanted cast
* refactor(servient): use type from Thing for dataSchemaMapping property
* refactor(core/wot-impl): simplify mapping handling in consume
* refactor(core/helpers): remove any references in extractDataFromPath
* refactor(core/wot-impl): simplify mapping handling in produce
* test(core/client-test): avoid using any casting
* test(core/server-test): avoid using any casting
* refactor(core/interaction-output): use consistency in arg ordering for ActionInteractionOutput
* docs: minor fixes as requested from code review
Co-authored-by: danielpeintner <daniel.peintner@gmail.com>
* chore: remove leftover files from other branches
---------
Co-authored-by: reluc <relu.cri@gmail.com>
Co-authored-by: Cristiano Aguzzi <relu91@users.noreply.github.com>
Co-authored-by: danielpeintner <daniel.peintner@gmail.com>
Copy file name to clipboardExpand all lines: README.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -319,6 +319,51 @@ Below are small explanations of what they can be used for:
319
319
- Smart Clock: It simply has a property affordance for the time. However, it runs 60 times faster than real-time to allow time-based decisions that can be easily tested.
320
320
- Simple Coffee Machine: This is a simpler simulation of the coffee machine above.
321
321
322
+
## Experimental Features
323
+
324
+
### Data Mapping per Thing
325
+
326
+
node-wot allows configuration of "Data Mapping" which extracts specific values from a Thing's response object (e.g., getting `123` from a wrapper `{ value: 123, timestamp: ... }`). This is useful when the Interaction only cares about an inner value but the Thing returns a wrapper object.
327
+
328
+
This is configured using the experimental node-wot `nw:dataSchemaMapping` vocabulary in the Thing Description. It can be defined at the Thing level or globally injected via the `Servient` configuration:
329
+
330
+
```json
331
+
{
332
+
"title": "MyThing",
333
+
"properties": {
334
+
"status": {
335
+
"type": "integer",
336
+
"forms": [{ "href": "/status" }]
337
+
}
338
+
},
339
+
"nw:dataSchemaMapping": {
340
+
"nw:property": {
341
+
"nw:valuePath": "/value"
342
+
},
343
+
"nw:action": {
344
+
"nw:valuePath": "/value"
345
+
},
346
+
"nw:event": {
347
+
"nw:valuePath": "/value"
348
+
}
349
+
}
350
+
}
351
+
```
352
+
353
+
The `nw:valuePath` supports simple JSON Pointer-like notation (e.g., `/value` or `value/nested`) or dot-notation (e.g., `value.nested`) and is evaluated _after_ content deserialization but _before_ JSON Schema validation. Currently, the `nw:` vocabulary is hardcoded internally and doesn't explicitly require an `@context` definition for node-wot to process it.
354
+
355
+
Servient-level configuration can be added to naturally inject this vocabulary to any consumed or exposed Thing Descriptions without the application needing to do it manually. In the `wot-servient.conf.json` file, you can specify this parameter under the `"servient"` key:
0 commit comments