@@ -1024,6 +1024,17 @@
The InteractionOutput interface
1024
1024
[=Resolve=] |promise| with < a > [[\value]]a > .
1025
1025
li >
1026
1026
ol >
1027
+ < p >
1028
+ While the {{value()}} function provides built-in validation, we recognize that some
1029
+ use cases may require returning values without validation. In such cases, developers
1030
+ can use alternative patterns, such as directly accessing the underlying data
1031
+ using streams or the {{InteractionOutput/arrayBuffer()}} function (See [[[#validation-arraybuffer-example]]] and [[[#stream-example]]]).
1032
+ p >
1033
+ < p class ="advisement " id ="non-validating-value-warning " title ="Implications for not using validation ">
1034
+ < strong > Warning:strong > Disabling validation may introduce risks, particularly when interacting
1035
+ with remote Things, as mismatches in data formats or schema expectations can lead to
1036
+ unforeseen bugs and vulnerabilities. For more details, see the < a data-cite ="wot-thing-description11#behavior-data "> consumer assertionsa > .
1037
+ p >
1027
1038
section >
1028
1039
1029
1040
< section > < h3 > The < dfn > arrayBuffer()dfn > functionh3 >
@@ -2472,10 +2483,25 @@
ConsumedThing Examples
2472
2483
// image: ArrayBuffer [0x1 0x2 0x3 0x5 0x15 0x23 ...]
2473
2484
}
2474
2485
pre >
2486
+ < aside id ="validation-arraybuffer-example " class ="example " title ="Read data without validation using arraybuffer() ">
2487
+ < p >
2488
+ The {{InteractionOutput/arrayBuffer()}} can be used as a shortcut to skip the validation of the {{value()}} function.
2489
+ See < a href ="#non-validating-value-warning "> relevant warninga > for the implications.
2490
+ p >
2491
+ < pre >
2492
+ try{
2493
+ // output is an InteractionOutput instance
2494
+ const value = JSON.parse(Buffer.from(await output.arrayBuffer()).toString())
2495
+ // ... custom validation
2496
+ } catch(ex) {
2497
+ // deal with parsing errors.
2498
+ }
2499
+ pre >
2500
+ aside >
2475
2501
< p >
2476
2502
Finally, the next two examples shows the usage of a {{ReadableStream}} from an {{InteractionOutput}}.
2477
2503
p >
2478
- < pre class ="example " title ="Thing Client API example with readable stream (e.g., video stream) ">
2504
+ < pre id =" stream-example " class ="example " title ="Thing Client API example with readable stream (e.g., video stream) ">
2479
2505
/*{
2480
2506
"video": {
2481
2507
"description" : "the video stream of this camera",
0 commit comments