Skip to content

Commit 982d437

Browse files
committed
add explaination about how to get data without validation
fix #554
1 parent 06a31b1 commit 982d437

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

index.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,17 @@

The InteractionOutput interface

10241024
[=Resolve=] |promise| with <a>[[\value]]a>.
10251025
li>
10261026
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>
10271038
section>
10281039

10291040
<section><h3>The <dfn>arrayBuffer()dfn> functionh3>
@@ -2472,10 +2483,25 @@

ConsumedThing Examples

24722483
// image: ArrayBuffer [0x1 0x2 0x3 0x5 0x15 0x23 ...]
24732484
}
24742485
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>
24752501
<p>
24762502
Finally, the next two examples shows the usage of a {{ReadableStream}} from an {{InteractionOutput}}.
24772503
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)">
24792505
/*{
24802506
"video": {
24812507
"description" : "the video stream of this camera",

0 commit comments

Comments
 (0)