lib!: change CloudEvent to use direct object notation and get/set properties (#172)
This commit makes a substantial change to the API, changing the CloudEvent class to accept properties as an object in the constructor. For example: ```js const CloudEvent = require('cloudevents-sdk'); // all event properties except extensions may be set in the constructor const event = new CloudEvent({ source: 'http://my.event.source', type: 'test-event-type' }); // get and set all properties standard property notation console.log(event.time); // the event timestamp event.subject = 'my event subject'; ``` Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
parent
57991e1e1b
commit
abc114b24e
|
@ -9,7 +9,8 @@
|
||||||
"excludePattern": "(node_modules/|docs|examples|coverage|test)"
|
"excludePattern": "(node_modules/|docs|examples|coverage|test)"
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"plugins/markdown"
|
"plugins/markdown",
|
||||||
|
"plugins/ignore-typedef"
|
||||||
],
|
],
|
||||||
"templates": {
|
"templates": {
|
||||||
"referenceTitle": "cloudevents-sdk",
|
"referenceTitle": "cloudevents-sdk",
|
||||||
|
|
|
@ -78,11 +78,9 @@ const { CloudEvent, HTTPEmitter } = require("cloudevents-sdk");
|
||||||
const v1Emitter = new HTTPEmitter({
|
const v1Emitter = new HTTPEmitter({
|
||||||
url: "https://cloudevents.io/example"
|
url: "https://cloudevents.io/example"
|
||||||
});
|
});
|
||||||
const event = new CloudEvent()
|
const event = new CloudEvent({
|
||||||
.type(type)
|
type, source, data
|
||||||
.source(source)
|
});
|
||||||
.time(new Date())
|
|
||||||
.data(data)
|
|
||||||
|
|
||||||
// By default, the emitter will send binary events
|
// By default, the emitter will send binary events
|
||||||
v1Emitter.send(event).then((response) => {
|
v1Emitter.send(event).then((response) => {
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,7 +96,8 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="class-description">
|
<div class="class-description">
|
||||||
<p>A class that receives binary CloudEvents over HTTP. This class can be used
|
<p>/**
|
||||||
|
A class that receives binary CloudEvents over HTTP. This class can be used
|
||||||
if you know that all incoming events will be using binary transport. If
|
if you know that all incoming events will be using binary transport. If
|
||||||
events can come as either binary or structured, use {HTTPReceiver}.</p>
|
events can come as either binary or structured, use {HTTPReceiver}.</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -228,7 +229,7 @@ events can come as either binary or structured, use {HTTPReceiver}.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line18">line 18</a>
|
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line20">line 20</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -422,7 +423,7 @@ Cloud Event specification for this receiver.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line35">line 35</a>
|
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line37">line 37</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -629,7 +630,7 @@ instance if it conforms to the Cloud Event specification for this receiver.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line48">line 48</a>
|
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line50">line 50</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
3055
docs/CloudEvent.html
3055
docs/CloudEvent.html
File diff suppressed because it is too large
Load Diff
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,7 +96,12 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="class-description">
|
<div class="class-description">
|
||||||
<p>A class which is capable of sending binary and structured events using
|
<p>const {
|
||||||
|
SPEC_V03,
|
||||||
|
SPEC_V1
|
||||||
|
} = require("./constants");</p>
|
||||||
|
<p>/**
|
||||||
|
A class which is capable of sending binary and structured events using
|
||||||
the CloudEvents HTTP Protocol Binding specification.</p>
|
the CloudEvents HTTP Protocol Binding specification.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,7 +96,8 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="class-description">
|
<div class="class-description">
|
||||||
<p>A class to receive a CloudEvent from an HTTP POST request.</p>
|
<p>/**
|
||||||
|
A class to receive a CloudEvent from an HTTP POST request.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,7 +96,20 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="class-description">
|
<div class="class-description">
|
||||||
<p>A class for sending {CloudEvent} instances over HTTP.</p>
|
<p>const {
|
||||||
|
DATA_ATTRIBUTE,
|
||||||
|
DEFAULT_CE_CONTENT_TYPE,
|
||||||
|
HEADERS,
|
||||||
|
HEADER_CONTENT_TYPE
|
||||||
|
} = require("./constants.js");</p>
|
||||||
|
<p>const defaults = {
|
||||||
|
[HEADERS]: {
|
||||||
|
[HEADER_CONTENT_TYPE]: DEFAULT_CE_CONTENT_TYPE
|
||||||
|
},
|
||||||
|
method: "POST"
|
||||||
|
};</p>
|
||||||
|
<p>/**
|
||||||
|
A class for sending {CloudEvent} instances over HTTP.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,7 +96,8 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="class-description">
|
<div class="class-description">
|
||||||
<p>A utility class used to receive structured CloudEvents
|
<p>/**
|
||||||
|
A utility class used to receive structured CloudEvents
|
||||||
over HTTP.</p>
|
over HTTP.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -228,7 +229,7 @@ versions 0.3 and 1.0 (default).</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line19">line 19</a>
|
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line21">line 21</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -433,7 +434,7 @@ specification version supported by this instance.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line36">line 36</a>
|
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line38">line 38</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -639,7 +640,7 @@ specification version supported by this instance.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line48">line 48</a>
|
<a href="bindings_http_receiver_structured.js.html">bindings/http/receiver_structured.js</a>, <a href="bindings_http_receiver_structured.js.html#line50">line 50</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -126,10 +126,10 @@ class BinaryHTTPEmitter {
|
||||||
*/
|
*/
|
||||||
constructor(version) {
|
constructor(version) {
|
||||||
if (version === SPEC_V1) {
|
if (version === SPEC_V1) {
|
||||||
this.headerByGetter = EmitterV1;
|
this.headerParserMap = EmitterV1;
|
||||||
this.extensionPrefix = BINARY_HEADERS_1.EXTENSIONS_PREFIX;
|
this.extensionPrefix = BINARY_HEADERS_1.EXTENSIONS_PREFIX;
|
||||||
} else if (version === SPEC_V03) {
|
} else if (version === SPEC_V03) {
|
||||||
this.headerByGetter = EmitterV3;
|
this.headerParserMap = EmitterV3;
|
||||||
this.extensionPrefix = BINARY_HEADERS_03.EXTENSIONS_PREFIX;
|
this.extensionPrefix = BINARY_HEADERS_03.EXTENSIONS_PREFIX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,11 +148,11 @@ class BinaryHTTPEmitter {
|
||||||
const config = { ...options, ...defaults };
|
const config = { ...options, ...defaults };
|
||||||
const headers = config[HEADERS];
|
const headers = config[HEADERS];
|
||||||
|
|
||||||
Object.keys(this.headerByGetter)
|
this.headerParserMap.forEach((parser, getterName) => {
|
||||||
.filter((getter) => cloudevent[getter]())
|
const value = cloudevent[getterName];
|
||||||
.forEach((getter) => {
|
if (value) {
|
||||||
const header = this.headerByGetter[getter];
|
headers[parser.headerName] = parser.parse(value);
|
||||||
headers[header.name] = header.parser(cloudevent[getter]());
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set the cloudevent payload
|
// Set the cloudevent payload
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -169,11 +169,11 @@ class HTTPEmitter {
|
||||||
headers(event) {
|
headers(event) {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
Object.keys(this.binary.headerByGetter)
|
this.binary.headerParserMap.forEach((parser, getterName) => {
|
||||||
.filter((getter) => event[getter]())
|
const value = event[getterName];
|
||||||
.forEach((getter) => {
|
if (value) {
|
||||||
const header = this.binary.headerByGetter[getter];
|
headers[parser.headerName] = parser.parse(value);
|
||||||
headers[header.name] = header.parser(event[getter]());
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,6 +96,8 @@ const ReceiverV3 = require("./v03/receiver_binary_0_3.js");
|
||||||
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
|
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
|
||||||
const { check, parse } = require("./validation/binary.js");
|
const { check, parse } = require("./validation/binary.js");
|
||||||
|
|
||||||
|
/** @typedef {import("../../cloudevent")} CloudEvent */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that receives binary CloudEvents over HTTP. This class can be used
|
* A class that receives binary CloudEvents over HTTP. This class can be used
|
||||||
* if you know that all incoming events will be using binary transport. If
|
* if you know that all incoming events will be using binary transport. If
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -96,6 +96,8 @@ const ReceiverV3 = require("./v03/receiver_structured_0_3.js");
|
||||||
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
|
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
|
||||||
const { check, parse } = require("./validation/structured.js");
|
const { check, parse } = require("./validation/structured.js");
|
||||||
|
|
||||||
|
/** @typedef {import("../../cloudevent")} CloudEvent */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class used to receive structured CloudEvents
|
* A utility class used to receive structured CloudEvents
|
||||||
* over HTTP.
|
* over HTTP.
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -92,63 +92,39 @@
|
||||||
<article>
|
<article>
|
||||||
<pre class="prettyprint source linenums"><code>const {
|
<pre class="prettyprint source linenums"><code>const {
|
||||||
HEADER_CONTENT_TYPE,
|
HEADER_CONTENT_TYPE,
|
||||||
BINARY_HEADERS_03
|
BINARY_HEADERS_03 : {
|
||||||
|
CONTENT_ENCODING,
|
||||||
|
SUBJECT,
|
||||||
|
TYPE,
|
||||||
|
SPEC_VERSION,
|
||||||
|
SOURCE,
|
||||||
|
ID,
|
||||||
|
TIME,
|
||||||
|
SCHEMA_URL
|
||||||
|
}
|
||||||
} = require("../constants.js");
|
} = require("../constants.js");
|
||||||
|
|
||||||
const passThroughParser = (v) => v;
|
function parser(header, parser = (v) => v) {
|
||||||
|
return { headerName: header, parse: parser };
|
||||||
|
}
|
||||||
|
const passThroughParser = parser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility object used to retrieve the header names for a CloudEvent
|
* A utility Map used to retrieve the header names for a CloudEvent
|
||||||
* using the CloudEvent getter function.
|
* using the CloudEvent getter function.
|
||||||
*/
|
*/
|
||||||
const headerByGetter = {
|
const headerMap = new Map();
|
||||||
getDataContentType: {
|
headerMap.set("dataContentType", passThroughParser(HEADER_CONTENT_TYPE));
|
||||||
name: HEADER_CONTENT_TYPE,
|
headerMap.set("dataContentEncoding", passThroughParser(CONTENT_ENCODING));
|
||||||
parser: passThroughParser
|
headerMap.set("subject", passThroughParser(SUBJECT));
|
||||||
},
|
headerMap.set("type", passThroughParser(TYPE));
|
||||||
|
headerMap.set("specversion", passThroughParser(SPEC_VERSION));
|
||||||
|
headerMap.set("source", passThroughParser(SOURCE));
|
||||||
|
headerMap.set("id", passThroughParser(ID));
|
||||||
|
headerMap.set("time", passThroughParser(TIME));
|
||||||
|
headerMap.set("schemaURL", passThroughParser(SCHEMA_URL));
|
||||||
|
|
||||||
getDataContentEncoding: {
|
module.exports = headerMap;
|
||||||
name: BINARY_HEADERS_03.CONTENT_ENCODING,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSubject: {
|
|
||||||
name: BINARY_HEADERS_03.SUBJECT,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getType: {
|
|
||||||
name: BINARY_HEADERS_03.TYPE,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSpecversion: {
|
|
||||||
name: BINARY_HEADERS_03.SPEC_VERSION,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSource: {
|
|
||||||
name: BINARY_HEADERS_03.SOURCE,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getId: {
|
|
||||||
name: BINARY_HEADERS_03.ID,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getTime: {
|
|
||||||
name: BINARY_HEADERS_03.TIME,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSchemaurl: {
|
|
||||||
name: BINARY_HEADERS_03.SCHEMA_URL,
|
|
||||||
parser: passThroughParser
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = headerByGetter;
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -92,58 +92,37 @@
|
||||||
<article>
|
<article>
|
||||||
<pre class="prettyprint source linenums"><code>const {
|
<pre class="prettyprint source linenums"><code>const {
|
||||||
HEADER_CONTENT_TYPE,
|
HEADER_CONTENT_TYPE,
|
||||||
BINARY_HEADERS_1
|
BINARY_HEADERS_1 : {
|
||||||
|
SUBJECT,
|
||||||
|
TYPE,
|
||||||
|
SPEC_VERSION,
|
||||||
|
SOURCE,
|
||||||
|
ID,
|
||||||
|
TIME,
|
||||||
|
DATA_SCHEMA
|
||||||
|
}
|
||||||
} = require("../constants.js");
|
} = require("../constants.js");
|
||||||
|
|
||||||
const passThroughParser = (v) => v;
|
function parser(header, parser = (v) => v) {
|
||||||
|
return { headerName: header, parse: parser };
|
||||||
|
}
|
||||||
|
const passThroughParser = parser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility object used to retrieve the header names for a CloudEvent
|
* A utility Map used to retrieve the header names for a CloudEvent
|
||||||
* using the CloudEvent getter function.
|
* using the CloudEvent getter function.
|
||||||
*/
|
*/
|
||||||
const headerByGetter = {
|
const headerMap = new Map();
|
||||||
getDataContentType: {
|
headerMap.set("dataContentType", passThroughParser(HEADER_CONTENT_TYPE));
|
||||||
name: HEADER_CONTENT_TYPE,
|
headerMap.set("subject", passThroughParser(SUBJECT));
|
||||||
parser: passThroughParser
|
headerMap.set("type", passThroughParser(TYPE));
|
||||||
},
|
headerMap.set("specversion", passThroughParser(SPEC_VERSION));
|
||||||
|
headerMap.set("source", passThroughParser(SOURCE));
|
||||||
|
headerMap.set("id", passThroughParser(ID));
|
||||||
|
headerMap.set("time", passThroughParser(TIME));
|
||||||
|
headerMap.set("dataSchema", passThroughParser(DATA_SCHEMA));
|
||||||
|
|
||||||
getSubject: {
|
module.exports = headerMap;
|
||||||
name: BINARY_HEADERS_1.SUBJECT,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getType: {
|
|
||||||
name: BINARY_HEADERS_1.TYPE,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSpecversion: {
|
|
||||||
name: BINARY_HEADERS_1.SPEC_VERSION,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getSource: {
|
|
||||||
name: BINARY_HEADERS_1.SOURCE,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getId: {
|
|
||||||
name: BINARY_HEADERS_1.ID,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getTime: {
|
|
||||||
name: BINARY_HEADERS_1.TIME,
|
|
||||||
parser: passThroughParser
|
|
||||||
},
|
|
||||||
|
|
||||||
getDataschema: {
|
|
||||||
name: BINARY_HEADERS_1.DATA_SCHEMA,
|
|
||||||
parser: passThroughParser
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = headerByGetter;
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -91,8 +91,8 @@
|
||||||
<section>
|
<section>
|
||||||
<article>
|
<article>
|
||||||
<pre class="prettyprint source linenums"><code>/**
|
<pre class="prettyprint source linenums"><code>/**
|
||||||
* @typedef {import("ajv").ErrorObject} ErrorObject
|
|
||||||
* @ignore
|
* @ignore
|
||||||
|
* @typedef {import("ajv").ErrorObject} ErrorObject
|
||||||
* */
|
* */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -90,34 +90,263 @@
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<article>
|
<article>
|
||||||
<pre class="prettyprint source linenums"><code>const Spec = require("./bindings/http/v1/spec_1.js");
|
<pre class="prettyprint source linenums"><code>const Spec1 = require("./bindings/http/v1/spec_1.js");
|
||||||
|
const Spec03 = require("./bindings/http/v03/spec_0_3.js");
|
||||||
const Formatter = require("./formats/json/formatter.js");
|
const Formatter = require("./formats/json/formatter.js");
|
||||||
|
|
||||||
|
const { SPEC_V1, SPEC_V03 } = require("./bindings/http/constants.js");
|
||||||
|
const { isBinary } = require("./bindings/http/validation/fun.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance of a CloudEvent.
|
* An CloudEvent describes event data in common formats to provide
|
||||||
|
* interopability across services, platforms and systems.
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
|
||||||
*/
|
*/
|
||||||
class CloudEvent {
|
class CloudEvent {
|
||||||
/**
|
/**
|
||||||
* Creates a new CloudEvent instance
|
* Creates a new CloudEvent instance
|
||||||
* @param {Spec} [userSpec] A CloudEvent version specification
|
* @param {object} options CloudEvent properties as a simple object
|
||||||
* @param {Formatter} [userFormatter] Converts the event into a readable string
|
* @param {string} options.source Identifies the context in which an event happened as a URI reference
|
||||||
|
* @param {string} options.type Describes the type of event related to the originating occurrence
|
||||||
|
* @param {string} [options.id] A unique ID for this event - if not supplied, will be autogenerated
|
||||||
|
* @param {string} [options.time] A timestamp for this event. May also be provided as a Date
|
||||||
|
* @param {string} [options.subject] Describes the subject of the event in the context of the event producer
|
||||||
|
* @param {string} [options.dataContentType] The mime content type for the event data
|
||||||
|
* @param {string} [options.dataSchema] The URI of the schema that the event data adheres to (v1.0 events)
|
||||||
|
* @param {string} [options.schemaURL] The URI of the schema that the event data adheres to (v0.3 events)
|
||||||
|
* @param {string} [options.dataContentEncoding] The content encoding for the event data (v0.3 events)
|
||||||
|
* @param {string} [options.specversion] The CloudEvent specification version for this event - default: 1.0
|
||||||
|
* @param {*} [options.data] The event payload
|
||||||
*/
|
*/
|
||||||
constructor(userSpec, userFormatter) {
|
constructor({
|
||||||
// @ts-ignore Type 'Spec1' has no construct signatures.
|
id,
|
||||||
this.spec = (userSpec) ? new userSpec(CloudEvent) : new Spec(CloudEvent);
|
source,
|
||||||
// @ts-ignore Type 'JSONFormatter' has no construct signatures.
|
type,
|
||||||
this.formatter = (userFormatter) ? new userFormatter() : new Formatter();
|
dataContentType,
|
||||||
|
time,
|
||||||
|
subject,
|
||||||
|
dataSchema,
|
||||||
|
schemaURL,
|
||||||
|
dataContentEncoding,
|
||||||
|
data,
|
||||||
|
specversion = SPEC_V1 } = {
|
||||||
|
id: undefined,
|
||||||
|
source: undefined,
|
||||||
|
type: undefined,
|
||||||
|
dataContentType: undefined,
|
||||||
|
time: undefined,
|
||||||
|
subject: undefined,
|
||||||
|
dataSchema: undefined,
|
||||||
|
schemaURL: undefined,
|
||||||
|
dataContentEncoding: undefined,
|
||||||
|
data: undefined
|
||||||
|
}) {
|
||||||
|
|
||||||
// The map of extensions
|
if (!type || !source) {
|
||||||
this.extensions = {};
|
throw new TypeError("event type and source are required");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (specversion) {
|
||||||
|
case SPEC_V1:
|
||||||
|
this.spec = new Spec1();
|
||||||
|
break;
|
||||||
|
case SPEC_V03:
|
||||||
|
this.spec = new Spec03();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new TypeError(`unknown specification version ${specversion}`);
|
||||||
|
}
|
||||||
|
this.source = source;
|
||||||
|
this.type = type;
|
||||||
|
this.dataContentType = dataContentType;
|
||||||
|
this.data = data;
|
||||||
|
this.subject = subject;
|
||||||
|
|
||||||
|
if (dataSchema) {
|
||||||
|
this.dataSchema = dataSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
if (dataContentEncoding) {
|
||||||
|
this.dataContentEncoding = dataContentEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
if (schemaURL) {
|
||||||
|
this.schemaURL = schemaURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
this.formatter = new Formatter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the formatters available to this CloudEvent
|
* Gets or sets the event id. Source + id must be unique for each distinct event.
|
||||||
* @returns {Object} a JSON formatter
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
|
||||||
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
getFormats() {
|
get id() {
|
||||||
return { json: Formatter };
|
return this.spec.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(id) {
|
||||||
|
this.spec.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the origination source of this event as a URI.
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
||||||
|
*/
|
||||||
|
get source() {
|
||||||
|
return this.spec.source;
|
||||||
|
}
|
||||||
|
|
||||||
|
set source(source) {
|
||||||
|
this.spec.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the CloudEvent specification version
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
|
||||||
|
*/
|
||||||
|
get specversion() {
|
||||||
|
return this.spec.specversion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event type
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
||||||
|
*/
|
||||||
|
get type() {
|
||||||
|
return this.spec.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set type(type) {
|
||||||
|
this.spec.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the content type of the data value for this event
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
||||||
|
*/
|
||||||
|
get dataContentType() {
|
||||||
|
return this.spec.dataContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataContentType(contenttype) {
|
||||||
|
this.spec.dataContentType = contenttype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event's data schema
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema
|
||||||
|
*/
|
||||||
|
get dataSchema() {
|
||||||
|
if (this.spec instanceof Spec1) {
|
||||||
|
return this.spec.dataSchema;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get dataSchema from version 0.3 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataSchema(dataschema) {
|
||||||
|
if (this.spec instanceof Spec1) {
|
||||||
|
this.spec.dataSchema = dataschema;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("cannot set dataSchema on version 0.3 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event's data content encoding
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding
|
||||||
|
*/
|
||||||
|
get dataContentEncoding() {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
return this.spec.dataContentEncoding;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get dataContentEncoding from version 1.0 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataContentEncoding(dataContentEncoding) {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
this.spec.dataContentEncoding = dataContentEncoding;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("cannot set dataContentEncoding on version 1.0 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event subject
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
|
||||||
|
*/
|
||||||
|
get subject() {
|
||||||
|
return this.spec.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
set subject(subject) {
|
||||||
|
this.spec.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the timestamp for this event as an ISO formatted date string
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
||||||
|
*/
|
||||||
|
get time() {
|
||||||
|
return this.spec.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
set time(time) {
|
||||||
|
this.spec.time = new Date(time).toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError}
|
||||||
|
* if this is a version 1.0 event.
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl
|
||||||
|
*/
|
||||||
|
get schemaURL() {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
return this.spec.schemaURL;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get schemaURL from version 1.0 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
set schemaURL(schemaurl) {
|
||||||
|
if (schemaurl && (this.spec instanceof Spec03)) {
|
||||||
|
this.spec.schemaURL = schemaurl;
|
||||||
|
} else if (schemaurl) {
|
||||||
|
throw new TypeError("cannot set schemaURL on version 1.0 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the data for this event
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
||||||
|
* @type {*}
|
||||||
|
*/
|
||||||
|
get data() {
|
||||||
|
return this.spec.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
set data(data) {
|
||||||
|
this.spec.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,200 +354,53 @@ class CloudEvent {
|
||||||
* to the CloudEvent specification and throws an exception if
|
* to the CloudEvent specification and throws an exception if
|
||||||
* it's invalid.
|
* it's invalid.
|
||||||
* @returns {JSON} the CloudEvent in JSON form
|
* @returns {JSON} the CloudEvent in JSON form
|
||||||
|
* @throws {ValidationError} if this event cannot be validated against the specification
|
||||||
*/
|
*/
|
||||||
format() {
|
format() {
|
||||||
// Check the constraints
|
|
||||||
this.spec.check();
|
this.spec.check();
|
||||||
|
const payload = {
|
||||||
|
data: undefined,
|
||||||
|
data_base64: undefined,
|
||||||
|
...this.spec.payload
|
||||||
|
};
|
||||||
|
|
||||||
// To run asData()
|
// Handle when is binary, creating the data_base64
|
||||||
this.getData();
|
if (isBinary(payload.data)) {
|
||||||
|
// TODO: The call to this.spec.data formats the binary data
|
||||||
// Then, format
|
// I think having a side effect like this is an anti-pattern.
|
||||||
return this.formatter.format(this.spec.payload);
|
// FIXIT
|
||||||
|
payload.data_base64 = this.spec.data;
|
||||||
|
delete payload.data;
|
||||||
|
} else {
|
||||||
|
delete payload.data_base64;
|
||||||
|
}
|
||||||
|
return this.formatter.format(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the CLoudEvent as JSON. No specification validation
|
* Formats the CloudEvent as JSON. No specification validation is performed.
|
||||||
* is performed.
|
* @returns {string} the CloudEvent as a JSON string
|
||||||
* @returns {JSON} the CloudEvent in JSON form
|
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
return this.formatter.toString(this.spec.payload);
|
return this.formatter.toString(this.spec.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the event type
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
|
||||||
* @param {string} type the type of event related to the originating source
|
|
||||||
* @returns {CloudEvent} this CloudEvent
|
|
||||||
*/
|
|
||||||
type(type) {
|
|
||||||
this.spec.type(type);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the event type
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
|
||||||
* @returns {String} the type of event related to the originating source
|
|
||||||
*/
|
|
||||||
getType() {
|
|
||||||
return this.spec.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: The fact that this is exposed is problematic, given that it's
|
|
||||||
// immutable and this method will have no effect. The specification
|
|
||||||
// version is determined via the constructor - specifically the use
|
|
||||||
// of cloud event creator functions in /v03 and /v1. By default this
|
|
||||||
// object is created as a version 1.0 CloudEvent. Not documenting.
|
|
||||||
specversion(version) {
|
|
||||||
return this.spec.specversion(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the CloudEvent specification version
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
|
|
||||||
* @returns {string} The CloudEvent version that this event adheres to
|
|
||||||
*/
|
|
||||||
getSpecversion() {
|
|
||||||
return this.spec.getSpecversion();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the origination source of this event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
|
||||||
* @param {string} source the context in which the event happened in URI form
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
source(source) {
|
|
||||||
this.spec.source(source);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the origination source of this event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
|
||||||
* @returns {string} the event source
|
|
||||||
*/
|
|
||||||
getSource() {
|
|
||||||
return this.spec.getSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the event id. Source + id must be unique for each distinct event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
|
|
||||||
* @param {string} id source+id must be unique for each distinct event
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
id(id) {
|
|
||||||
this.spec.id(id);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the event id.
|
|
||||||
* @returns {string} the event id
|
|
||||||
*/
|
|
||||||
getId() {
|
|
||||||
return this.spec.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the timestamp for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
|
||||||
* @param {Date} time timestamp when the event occurred
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
time(time) {
|
|
||||||
// TODO: Ensure that this is represented as a Date internally,
|
|
||||||
// or update the JSDoc
|
|
||||||
this.spec.time(time);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the timestamp for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
|
||||||
* @returns {Date} the timestamp for this event
|
|
||||||
*/
|
|
||||||
getTime() {
|
|
||||||
// TODO: Ensure that this is represented as a Date internally,
|
|
||||||
// or update the JSDoc
|
|
||||||
return this.spec.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Deprecated in 1.0
|
|
||||||
schemaurl(schemaurl) {
|
|
||||||
this.spec.schemaurl(schemaurl);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Deprecated in 1.0
|
|
||||||
getSchemaurl() {
|
|
||||||
return this.spec.getSchemaurl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the content type of the data value for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
|
||||||
* @param {string} contenttype per https://tools.ietf.org/html/rfc2046
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
dataContenttype(contenttype) {
|
|
||||||
this.spec.dataContenttype(contenttype);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the content type of the data value for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
|
||||||
* @returns {string} the content type for the data in this event
|
|
||||||
*/
|
|
||||||
getDataContenttype() {
|
|
||||||
return this.spec.getDataContenttype();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
|
||||||
* @param {*} data any data associated with this event
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
data(data) {
|
|
||||||
this.spec.data(data);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets any data that has been set for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
|
||||||
* @returns {*} any data set for this event
|
|
||||||
*/
|
|
||||||
getData() {
|
|
||||||
return this.spec.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an extension attribute to this CloudEvent
|
* Adds an extension attribute to this CloudEvent
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
||||||
* @param {*} key the name of the extension attribute
|
* @param {string} key the name of the extension attribute
|
||||||
* @param {*} value the value of the extension attribute
|
* @param {*} value the value of the extension attribute
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
addExtension(key, value) {
|
addExtension(key, value) {
|
||||||
this.spec.addExtension(key, value);
|
this.spec.addExtension(key, value);
|
||||||
|
this.extensions = { [key]: value, ...this.extensions };
|
||||||
// Stores locally
|
|
||||||
this.extensions[key] = value;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the extension attributes, if any, associated with this event
|
* Gets the extension attributes, if any, associated with this event
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
||||||
* @returns {Object} the extensions attributes - if none exist will will be {}
|
* @returns {Object} the extensions attributes - if none exist will will be {}
|
||||||
* // TODO - this should return null or undefined if no extensions
|
|
||||||
*/
|
*/
|
||||||
getExtensions() {
|
getExtensions() {
|
||||||
return this.extensions;
|
return this.extensions;
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -117,12 +117,9 @@ class JSONParser {
|
||||||
payload = this.decorator.parse(payload);
|
payload = this.decorator.parse(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.of(payload)
|
isDefinedOrThrow(payload, nullOrUndefinedPayload);
|
||||||
|
isStringOrObjectOrThrow(payload, invalidPayloadTypeError);
|
||||||
.filter((p) => isDefinedOrThrow(p, nullOrUndefinedPayload))
|
return asJSON(payload);
|
||||||
.filter((p) => isStringOrObjectOrThrow(p, invalidPayloadTypeError))
|
|
||||||
.map(asJSON)
|
|
||||||
.shift();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -161,15 +161,15 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h4 class="name" id="headerByGetter">
|
<h4 class="name" id="headerMap">
|
||||||
<span class="type-signature">(constant) </span>headerByGetter<span class="type-signature"></span>
|
<span class="type-signature">(constant) </span>headerMap<span class="type-signature"></span>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<p>A utility object used to retrieve the header names for a CloudEvent
|
<p>A utility Map used to retrieve the header names for a CloudEvent
|
||||||
using the CloudEvent getter function.</p>
|
using the CloudEvent getter function.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ using the CloudEvent getter function.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_v03_emitter_binary_0_3.js.html">bindings/http/v03/emitter_binary_0_3.js</a>, <a href="bindings_http_v03_emitter_binary_0_3.js.html#line12">line 12</a>
|
<a href="bindings_http_v03_emitter_binary_0_3.js.html">bindings/http/v03/emitter_binary_0_3.js</a>, <a href="bindings_http_v03_emitter_binary_0_3.js.html#line24">line 24</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
@ -229,15 +229,15 @@ using the CloudEvent getter function.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h4 class="name" id="headerByGetter">
|
<h4 class="name" id="headerMap">
|
||||||
<span class="type-signature">(constant) </span>headerByGetter<span class="type-signature"></span>
|
<span class="type-signature">(constant) </span>headerMap<span class="type-signature"></span>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<p>A utility object used to retrieve the header names for a CloudEvent
|
<p>A utility Map used to retrieve the header names for a CloudEvent
|
||||||
using the CloudEvent getter function.</p>
|
using the CloudEvent getter function.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ using the CloudEvent getter function.</p>
|
||||||
<dd class="tag-source">
|
<dd class="tag-source">
|
||||||
<ul class="dummy">
|
<ul class="dummy">
|
||||||
<li>
|
<li>
|
||||||
<a href="bindings_http_v1_emitter_binary_1.js.html">bindings/http/v1/emitter_binary_1.js</a>, <a href="bindings_http_v1_emitter_binary_1.js.html#line12">line 12</a>
|
<a href="bindings_http_v1_emitter_binary_1.js.html">bindings/http/v1/emitter_binary_1.js</a>, <a href="bindings_http_v1_emitter_binary_1.js.html#line23">line 23</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerByGetter">headerByGetter</a></li></ul>
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -149,11 +149,9 @@ structured events, add that string as a parameter to <code>emitter.sent()</code>
|
||||||
const v1Emitter = new HTTPEmitter({
|
const v1Emitter = new HTTPEmitter({
|
||||||
url: "https://cloudevents.io/example"
|
url: "https://cloudevents.io/example"
|
||||||
});
|
});
|
||||||
const event = new CloudEvent()
|
const event = new CloudEvent({
|
||||||
.type(type)
|
type, source, data
|
||||||
.source(source)
|
});
|
||||||
.time(new Date())
|
|
||||||
.data(data)
|
|
||||||
|
|
||||||
// By default, the emitter will send binary events
|
// By default, the emitter will send binary events
|
||||||
v1Emitter.send(event).then((response) => {
|
v1Emitter.send(event).then((response) => {
|
||||||
|
|
|
@ -57,7 +57,7 @@ class BinaryHTTPEmitter {
|
||||||
const headers = config[HEADERS];
|
const headers = config[HEADERS];
|
||||||
|
|
||||||
this.headerParserMap.forEach((parser, getterName) => {
|
this.headerParserMap.forEach((parser, getterName) => {
|
||||||
const value = cloudevent[getterName]();
|
const value = cloudevent[getterName];
|
||||||
if (value) {
|
if (value) {
|
||||||
headers[parser.headerName] = parser.parse(value);
|
headers[parser.headerName] = parser.parse(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ class HTTPEmitter {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
this.binary.headerParserMap.forEach((parser, getterName) => {
|
this.binary.headerParserMap.forEach((parser, getterName) => {
|
||||||
const value = event[getterName]();
|
const value = event[getterName];
|
||||||
if (value) {
|
if (value) {
|
||||||
headers[parser.headerName] = parser.parse(value);
|
headers[parser.headerName] = parser.parse(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,14 @@ const passThroughParser = parser;
|
||||||
* using the CloudEvent getter function.
|
* using the CloudEvent getter function.
|
||||||
*/
|
*/
|
||||||
const headerMap = new Map();
|
const headerMap = new Map();
|
||||||
headerMap.set('getDataContentType', passThroughParser(HEADER_CONTENT_TYPE));
|
headerMap.set("dataContentType", passThroughParser(HEADER_CONTENT_TYPE));
|
||||||
headerMap.set('getDataContentEncoding', passThroughParser(CONTENT_ENCODING));
|
headerMap.set("dataContentEncoding", passThroughParser(CONTENT_ENCODING));
|
||||||
headerMap.set('getSubject', passThroughParser(SUBJECT));
|
headerMap.set("subject", passThroughParser(SUBJECT));
|
||||||
headerMap.set('getType', passThroughParser(TYPE));
|
headerMap.set("type", passThroughParser(TYPE));
|
||||||
headerMap.set('getSpecversion', passThroughParser(SPEC_VERSION));
|
headerMap.set("specversion", passThroughParser(SPEC_VERSION));
|
||||||
headerMap.set('getSource', passThroughParser(SOURCE));
|
headerMap.set("source", passThroughParser(SOURCE));
|
||||||
headerMap.set('getId', passThroughParser(ID));
|
headerMap.set("id", passThroughParser(ID));
|
||||||
headerMap.set('getTime', passThroughParser(TIME));
|
headerMap.set("time", passThroughParser(TIME));
|
||||||
headerMap.set('getSchemaurl', passThroughParser(SCHEMA_URL));
|
headerMap.set("schemaURL", passThroughParser(SCHEMA_URL));
|
||||||
|
|
||||||
module.exports = headerMap;
|
module.exports = headerMap;
|
||||||
|
|
|
@ -48,7 +48,7 @@ const setterByHeader = {
|
||||||
[BINARY_HEADERS_03.SOURCE] : { name: "source", parser: passThroughParser },
|
[BINARY_HEADERS_03.SOURCE] : { name: "source", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_03.ID] : { name: "id", parser: passThroughParser },
|
[BINARY_HEADERS_03.ID] : { name: "id", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_03.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
|
[BINARY_HEADERS_03.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
|
||||||
[BINARY_HEADERS_03.SCHEMA_URL] : { name: "schemaurl", parser: passThroughParser },
|
[BINARY_HEADERS_03.SCHEMA_URL] : { name: "schemaURL", parser: passThroughParser },
|
||||||
[HEADER_CONTENT_TYPE]: { name: "dataContentType", parser: passThroughParser },
|
[HEADER_CONTENT_TYPE]: { name: "dataContentType", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_03.CONTENT_ENCONDING]: { name: "dataContentEncoding", parser: passThroughParser },
|
[BINARY_HEADERS_03.CONTENT_ENCONDING]: { name: "dataContentEncoding", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_03.SUBJECT] : { name: "subject", parser: passThroughParser }
|
[BINARY_HEADERS_03.SUBJECT] : { name: "subject", parser: passThroughParser }
|
||||||
|
|
|
@ -123,58 +123,19 @@ const isValidAgainstSchema = ajv.compile(schema);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorates a CloudEvent with the 0.3 specification getters and setters
|
* Decorates a CloudEvent with the 0.3 specification getters and setters
|
||||||
* @param {object} [_caller] a CloudEvent class to decorate with the 0.3 spec
|
|
||||||
* @returns {void}
|
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
function Spec03(_caller) {
|
class Spec03 {
|
||||||
|
constructor() {
|
||||||
this.payload = {
|
this.payload = {
|
||||||
specversion: schema.definitions.specversion.const,
|
specversion: schema.definitions.specversion.const,
|
||||||
id: uuidv4()
|
id: uuidv4(),
|
||||||
};
|
time: new Date().toISOString()
|
||||||
|
|
||||||
if (!_caller) {
|
|
||||||
_caller = require("../../../cloudevent.js");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Used to inject compatibility methods or attributes
|
|
||||||
*/
|
|
||||||
this.caller = _caller;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Inject compatibility methods
|
|
||||||
*/
|
|
||||||
this.caller.prototype.dataContentEncoding = function(encoding) {
|
|
||||||
this.spec.dataContentEncoding(encoding);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getDataContentEncoding = function() {
|
|
||||||
return this.spec.getDataContentEncoding();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.caller.prototype.dataContentType = function(contentType) {
|
|
||||||
this.spec.dataContentType(contentType);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getDataContentType = function() {
|
|
||||||
return this.spec.getDataContentType();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.caller.prototype.subject = function(_subject) {
|
|
||||||
this.spec.subject(_subject);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getSubject = function() {
|
|
||||||
return this.spec.getSubject();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
check() {
|
||||||
* Check the spec constraints
|
const toCheck = this.payload;
|
||||||
*/
|
|
||||||
Spec03.prototype.check = function(ce) {
|
|
||||||
const toCheck = (!ce ? this.payload : ce);
|
|
||||||
|
|
||||||
if (!isValidAgainstSchema(toCheck)) {
|
if (!isValidAgainstSchema(toCheck)) {
|
||||||
throw new ValidationError("invalid payload", isValidAgainstSchema.errors);
|
throw new ValidationError("invalid payload", isValidAgainstSchema.errors);
|
||||||
|
@ -205,90 +166,73 @@ Spec03.prototype.check = function(ce) {
|
||||||
.forEach((tc) => {
|
.forEach((tc) => {
|
||||||
throw new ValidationError("invalid payload", [`Invalid content encoding of data: ${tc.data}`]);
|
throw new ValidationError("invalid payload", [`Invalid content encoding of data: ${tc.data}`]);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.id = function(_id) {
|
set id(id) {
|
||||||
this.payload.id = _id;
|
this.payload.id = id;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.getId = function() {
|
get id() {
|
||||||
return this.payload.id;
|
return this.payload.id;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.source = function(_source) {
|
set source(source) {
|
||||||
this.payload.source = _source;
|
this.payload.source = source;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.getSource = function() {
|
get source() {
|
||||||
return this.payload.source;
|
return this.payload.source;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.specversion = function() {
|
get specversion() {
|
||||||
// does not set! This is right
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.getSpecversion = function() {
|
|
||||||
return this.payload.specversion;
|
return this.payload.specversion;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.type = function(_type) {
|
set type(type) {
|
||||||
this.payload.type = _type;
|
this.payload.type = type;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.getType = function() {
|
get type() {
|
||||||
return this.payload.type;
|
return this.payload.type;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.dataContentEncoding = function(encoding) {
|
set dataContentType(datacontenttype) {
|
||||||
this.payload.datacontentencoding = encoding;
|
this.payload.datacontenttype = datacontenttype;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.getDataContentEncoding = function() {
|
get dataContentType() {
|
||||||
return this.payload.datacontentencoding;
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.dataContentType = function(_contenttype) {
|
|
||||||
this.payload.datacontenttype = _contenttype;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
Spec03.prototype.getDataContentType = function() {
|
|
||||||
return this.payload.datacontenttype;
|
return this.payload.datacontenttype;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.schemaurl = function(_schemaurl) {
|
set schemaURL(schema) {
|
||||||
this.payload.schemaurl = _schemaurl;
|
this.payload.schemaURL = schema;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec03.prototype.getSchemaurl = function() {
|
|
||||||
return this.payload.schemaurl;
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec03.prototype.subject = function(_subject) {
|
get schemaURL() {
|
||||||
this.payload.subject = _subject;
|
return this.payload.schemaURL;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec03.prototype.getSubject = function() {
|
set subject(subject) {
|
||||||
|
this.payload.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
get subject() {
|
||||||
return this.payload.subject;
|
return this.payload.subject;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.time = function(_time) {
|
set time(time) {
|
||||||
this.payload.time = _time.toISOString();
|
this.payload.time = time;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec03.prototype.getTime = function() {
|
get time() {
|
||||||
return this.payload.time;
|
return this.payload.time;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec03.prototype.data = function(_data) {
|
set data(data) {
|
||||||
this.payload.data = _data;
|
this.payload.data = data;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec03.prototype.getData = function() {
|
get data() {
|
||||||
const dct = this.payload.datacontenttype;
|
const dct = this.payload.datacontenttype;
|
||||||
const dce = this.payload.datacontentencoding;
|
const dce = this.payload.datacontentencoding;
|
||||||
|
|
||||||
|
@ -297,7 +241,17 @@ Spec03.prototype.getData = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.payload.data;
|
return this.payload.data;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
set dataContentEncoding(encoding) {
|
||||||
|
this.payload.datacontentencoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
get dataContentEncoding() {
|
||||||
|
return this.payload.datacontentencoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Spec03.prototype.addExtension = function(key, value) {
|
Spec03.prototype.addExtension = function(key, value) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(RESERVED_ATTRIBUTES, key)) {
|
if (!Object.prototype.hasOwnProperty.call(RESERVED_ATTRIBUTES, key)) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const {
|
||||||
}
|
}
|
||||||
} = require("../constants.js");
|
} = require("../constants.js");
|
||||||
|
|
||||||
function parser(header, parser = v => v) {
|
function parser(header, parser = (v) => v) {
|
||||||
return { headerName: header, parse: parser };
|
return { headerName: header, parse: parser };
|
||||||
}
|
}
|
||||||
const passThroughParser = parser;
|
const passThroughParser = parser;
|
||||||
|
@ -21,13 +21,13 @@ const passThroughParser = parser;
|
||||||
* using the CloudEvent getter function.
|
* using the CloudEvent getter function.
|
||||||
*/
|
*/
|
||||||
const headerMap = new Map();
|
const headerMap = new Map();
|
||||||
headerMap.set('getDataContentType', passThroughParser(HEADER_CONTENT_TYPE));
|
headerMap.set("dataContentType", passThroughParser(HEADER_CONTENT_TYPE));
|
||||||
headerMap.set('getSubject', passThroughParser(SUBJECT));
|
headerMap.set("subject", passThroughParser(SUBJECT));
|
||||||
headerMap.set('getType', passThroughParser(TYPE));
|
headerMap.set("type", passThroughParser(TYPE));
|
||||||
headerMap.set('getSpecversion', passThroughParser(SPEC_VERSION));
|
headerMap.set("specversion", passThroughParser(SPEC_VERSION));
|
||||||
headerMap.set('getSource', passThroughParser(SOURCE));
|
headerMap.set("source", passThroughParser(SOURCE));
|
||||||
headerMap.set('getId', passThroughParser(ID));
|
headerMap.set("id", passThroughParser(ID));
|
||||||
headerMap.set('getTime', passThroughParser(TIME));
|
headerMap.set("time", passThroughParser(TIME));
|
||||||
headerMap.set('getDataschema', passThroughParser(DATA_SCHEMA));
|
headerMap.set("dataSchema", passThroughParser(DATA_SCHEMA));
|
||||||
|
|
||||||
module.exports = headerMap;
|
module.exports = headerMap;
|
||||||
|
|
|
@ -40,7 +40,7 @@ const setterByHeader = {
|
||||||
[BINARY_HEADERS_1.SOURCE] : { name: "source", parser: passThroughParser },
|
[BINARY_HEADERS_1.SOURCE] : { name: "source", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_1.ID] : { name: "id", parser: passThroughParser },
|
[BINARY_HEADERS_1.ID] : { name: "id", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_1.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
|
[BINARY_HEADERS_1.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
|
||||||
[BINARY_HEADERS_1.DATA_SCHEMA] : { name: "dataschema", parser: passThroughParser },
|
[BINARY_HEADERS_1.DATA_SCHEMA] : { name: "dataSchema", parser: passThroughParser },
|
||||||
[HEADER_CONTENT_TYPE] : { name: "dataContentType", parser: passThroughParser },
|
[HEADER_CONTENT_TYPE] : { name: "dataContentType", parser: passThroughParser },
|
||||||
[BINARY_HEADERS_1.SUBJECT] : { name: "subject", parser: passThroughParser }
|
[BINARY_HEADERS_1.SUBJECT] : { name: "subject", parser: passThroughParser }
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,11 +18,11 @@ const {
|
||||||
const Spec = require("./spec_1.js");
|
const Spec = require("./spec_1.js");
|
||||||
const JSONParser = require("../../../formats/json/parser.js");
|
const JSONParser = require("../../../formats/json/parser.js");
|
||||||
|
|
||||||
const jsonParserSpec = new JSONParser();
|
const jsonParser = new JSONParser();
|
||||||
|
|
||||||
const parserByMime = {
|
const parserByMime = {
|
||||||
[MIME_JSON]: jsonParserSpec,
|
[MIME_JSON]: jsonParser,
|
||||||
[MIME_CE_JSON]: jsonParserSpec
|
[MIME_CE_JSON]: jsonParser
|
||||||
};
|
};
|
||||||
|
|
||||||
const allowedContentTypes = [ MIME_CE_JSON ];
|
const allowedContentTypes = [ MIME_CE_JSON ];
|
||||||
|
@ -38,8 +38,8 @@ parserMap.set(SPEC_VERSION, passThroughParser("specversion"));
|
||||||
parserMap.set(SOURCE, passThroughParser("source"));
|
parserMap.set(SOURCE, passThroughParser("source"));
|
||||||
parserMap.set(ID, passThroughParser("id"));
|
parserMap.set(ID, passThroughParser("id"));
|
||||||
parserMap.set(TIME, parser("time", (v) => new Date(Date.parse(v))));
|
parserMap.set(TIME, parser("time", (v) => new Date(Date.parse(v))));
|
||||||
parserMap.set(DATA_SCHEMA, passThroughParser("dataschema"));
|
parserMap.set(DATA_SCHEMA, passThroughParser("dataSchema"));
|
||||||
parserMap.set(CONTENT_TYPE, passThroughParser("dataContentType"))
|
parserMap.set(CONTENT_TYPE, passThroughParser("dataContentType"));
|
||||||
parserMap.set(SUBJECT, passThroughParser("subject"));
|
parserMap.set(SUBJECT, passThroughParser("subject"));
|
||||||
parserMap.set(DATA, passThroughParser("data"));
|
parserMap.set(DATA, passThroughParser("data"));
|
||||||
parserMap.set(DATA_BASE64, passThroughParser("data"));
|
parserMap.set(DATA_BASE64, passThroughParser("data"));
|
||||||
|
|
|
@ -8,8 +8,7 @@ const {
|
||||||
isInteger,
|
isInteger,
|
||||||
isString,
|
isString,
|
||||||
isDate,
|
isDate,
|
||||||
isBinary,
|
isBinary
|
||||||
clone
|
|
||||||
} = require("../validation/fun.js");
|
} = require("../validation/fun.js");
|
||||||
|
|
||||||
const isValidType = (v) =>
|
const isValidType = (v) =>
|
||||||
|
@ -21,7 +20,7 @@ const RESERVED_ATTRIBUTES = {
|
||||||
source: "source",
|
source: "source",
|
||||||
id: "id",
|
id: "id",
|
||||||
time: "time",
|
time: "time",
|
||||||
dataschema: "schemaurl",
|
dataschema: "dataschema",
|
||||||
datacontenttype: "datacontenttype",
|
datacontenttype: "datacontenttype",
|
||||||
subject: "subject",
|
subject: "subject",
|
||||||
data: "data",
|
data: "data",
|
||||||
|
@ -119,164 +118,89 @@ const isValidAgainstSchema = ajv.compile(schema);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorates a CloudEvent with the 1.0 specification getters and setters
|
* Decorates a CloudEvent with the 1.0 specification getters and setters
|
||||||
* @param {object} [_caller] a CloudEvent class to decorate with the 1.0 spec
|
|
||||||
* @returns {void}
|
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
function Spec1(_caller) {
|
class Spec1 {
|
||||||
|
constructor() {
|
||||||
this.payload = {
|
this.payload = {
|
||||||
specversion: schema.definitions.specversion.const,
|
specversion: schema.definitions.specversion.const,
|
||||||
id: uuidv4()
|
id: uuidv4(),
|
||||||
|
time: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
Object.freeze(this);
|
||||||
if (!_caller) {
|
|
||||||
_caller = require("../../../cloudevent.js");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
check() {
|
||||||
* Used to inject compatibility methods or attributes
|
if (!isValidAgainstSchema(this.payload)) {
|
||||||
*/
|
|
||||||
this.caller = _caller;
|
|
||||||
|
|
||||||
// dataschema attribute
|
|
||||||
this.caller.prototype.dataschema = function(dataschema) {
|
|
||||||
this.spec.dataschema(dataschema);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getDataschema = function() {
|
|
||||||
return this.spec.getDataschema();
|
|
||||||
};
|
|
||||||
|
|
||||||
// datacontenttype attribute
|
|
||||||
this.caller.prototype.dataContentType = function(contentType) {
|
|
||||||
this.spec.dataContentType(contentType);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getDataContentType = function() {
|
|
||||||
return this.spec.getDataContentType();
|
|
||||||
};
|
|
||||||
|
|
||||||
// subject attribute
|
|
||||||
this.caller.prototype.subject = function(_subject) {
|
|
||||||
this.spec.subject(_subject);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.caller.prototype.getSubject = function() {
|
|
||||||
return this.spec.getSubject();
|
|
||||||
};
|
|
||||||
|
|
||||||
// format() method override
|
|
||||||
this.caller.prototype.format = function() {
|
|
||||||
// Check the constraints
|
|
||||||
this.spec.check();
|
|
||||||
|
|
||||||
// Check before getData() call
|
|
||||||
const isbin = isBinary(this.spec.payload[RESERVED_ATTRIBUTES.data]);
|
|
||||||
|
|
||||||
// May be used, if isbin==true
|
|
||||||
const payload = clone(this.spec.payload);
|
|
||||||
|
|
||||||
// To run asData()
|
|
||||||
this.getData();
|
|
||||||
|
|
||||||
// Handle when is binary, creating the data_base64
|
|
||||||
if (isbin) {
|
|
||||||
payload[RESERVED_ATTRIBUTES.data_base64] =
|
|
||||||
this.spec.payload[RESERVED_ATTRIBUTES.data];
|
|
||||||
delete payload[RESERVED_ATTRIBUTES.data];
|
|
||||||
|
|
||||||
return this.formatter.format(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then, format
|
|
||||||
return this.formatter.format(this.spec.payload);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check the spec constraints
|
|
||||||
*/
|
|
||||||
Spec1.prototype.check = function(ce) {
|
|
||||||
const toCheck = (!ce ? this.payload : ce);
|
|
||||||
|
|
||||||
if (!isValidAgainstSchema(toCheck)) {
|
|
||||||
throw new ValidationError("invalid payload", isValidAgainstSchema.errors);
|
throw new ValidationError("invalid payload", isValidAgainstSchema.errors);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.id = function(_id) {
|
set id(id) {
|
||||||
this.payload.id = _id;
|
this.payload.id = id;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec1.prototype.getId = function() {
|
get id() {
|
||||||
return this.payload.id;
|
return this.payload.id;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.source = function(_source) {
|
set source(source) {
|
||||||
this.payload.source = _source;
|
this.payload.source = source;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec1.prototype.getSource = function() {
|
get source() {
|
||||||
return this.payload.source;
|
return this.payload.source;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.specversion = function() {
|
get specversion() {
|
||||||
// does not set! This is right
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec1.prototype.getSpecversion = function() {
|
|
||||||
return this.payload.specversion;
|
return this.payload.specversion;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.type = function(_type) {
|
set type(type) {
|
||||||
this.payload.type = _type;
|
this.payload.type = type;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Spec1.prototype.getType = function() {
|
get type() {
|
||||||
return this.payload.type;
|
return this.payload.type;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.dataContentType = function(_contenttype) {
|
set dataContentType(datacontenttype) {
|
||||||
this.payload.datacontenttype = _contenttype;
|
this.payload.datacontenttype = datacontenttype;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec1.prototype.getDataContentType = function() {
|
get dataContentType() {
|
||||||
return this.payload.datacontenttype;
|
return this.payload.datacontenttype;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.dataschema = function(_schema) {
|
set dataSchema(schema) {
|
||||||
this.payload.dataschema = _schema;
|
this.payload.dataSchema = schema;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec1.prototype.getDataschema = function() {
|
|
||||||
return this.payload.dataschema;
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec1.prototype.subject = function(_subject) {
|
get dataSchema() {
|
||||||
this.payload.subject = _subject;
|
return this.payload.dataSchema;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec1.prototype.getSubject = function() {
|
set subject(subject) {
|
||||||
|
this.payload.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
get subject() {
|
||||||
return this.payload.subject;
|
return this.payload.subject;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.time = function(_time) {
|
set time(time) {
|
||||||
this.payload.time = _time.toISOString();
|
this.payload.time = time;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec1.prototype.getTime = function() {
|
get time() {
|
||||||
return this.payload.time;
|
return this.payload.time;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.data = function(_data) {
|
set data(data) {
|
||||||
this.payload.data = _data;
|
this.payload.data = data;
|
||||||
return this;
|
}
|
||||||
};
|
|
||||||
Spec1.prototype.getData = function() {
|
get data() {
|
||||||
const dct = this.payload.datacontenttype;
|
const dct = this.payload.datacontenttype;
|
||||||
|
|
||||||
if (dct) {
|
if (dct) {
|
||||||
|
@ -284,9 +208,9 @@ Spec1.prototype.getData = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.payload.data;
|
return this.payload.data;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec1.prototype.addExtension = function(key, value) {
|
addExtension(key, value) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(RESERVED_ATTRIBUTES, key)) {
|
if (!Object.prototype.hasOwnProperty.call(RESERVED_ATTRIBUTES, key)) {
|
||||||
if (isValidType(value)) {
|
if (isValidType(value)) {
|
||||||
this.payload[key] = value;
|
this.payload[key] = value;
|
||||||
|
@ -297,6 +221,7 @@ Spec1.prototype.addExtension = function(key, value) {
|
||||||
throw new ValidationError(`Reserved attribute name: '${key}'`);
|
throw new ValidationError(`Reserved attribute name: '${key}'`);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Spec1;
|
module.exports = Spec1;
|
||||||
|
|
|
@ -60,53 +60,32 @@ function parse(payload, headers, receiver) {
|
||||||
sanityHeaders[HEADER_CONTENT_TYPE] = MIME_JSON;
|
sanityHeaders[HEADER_CONTENT_TYPE] = MIME_JSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
const processedHeaders = [];
|
const eventObj = {};
|
||||||
const cloudevent = new CloudEvent(receiver.Spec);
|
|
||||||
|
|
||||||
const setterByHeader = receiver.setterByHeader;
|
const setterByHeader = receiver.setterByHeader;
|
||||||
// dont worry, check() have seen what was required or not
|
|
||||||
Array.from(Object.keys(setterByHeader))
|
Array.from(Object.keys(setterByHeader))
|
||||||
.filter((header) => sanityHeaders[header])
|
.filter((header) => sanityHeaders[header])
|
||||||
.forEach((header) => {
|
.forEach((header) => {
|
||||||
const setterName = setterByHeader[header].name;
|
eventObj[setterByHeader[header].name] = setterByHeader[header].parser(sanityHeaders[header]);
|
||||||
const parserFun = setterByHeader[header].parser;
|
delete sanityHeaders[header];
|
||||||
|
|
||||||
// invoke the setter function
|
|
||||||
cloudevent[setterName](parserFun(sanityHeaders[header]));
|
|
||||||
|
|
||||||
// to use ahead, for extensions processing
|
|
||||||
processedHeaders.push(header);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Parses the payload
|
// Parses the payload
|
||||||
const parsedPayload =
|
const parser = receiver.parsersByEncoding[eventObj.dataContentEncoding][eventObj.dataContentType];
|
||||||
parserFor(receiver.parsersByEncoding, cloudevent, sanityHeaders)
|
const parsedPayload = parser.parse(payload);
|
||||||
.parse(payload);
|
const cloudevent = new CloudEvent({ source: undefined, type: undefined, ...eventObj, data: parsedPayload });
|
||||||
|
|
||||||
// Every unprocessed header can be an extension
|
// Every unprocessed header can be an extension
|
||||||
Array.from(Object.keys(sanityHeaders))
|
Array.from(Object.keys(sanityHeaders))
|
||||||
.filter((value) => !processedHeaders.includes(value))
|
|
||||||
.filter((value) => value.startsWith(receiver.extensionsPrefix))
|
.filter((value) => value.startsWith(receiver.extensionsPrefix))
|
||||||
.map((extension) => extension.substring(receiver.extensionsPrefix.length)
|
.map((extension) => extension.substring(receiver.extensionsPrefix.length))
|
||||||
).forEach((extension) => cloudevent.addExtension(extension,
|
.forEach((extension) => cloudevent.addExtension(extension,
|
||||||
sanityHeaders[receiver.extensionsPrefix + extension])
|
sanityHeaders[receiver.extensionsPrefix + extension]));
|
||||||
);
|
|
||||||
|
|
||||||
// Sets the data
|
// Validates the event
|
||||||
cloudevent.data(parsedPayload);
|
cloudevent.spec.check();
|
||||||
|
|
||||||
// Checks the event spec
|
|
||||||
cloudevent.format();
|
|
||||||
|
|
||||||
// return the result
|
|
||||||
return cloudevent;
|
return cloudevent;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parserFor(parsersByEncoding, cloudevent, headers) {
|
|
||||||
const encoding = cloudevent.spec.payload.datacontentencoding;
|
|
||||||
return parsersByEncoding[encoding][headers[HEADER_CONTENT_TYPE]];
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
check, parse
|
check, parse
|
||||||
};
|
};
|
|
@ -14,8 +14,7 @@ function check(payload, headers, receiver) {
|
||||||
const sanityHeaders = sanityAndClone(headers);
|
const sanityHeaders = sanityAndClone(headers);
|
||||||
|
|
||||||
// Validation Level 1
|
// Validation Level 1
|
||||||
if (!receiver.allowedContentTypes
|
if (!receiver.allowedContentTypes.includes(sanityHeaders[HEADER_CONTENT_TYPE])) {
|
||||||
.includes(sanityHeaders[HEADER_CONTENT_TYPE])) {
|
|
||||||
throw new ValidationError("invalid content type", [sanityHeaders[HEADER_CONTENT_TYPE]]);
|
throw new ValidationError("invalid content type", [sanityHeaders[HEADER_CONTENT_TYPE]]);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,33 +24,28 @@ function parse(payload, headers, receiver) {
|
||||||
check(payload, headers, receiver);
|
check(payload, headers, receiver);
|
||||||
|
|
||||||
const sanityHeaders = sanityAndClone(headers);
|
const sanityHeaders = sanityAndClone(headers);
|
||||||
|
|
||||||
const contentType = sanityHeaders[HEADER_CONTENT_TYPE];
|
const contentType = sanityHeaders[HEADER_CONTENT_TYPE];
|
||||||
|
|
||||||
const parser = receiver.parserByMime[contentType];
|
const parser = receiver.parserByMime[contentType];
|
||||||
const event = parser.parse(payload);
|
const incoming = parser.parse(payload);
|
||||||
receiver.spec.check(event);
|
const event = {
|
||||||
|
type: undefined,
|
||||||
const processedAttributes = [];
|
source: undefined
|
||||||
const cloudevent = new CloudEvent(receiver.Spec);
|
};
|
||||||
|
|
||||||
receiver.parserMap.forEach((value, key) => {
|
receiver.parserMap.forEach((value, key) => {
|
||||||
if (event[key]) {
|
if (incoming[key]) {
|
||||||
// invoke the setter function
|
event[value.name] = value.parser(incoming[key]);
|
||||||
cloudevent[value.name](value.parser(event[key]));
|
delete incoming[key];
|
||||||
|
|
||||||
// to use ahead, for extensions processing
|
|
||||||
processedAttributes.push(key);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Every unprocessed attribute should be an extension
|
const cloudevent = new CloudEvent(event);
|
||||||
Array.from(Object.keys(event))
|
|
||||||
.filter((attribute) => !processedAttributes.includes(attribute))
|
|
||||||
.forEach((extension) =>
|
|
||||||
cloudevent.addExtension(extension, event[extension])
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// Every unprocessed attribute should be an extension
|
||||||
|
Array.from(Object.keys(incoming)).forEach((extension) =>
|
||||||
|
cloudevent.addExtension(extension, incoming[extension]));
|
||||||
|
|
||||||
|
cloudevent.spec.check();
|
||||||
return cloudevent;
|
return cloudevent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @typedef {import("ajv").ErrorObject} ErrorObject
|
|
||||||
* @ignore
|
* @ignore
|
||||||
|
* @typedef {import("ajv").ErrorObject} ErrorObject
|
||||||
* */
|
* */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,31 +1,260 @@
|
||||||
const Spec = require("./bindings/http/v1/spec_1.js");
|
const Spec1 = require("./bindings/http/v1/spec_1.js");
|
||||||
|
const Spec03 = require("./bindings/http/v03/spec_0_3.js");
|
||||||
const Formatter = require("./formats/json/formatter.js");
|
const Formatter = require("./formats/json/formatter.js");
|
||||||
|
|
||||||
|
const { SPEC_V1, SPEC_V03 } = require("./bindings/http/constants.js");
|
||||||
|
const { isBinary } = require("./bindings/http/validation/fun.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance of a CloudEvent.
|
* An CloudEvent describes event data in common formats to provide
|
||||||
|
* interoperability across services, platforms and systems.
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
|
||||||
*/
|
*/
|
||||||
class CloudEvent {
|
class CloudEvent {
|
||||||
/**
|
/**
|
||||||
* Creates a new CloudEvent instance
|
* Creates a new CloudEvent instance
|
||||||
* @param {Spec} [userSpec] A CloudEvent version specification
|
* @param {object} options CloudEvent properties as a simple object
|
||||||
* @param {Formatter} [userFormatter] Converts the event into a readable string
|
* @param {string} options.source Identifies the context in which an event happened as a URI reference
|
||||||
|
* @param {string} options.type Describes the type of event related to the originating occurrence
|
||||||
|
* @param {string} [options.id] A unique ID for this event - if not supplied, will be autogenerated
|
||||||
|
* @param {string} [options.time] A timestamp for this event. May also be provided as a Date
|
||||||
|
* @param {string} [options.subject] Describes the subject of the event in the context of the event producer
|
||||||
|
* @param {string} [options.dataContentType] The mime content type for the event data
|
||||||
|
* @param {string} [options.dataSchema] The URI of the schema that the event data adheres to (v1.0 events)
|
||||||
|
* @param {string} [options.schemaURL] The URI of the schema that the event data adheres to (v0.3 events)
|
||||||
|
* @param {string} [options.dataContentEncoding] The content encoding for the event data (v0.3 events)
|
||||||
|
* @param {string} [options.specversion] The CloudEvent specification version for this event - default: 1.0
|
||||||
|
* @param {*} [options.data] The event payload
|
||||||
*/
|
*/
|
||||||
constructor(userSpec, userFormatter) {
|
constructor({
|
||||||
// @ts-ignore Type 'Spec1' has no construct signatures.
|
id,
|
||||||
this.spec = (userSpec) ? new userSpec(CloudEvent) : new Spec(CloudEvent);
|
source,
|
||||||
// @ts-ignore Type 'JSONFormatter' has no construct signatures.
|
type,
|
||||||
this.formatter = (userFormatter) ? new userFormatter() : new Formatter();
|
dataContentType,
|
||||||
|
time,
|
||||||
|
subject,
|
||||||
|
dataSchema,
|
||||||
|
schemaURL,
|
||||||
|
dataContentEncoding,
|
||||||
|
data,
|
||||||
|
specversion = SPEC_V1 } = {
|
||||||
|
id: undefined,
|
||||||
|
source: undefined,
|
||||||
|
type: undefined,
|
||||||
|
dataContentType: undefined,
|
||||||
|
time: undefined,
|
||||||
|
subject: undefined,
|
||||||
|
dataSchema: undefined,
|
||||||
|
schemaURL: undefined,
|
||||||
|
dataContentEncoding: undefined,
|
||||||
|
data: undefined
|
||||||
|
}) {
|
||||||
|
|
||||||
// The map of extensions
|
if (!type || !source) {
|
||||||
this.extensions = {};
|
throw new TypeError("event type and source are required");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (specversion) {
|
||||||
|
case SPEC_V1:
|
||||||
|
this.spec = new Spec1();
|
||||||
|
break;
|
||||||
|
case SPEC_V03:
|
||||||
|
this.spec = new Spec03();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new TypeError(`unknown specification version ${specversion}`);
|
||||||
|
}
|
||||||
|
this.source = source;
|
||||||
|
this.type = type;
|
||||||
|
this.dataContentType = dataContentType;
|
||||||
|
this.data = data;
|
||||||
|
this.subject = subject;
|
||||||
|
|
||||||
|
if (dataSchema) {
|
||||||
|
this.dataSchema = dataSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
if (dataContentEncoding) {
|
||||||
|
this.dataContentEncoding = dataContentEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
if (schemaURL) {
|
||||||
|
this.schemaURL = schemaURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
this.formatter = new Formatter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the formatters available to this CloudEvent
|
* Gets or sets the event id. Source + id must be unique for each distinct event.
|
||||||
* @returns {Object} a JSON formatter
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
|
||||||
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
getFormats() {
|
get id() {
|
||||||
return { json: Formatter };
|
return this.spec.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(id) {
|
||||||
|
this.spec.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the origination source of this event as a URI.
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
||||||
|
*/
|
||||||
|
get source() {
|
||||||
|
return this.spec.source;
|
||||||
|
}
|
||||||
|
|
||||||
|
set source(source) {
|
||||||
|
this.spec.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the CloudEvent specification version
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
|
||||||
|
*/
|
||||||
|
get specversion() {
|
||||||
|
return this.spec.specversion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event type
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
||||||
|
*/
|
||||||
|
get type() {
|
||||||
|
return this.spec.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set type(type) {
|
||||||
|
this.spec.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the content type of the data value for this event
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
||||||
|
*/
|
||||||
|
get dataContentType() {
|
||||||
|
return this.spec.dataContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataContentType(contenttype) {
|
||||||
|
this.spec.dataContentType = contenttype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event's data schema
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema
|
||||||
|
*/
|
||||||
|
get dataSchema() {
|
||||||
|
if (this.spec instanceof Spec1) {
|
||||||
|
return this.spec.dataSchema;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get dataSchema from version 0.3 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataSchema(dataschema) {
|
||||||
|
if (this.spec instanceof Spec1) {
|
||||||
|
this.spec.dataSchema = dataschema;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("cannot set dataSchema on version 0.3 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event's data content encoding
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding
|
||||||
|
*/
|
||||||
|
get dataContentEncoding() {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
return this.spec.dataContentEncoding;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get dataContentEncoding from version 1.0 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
set dataContentEncoding(dataContentEncoding) {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
this.spec.dataContentEncoding = dataContentEncoding;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("cannot set dataContentEncoding on version 1.0 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the event subject
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
|
||||||
|
*/
|
||||||
|
get subject() {
|
||||||
|
return this.spec.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
set subject(subject) {
|
||||||
|
this.spec.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the timestamp for this event as an ISO formatted date string
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
||||||
|
*/
|
||||||
|
get time() {
|
||||||
|
return this.spec.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
set time(time) {
|
||||||
|
this.spec.time = new Date(time).toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError}
|
||||||
|
* if this is a version 1.0 event.
|
||||||
|
* @type {string}
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl
|
||||||
|
*/
|
||||||
|
get schemaURL() {
|
||||||
|
if (this.spec instanceof Spec03) {
|
||||||
|
return this.spec.schemaURL;
|
||||||
|
}
|
||||||
|
throw new TypeError("cannot get schemaURL from version 1.0 event");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Deprecated in 1.0
|
||||||
|
set schemaURL(schemaurl) {
|
||||||
|
if (schemaurl && (this.spec instanceof Spec03)) {
|
||||||
|
this.spec.schemaURL = schemaurl;
|
||||||
|
} else if (schemaurl) {
|
||||||
|
throw new TypeError("cannot set schemaURL on version 1.0 event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the data for this event
|
||||||
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
||||||
|
* @type {*}
|
||||||
|
*/
|
||||||
|
get data() {
|
||||||
|
return this.spec.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
set data(data) {
|
||||||
|
this.spec.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,200 +262,53 @@ class CloudEvent {
|
||||||
* to the CloudEvent specification and throws an exception if
|
* to the CloudEvent specification and throws an exception if
|
||||||
* it's invalid.
|
* it's invalid.
|
||||||
* @returns {JSON} the CloudEvent in JSON form
|
* @returns {JSON} the CloudEvent in JSON form
|
||||||
|
* @throws {ValidationError} if this event cannot be validated against the specification
|
||||||
*/
|
*/
|
||||||
format() {
|
format() {
|
||||||
// Check the constraints
|
|
||||||
this.spec.check();
|
this.spec.check();
|
||||||
|
const payload = {
|
||||||
|
data: undefined,
|
||||||
|
data_base64: undefined,
|
||||||
|
...this.spec.payload
|
||||||
|
};
|
||||||
|
|
||||||
// To run asData()
|
// Handle when is binary, creating the data_base64
|
||||||
this.getData();
|
if (isBinary(payload.data)) {
|
||||||
|
// TODO: The call to this.spec.data formats the binary data
|
||||||
// Then, format
|
// I think having a side effect like this is an anti-pattern.
|
||||||
return this.formatter.format(this.spec.payload);
|
// FIXIT
|
||||||
|
payload.data_base64 = this.spec.data;
|
||||||
|
delete payload.data;
|
||||||
|
} else {
|
||||||
|
delete payload.data_base64;
|
||||||
|
}
|
||||||
|
return this.formatter.format(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the CLoudEvent as JSON. No specification validation
|
* Formats the CloudEvent as JSON. No specification validation is performed.
|
||||||
* is performed.
|
* @returns {string} the CloudEvent as a JSON string
|
||||||
* @returns {JSON} the CloudEvent in JSON form
|
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
return this.formatter.toString(this.spec.payload);
|
return this.formatter.toString(this.spec.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the event type
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
|
||||||
* @param {string} type the type of event related to the originating source
|
|
||||||
* @returns {CloudEvent} this CloudEvent
|
|
||||||
*/
|
|
||||||
type(type) {
|
|
||||||
this.spec.type(type);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the event type
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
|
|
||||||
* @returns {String} the type of event related to the originating source
|
|
||||||
*/
|
|
||||||
getType() {
|
|
||||||
return this.spec.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: The fact that this is exposed is problematic, given that it's
|
|
||||||
// immutable and this method will have no effect. The specification
|
|
||||||
// version is determined via the constructor - specifically the use
|
|
||||||
// of cloud event creator functions in /v03 and /v1. By default this
|
|
||||||
// object is created as a version 1.0 CloudEvent. Not documenting.
|
|
||||||
specversion(version) {
|
|
||||||
return this.spec.specversion(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the CloudEvent specification version
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
|
|
||||||
* @returns {string} The CloudEvent version that this event adheres to
|
|
||||||
*/
|
|
||||||
getSpecversion() {
|
|
||||||
return this.spec.getSpecversion();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the origination source of this event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
|
||||||
* @param {string} source the context in which the event happened in URI form
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
source(source) {
|
|
||||||
this.spec.source(source);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the origination source of this event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
|
|
||||||
* @returns {string} the event source
|
|
||||||
*/
|
|
||||||
getSource() {
|
|
||||||
return this.spec.getSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the event id. Source + id must be unique for each distinct event.
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
|
|
||||||
* @param {string} id source+id must be unique for each distinct event
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
id(id) {
|
|
||||||
this.spec.id(id);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the event id.
|
|
||||||
* @returns {string} the event id
|
|
||||||
*/
|
|
||||||
getId() {
|
|
||||||
return this.spec.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the timestamp for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
|
||||||
* @param {Date} time timestamp when the event occurred
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
time(time) {
|
|
||||||
// TODO: Ensure that this is represented as a Date internally,
|
|
||||||
// or update the JSDoc
|
|
||||||
this.spec.time(time);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the timestamp for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
|
|
||||||
* @returns {Date} the timestamp for this event
|
|
||||||
*/
|
|
||||||
getTime() {
|
|
||||||
// TODO: Ensure that this is represented as a Date internally,
|
|
||||||
// or update the JSDoc
|
|
||||||
return this.spec.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Deprecated in 1.0
|
|
||||||
schemaurl(schemaurl) {
|
|
||||||
this.spec.schemaurl(schemaurl);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Deprecated in 1.0
|
|
||||||
getSchemaurl() {
|
|
||||||
return this.spec.getSchemaurl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the content type of the data value for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
|
||||||
* @param {string} contenttype per https://tools.ietf.org/html/rfc2046
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
dataContenttype(contenttype) {
|
|
||||||
this.spec.dataContenttype(contenttype);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the content type of the data value for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
|
|
||||||
* @returns {string} the content type for the data in this event
|
|
||||||
*/
|
|
||||||
getDataContenttype() {
|
|
||||||
return this.spec.getDataContenttype();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
|
||||||
* @param {*} data any data associated with this event
|
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
|
||||||
*/
|
|
||||||
data(data) {
|
|
||||||
this.spec.data(data);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets any data that has been set for this event
|
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
|
|
||||||
* @returns {*} any data set for this event
|
|
||||||
*/
|
|
||||||
getData() {
|
|
||||||
return this.spec.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an extension attribute to this CloudEvent
|
* Adds an extension attribute to this CloudEvent
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
||||||
* @param {*} key the name of the extension attribute
|
* @param {string} key the name of the extension attribute
|
||||||
* @param {*} value the value of the extension attribute
|
* @param {*} value the value of the extension attribute
|
||||||
* @returns {CloudEvent} this CloudEvent instance
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
addExtension(key, value) {
|
addExtension(key, value) {
|
||||||
this.spec.addExtension(key, value);
|
this.spec.addExtension(key, value);
|
||||||
|
this.extensions = { [key]: value, ...this.extensions };
|
||||||
// Stores locally
|
|
||||||
this.extensions[key] = value;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the extension attributes, if any, associated with this event
|
* Gets the extension attributes, if any, associated with this event
|
||||||
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
|
||||||
* @returns {Object} the extensions attributes - if none exist will will be {}
|
* @returns {Object} the extensions attributes - if none exist will will be {}
|
||||||
* // TODO - this should return null or undefined if no extensions
|
|
||||||
*/
|
*/
|
||||||
getExtensions() {
|
getExtensions() {
|
||||||
return this.extensions;
|
return this.extensions;
|
||||||
|
|
|
@ -25,12 +25,9 @@ class JSONParser {
|
||||||
payload = this.decorator.parse(payload);
|
payload = this.decorator.parse(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.of(payload)
|
isDefinedOrThrow(payload, nullOrUndefinedPayload);
|
||||||
|
isStringOrObjectOrThrow(payload, invalidPayloadTypeError);
|
||||||
.filter((p) => isDefinedOrThrow(p, nullOrUndefinedPayload))
|
return asJSON(payload);
|
||||||
.filter((p) => isStringOrObjectOrThrow(p, invalidPayloadTypeError))
|
|
||||||
.map(asJSON)
|
|
||||||
.shift();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
exports.handlers = {
|
||||||
|
beforeParse(e) {
|
||||||
|
e.source = e.source.replace(/@typedef.*/, "");
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
};
|
|
@ -46,19 +46,20 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
|
|
||||||
describe("V1", () => {
|
describe("V1", () => {
|
||||||
const emitter = new HTTPEmitter({ url: receiver });
|
const emitter = new HTTPEmitter({ url: receiver });
|
||||||
const event = new CloudEvent(V1Spec)
|
const event = new CloudEvent({
|
||||||
.type(type)
|
specversion: SPEC_V1,
|
||||||
.source(source)
|
type,
|
||||||
.time(new Date())
|
source,
|
||||||
.data(data)
|
time: new Date(),
|
||||||
.addExtension(ext1Name, ext1Value)
|
data
|
||||||
.addExtension(ext2Name, ext2Value);
|
});
|
||||||
|
event.addExtension(ext1Name, ext1Value)
|
||||||
|
event.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
it("Sends a binary 1.0 CloudEvent by default", () => {
|
it("Sends a binary 1.0 CloudEvent by default", () => {
|
||||||
emitter.send(event)
|
emitter.send(event).then((response) => {
|
||||||
.then((response) => {
|
|
||||||
// A binary message will have a ce-id header
|
// A binary message will have a ce-id header
|
||||||
expect(response.data[BINARY_HEADERS_1.ID]).to.equal(event.getId());
|
expect(response.data[BINARY_HEADERS_1.ID]).to.equal(event.id);
|
||||||
expect(response.data[BINARY_HEADERS_1.SPEC_VERSION]).to.equal(SPEC_V1);
|
expect(response.data[BINARY_HEADERS_1.SPEC_VERSION]).to.equal(SPEC_V1);
|
||||||
// A binary message will have a request body for the data
|
// A binary message will have a request body for the data
|
||||||
expect(response.data.lunchBreak).to.equal(data.lunchBreak);
|
expect(response.data.lunchBreak).to.equal(data.lunchBreak);
|
||||||
|
@ -67,11 +68,11 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
|
|
||||||
it("Provides the HTTP headers for a binary event", () => {
|
it("Provides the HTTP headers for a binary event", () => {
|
||||||
const headers = emitter.headers(event);
|
const headers = emitter.headers(event);
|
||||||
expect(headers[BINARY_HEADERS_1.TYPE]).to.equal(event.getType());
|
expect(headers[BINARY_HEADERS_1.TYPE]).to.equal(event.type);
|
||||||
expect(headers[BINARY_HEADERS_1.SPEC_VERSION]).to.equal(event.getSpecversion());
|
expect(headers[BINARY_HEADERS_1.SPEC_VERSION]).to.equal(event.specversion);
|
||||||
expect(headers[BINARY_HEADERS_1.SOURCE]).to.equal(event.getSource());
|
expect(headers[BINARY_HEADERS_1.SOURCE]).to.equal(event.source);
|
||||||
expect(headers[BINARY_HEADERS_1.ID]).to.equal(event.getId());
|
expect(headers[BINARY_HEADERS_1.ID]).to.equal(event.id);
|
||||||
expect(headers[BINARY_HEADERS_1.TIME]).to.equal(event.getTime());
|
expect(headers[BINARY_HEADERS_1.TIME]).to.equal(event.time);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Sends a structured 1.0 CloudEvent if specified", () => {
|
it("Sends a structured 1.0 CloudEvent if specified", () => {
|
||||||
|
@ -118,19 +119,20 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
|
|
||||||
describe("V03", () => {
|
describe("V03", () => {
|
||||||
const emitter = new HTTPEmitter({ url: receiver, version: SPEC_V03 });
|
const emitter = new HTTPEmitter({ url: receiver, version: SPEC_V03 });
|
||||||
const event = new CloudEvent(V03Spec)
|
const event = new CloudEvent({
|
||||||
.type(type)
|
specversion: SPEC_V03,
|
||||||
.source(source)
|
type,
|
||||||
.time(new Date())
|
source,
|
||||||
.data(data)
|
time: new Date(),
|
||||||
.addExtension(ext1Name, ext1Value)
|
data
|
||||||
.addExtension(ext2Name, ext2Value);
|
});
|
||||||
|
event.addExtension(ext1Name, ext1Value)
|
||||||
|
event.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
it("Sends a binary 0.3 CloudEvent", () => {
|
it("Sends a binary 0.3 CloudEvent", () => {
|
||||||
emitter.send(event)
|
emitter.send(event).then((response) => {
|
||||||
.then((response) => {
|
|
||||||
// A binary message will have a ce-id header
|
// A binary message will have a ce-id header
|
||||||
expect(response.data[BINARY_HEADERS_03.ID]).to.equal(event.getId());
|
expect(response.data[BINARY_HEADERS_03.ID]).to.equal(event.id);
|
||||||
expect(response.data[BINARY_HEADERS_03.SPEC_VERSION]).to.equal(SPEC_V03);
|
expect(response.data[BINARY_HEADERS_03.SPEC_VERSION]).to.equal(SPEC_V03);
|
||||||
// A binary message will have a request body for the data
|
// A binary message will have a request body for the data
|
||||||
expect(response.data.lunchBreak).to.equal(data.lunchBreak);
|
expect(response.data.lunchBreak).to.equal(data.lunchBreak);
|
||||||
|
@ -139,11 +141,11 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
|
|
||||||
it("Provides the HTTP headers for a binary event", () => {
|
it("Provides the HTTP headers for a binary event", () => {
|
||||||
const headers = emitter.headers(event);
|
const headers = emitter.headers(event);
|
||||||
expect(headers[BINARY_HEADERS_03.TYPE]).to.equal(event.getType());
|
expect(headers[BINARY_HEADERS_03.TYPE]).to.equal(event.type);
|
||||||
expect(headers[BINARY_HEADERS_03.SPEC_VERSION]).to.equal(event.getSpecversion());
|
expect(headers[BINARY_HEADERS_03.SPEC_VERSION]).to.equal(event.specversion);
|
||||||
expect(headers[BINARY_HEADERS_03.SOURCE]).to.equal(event.getSource());
|
expect(headers[BINARY_HEADERS_03.SOURCE]).to.equal(event.source);
|
||||||
expect(headers[BINARY_HEADERS_03.ID]).to.equal(event.getId());
|
expect(headers[BINARY_HEADERS_03.ID]).to.equal(event.id);
|
||||||
expect(headers[BINARY_HEADERS_03.TIME]).to.equal(event.getTime());
|
expect(headers[BINARY_HEADERS_03.TIME]).to.equal(event.time);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Sends a structured 0.3 CloudEvent if specified", () => {
|
it("Sends a structured 0.3 CloudEvent if specified", () => {
|
||||||
|
@ -158,6 +160,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
|
||||||
expect(response.data.data.lunchBreak).to.equal(data.lunchBreak);
|
expect(response.data.data.lunchBreak).to.equal(data.lunchBreak);
|
||||||
}).catch(expect.fail);
|
}).catch(expect.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Sends to an alternate URL if specified", () => {
|
it("Sends to an alternate URL if specified", () => {
|
||||||
nock(receiver)
|
nock(receiver)
|
||||||
.post("/alternate")
|
.post("/alternate")
|
||||||
|
|
|
@ -131,20 +131,20 @@ describe("HTTP Transport Binding Receiver for CloudEvents", () => {
|
||||||
};
|
};
|
||||||
const event = receiver.accept(headers, data);
|
const event = receiver.accept(headers, data);
|
||||||
expect(event instanceof CloudEvent).to.equal(true);
|
expect(event instanceof CloudEvent).to.equal(true);
|
||||||
expect(event.getId()).to.equal(id);
|
expect(event.id).to.equal(id);
|
||||||
expect(event.getType()).to.equal(type);
|
expect(event.type).to.equal(type);
|
||||||
expect(event.getSource()).to.equal(source);
|
expect(event.source).to.equal(source);
|
||||||
expect(event.getData()).to.deep.equal(data);
|
expect(event.data).to.deep.equal(data);
|
||||||
expect(event.getSpecversion()).to.equal(specversion);
|
expect(event.specversion).to.equal(specversion);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function validateEvent(event, specversion) {
|
function validateEvent(event, specversion) {
|
||||||
expect(event instanceof CloudEvent).to.equal(true);
|
expect(event instanceof CloudEvent).to.equal(true);
|
||||||
expect(event.getId()).to.equal(id);
|
expect(event.id).to.equal(id);
|
||||||
expect(event.getType()).to.equal(type);
|
expect(event.type).to.equal(type);
|
||||||
expect(event.getSource()).to.equal(source);
|
expect(event.source).to.equal(source);
|
||||||
expect(event.getData()).to.deep.equal(data);
|
expect(event.data).to.deep.equal(data);
|
||||||
expect(event.getSpecversion()).to.equal(specversion);
|
expect(event.specversion).to.equal(specversion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
|
|
||||||
|
const CloudEvent = require("../../../lib/cloudevent.js");
|
||||||
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
|
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
|
||||||
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
||||||
const {
|
const {
|
||||||
|
@ -185,8 +186,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getType())
|
expect(actual.type).to.equal("type");
|
||||||
.to.equal("type");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'specversion'", () => {
|
it("CloudEvent contains 'specversion'", () => {
|
||||||
|
@ -208,8 +208,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getSpecversion())
|
expect(actual.specversion).to.equal(SPEC_V03);
|
||||||
.to.equal(SPEC_V03);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'source'", () => {
|
it("CloudEvent contains 'source'", () => {
|
||||||
|
@ -231,8 +230,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getSource())
|
expect(actual.source).to.equal("/source");
|
||||||
.to.equal("/source");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'id'", () => {
|
it("CloudEvent contains 'id'", () => {
|
||||||
|
@ -254,8 +252,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getId())
|
expect(actual.id).to.equal("id");
|
||||||
.to.equal("id");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'time'", () => {
|
it("CloudEvent contains 'time'", () => {
|
||||||
|
@ -277,8 +274,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getTime())
|
expect(actual.time).to.equal("2019-06-16T11:42:00.000Z");
|
||||||
.to.equal("2019-06-16T11:42:00.000Z");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'schemaurl'", () => {
|
it("CloudEvent contains 'schemaurl'", () => {
|
||||||
|
@ -300,8 +296,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getSchemaurl())
|
expect(actual.schemaURL).to.equal("http://schema.registry/v1");
|
||||||
.to.equal("http://schema.registry/v1");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'datacontenttype' (application/json)", () => {
|
it("CloudEvent contains 'datacontenttype' (application/json)", () => {
|
||||||
|
@ -323,8 +318,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getDataContentType())
|
expect(actual.dataContentType).to.equal("application/json");
|
||||||
.to.equal("application/json");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'datacontenttype' (application/octet-stream)",
|
it("CloudEvent contains 'datacontenttype' (application/octet-stream)",
|
||||||
|
@ -345,8 +339,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getDataContentType())
|
expect(actual.dataContentType).to.equal("application/octet-stream");
|
||||||
.to.equal("application/octet-stream");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'data' (application/json)", () => {
|
it("CloudEvent contains 'data' (application/json)", () => {
|
||||||
|
@ -368,8 +361,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData())
|
expect(actual.data).to.deep.equal(payload);
|
||||||
.to.deep.equal(payload);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
||||||
|
@ -389,8 +381,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData())
|
expect(actual.data).to.deep.equal(payload);
|
||||||
.to.deep.equal(payload);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("No error when all attributes are in place", () => {
|
it("No error when all attributes are in place", () => {
|
||||||
|
@ -412,11 +403,8 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual)
|
expect(actual).to.be.an.instanceof(CloudEvent);
|
||||||
.to.be.an("object");
|
expect(actual).to.have.property("format");
|
||||||
|
|
||||||
expect(actual)
|
|
||||||
.to.have.property("format");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should accept 'extension1'", () => {
|
it("Should accept 'extension1'", () => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ const {
|
||||||
HEADER_CONTENT_TYPE
|
HEADER_CONTENT_TYPE
|
||||||
} = require("../../../lib/bindings/http/constants.js");
|
} = require("../../../lib/bindings/http/constants.js");
|
||||||
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
||||||
|
const CloudEvent = require("../../../lib/cloudevent.js");
|
||||||
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
|
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
|
||||||
|
|
||||||
const receiver = new BinaryHTTPReceiver(SPEC_V1);
|
const receiver = new BinaryHTTPReceiver(SPEC_V1);
|
||||||
|
@ -186,7 +186,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getType()).to.equal("type");
|
expect(actual.type).to.equal("type");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'specversion'", () => {
|
it("CloudEvent contains 'specversion'", () => {
|
||||||
|
@ -208,7 +208,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getSpecversion()).to.equal(SPEC_V1);
|
expect(actual.specversion).to.equal(SPEC_V1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'source'", () => {
|
it("CloudEvent contains 'source'", () => {
|
||||||
|
@ -230,7 +230,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getSource()).to.equal("/source");
|
expect(actual.source).to.equal("/source");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getId()).to.equal("id");
|
expect(actual.id).to.equal("id");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'time'", () => {
|
it("CloudEvent contains 'time'", () => {
|
||||||
|
@ -275,7 +275,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getTime()).to.equal("2019-06-16T11:42:00.000Z");
|
expect(actual.time).to.equal("2019-06-16T11:42:00.000Z");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'dataschema'", () => {
|
it("CloudEvent contains 'dataschema'", () => {
|
||||||
|
@ -297,7 +297,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getDataschema()).to.equal("http://schema.registry/v1");
|
expect(actual.dataSchema).to.equal("http://schema.registry/v1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'contenttype' (application/json)", () => {
|
it("CloudEvent contains 'contenttype' (application/json)", () => {
|
||||||
|
@ -319,7 +319,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getDataContentType()).to.equal("application/json");
|
expect(actual.dataContentType).to.equal("application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'contenttype' (application/octet-stream)", () => {
|
it("CloudEvent contains 'contenttype' (application/octet-stream)", () => {
|
||||||
|
@ -339,7 +339,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getDataContentType()).to.equal("application/octet-stream");
|
expect(actual.dataContentType).to.equal("application/octet-stream");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'data' (application/json)", () => {
|
it("CloudEvent contains 'data' (application/json)", () => {
|
||||||
|
@ -361,7 +361,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.deep.equal(payload);
|
expect(actual.data).to.deep.equal(payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
||||||
|
@ -381,7 +381,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.deep.equal(payload);
|
expect(actual.data).to.deep.equal(payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("The content of 'data' is base64 for binary", () => {
|
it("The content of 'data' is base64 for binary", () => {
|
||||||
|
@ -390,8 +390,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindata = Uint32Array
|
const bindata = Uint32Array.from(JSON.stringify(expected), (c) => c.codePointAt(0));
|
||||||
.from(JSON.stringify(expected), (c) => c.codePointAt(0));
|
|
||||||
const payload = asBase64(bindata);
|
const payload = asBase64(bindata);
|
||||||
|
|
||||||
const attributes = {
|
const attributes = {
|
||||||
|
@ -408,7 +407,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.deep.equal(expected);
|
expect(actual.data).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("No error when all attributes are in place", () => {
|
it("No error when all attributes are in place", () => {
|
||||||
|
@ -430,7 +429,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
const actual = receiver.parse(payload, attributes);
|
const actual = receiver.parse(payload, attributes);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual).to.be.an("object");
|
expect(actual).to.be.an.instanceof(CloudEvent);
|
||||||
|
|
||||||
expect(actual).to.have.property("format");
|
expect(actual).to.have.property("format");
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,15 +2,14 @@ const expect = require("chai").expect;
|
||||||
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
|
||||||
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured.js");
|
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured.js");
|
||||||
const CloudEvent = require("../../../lib/cloudevent.js");
|
const CloudEvent = require("../../../lib/cloudevent.js");
|
||||||
const { Spec } = require("../../../lib/bindings/http/v03/index.js");
|
|
||||||
const { SPEC_V03 } = require("../../../lib/bindings/http/constants.js");
|
const { SPEC_V03 } = require("../../../lib/bindings/http/constants.js");
|
||||||
|
|
||||||
const receiver = new HTTPStructuredReceiver(SPEC_V03);
|
const receiver = new HTTPStructuredReceiver(SPEC_V03);
|
||||||
|
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resourse/123";
|
const source = "urn:event:from:myapi/resourse/123";
|
||||||
const now = new Date();
|
const time = new Date();
|
||||||
const schemaurl = "http://cloudevents.io/schema.json";
|
const schemaURL = "http://cloudevents.io/schema.json";
|
||||||
|
|
||||||
const ceContentType = "application/json";
|
const ceContentType = "application/json";
|
||||||
|
|
||||||
|
@ -70,17 +69,19 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
it("Throw error data content encoding is base64, but 'data' is not",
|
it("Throw error data content encoding is base64, but 'data' is not",
|
||||||
() => {
|
() => {
|
||||||
// setup
|
// setup
|
||||||
const payload = new CloudEvent(Spec)
|
const event = new CloudEvent({
|
||||||
.type(type)
|
specversion: SPEC_V03,
|
||||||
.source(source)
|
type,
|
||||||
.dataContentType("text/plain")
|
source,
|
||||||
.dataContentEncoding("base64")
|
time,
|
||||||
.time(now)
|
dataContentType: "text/plain",
|
||||||
.schemaurl(schemaurl)
|
dataContentEncoding: "base64",
|
||||||
.data("No base 64 value")
|
schemaURL,
|
||||||
.addExtension(ext1Name, ext1Value)
|
data: "No base 64 value"
|
||||||
.addExtension(ext2Name, ext2Value)
|
});
|
||||||
.toString();
|
event.addExtension(ext1Name, ext1Value);
|
||||||
|
event.addExtension(ext2Name, ext2Value);
|
||||||
|
const payload = event.toString();
|
||||||
|
|
||||||
const attributes = {
|
const attributes = {
|
||||||
"Content-Type": "application/cloudevents+json"
|
"Content-Type": "application/cloudevents+json"
|
||||||
|
@ -120,14 +121,13 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
|
|
||||||
describe("Parse", () => {
|
describe("Parse", () => {
|
||||||
it("Throw error when the event does not follow the spec", () => {
|
it("Throw error when the event does not follow the spec", () => {
|
||||||
// setup
|
const payload = {
|
||||||
const payload = new CloudEvent(Spec)
|
type,
|
||||||
.type(type)
|
source,
|
||||||
.source(source)
|
time,
|
||||||
.time(now)
|
schemaURL,
|
||||||
.schemaurl(schemaurl)
|
data
|
||||||
.data(data)
|
};
|
||||||
.toString();
|
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/cloudevents+xml"
|
"Content-Type": "application/cloudevents+xml"
|
||||||
|
@ -141,15 +141,15 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
it("Should accept event that follows the spec", () => {
|
it("Should accept event that follows the spec", () => {
|
||||||
// setup
|
// setup
|
||||||
const id = "id-x0dk";
|
const id = "id-x0dk";
|
||||||
const payload = new CloudEvent(Spec)
|
const payload = {
|
||||||
.type(type)
|
id,
|
||||||
.source(source)
|
type,
|
||||||
.id(id)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
schemaURL,
|
||||||
.schemaurl(schemaurl)
|
dataContentType: ceContentType,
|
||||||
.data(data)
|
data
|
||||||
.toString();
|
};
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
@ -158,29 +158,25 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, headers);
|
const actual = receiver.parse(payload, headers);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual)
|
expect(actual).to.be.an.instanceof(CloudEvent);
|
||||||
.to.be.an("object");
|
|
||||||
|
|
||||||
expect(actual)
|
expect(actual).to.have.property("format");
|
||||||
.to.have.property("format");
|
|
||||||
|
|
||||||
expect(actual.getId())
|
expect(actual.id).to.equal(id);
|
||||||
.to.equals(id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should accept 'extension1'", () => {
|
it("Should accept 'extension1'", () => {
|
||||||
// setup
|
// setup
|
||||||
const extension1 = "mycuston-ext1";
|
const extension1 = "mycuston-ext1";
|
||||||
const payload = new CloudEvent(Spec)
|
const payload = {
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
schemaURL,
|
||||||
.schemaurl(schemaurl)
|
data,
|
||||||
.data(data)
|
dataContentType: ceContentType,
|
||||||
.addExtension("extension1", extension1)
|
"extension1": extension1
|
||||||
.toString();
|
};
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
@ -190,21 +186,19 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
const actualExtensions = actual.getExtensions();
|
const actualExtensions = actual.getExtensions();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actualExtensions.extension1)
|
expect(actualExtensions.extension1).to.equal(extension1);
|
||||||
.to.equal(extension1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should parse 'data' stringfied json to json object", () => {
|
it("Should parse 'data' stringfied json to json object", () => {
|
||||||
// setup
|
const payload = new CloudEvent({
|
||||||
const payload = new CloudEvent(Spec)
|
specversion: SPEC_V03,
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
schemaURL,
|
||||||
.schemaurl(schemaurl)
|
dataContentType: ceContentType,
|
||||||
.data(JSON.stringify(data))
|
data: JSON.stringify(data)
|
||||||
.toString();
|
}).toString();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
@ -213,7 +207,7 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
|
||||||
const actual = receiver.parse(payload, headers);
|
const actual = receiver.parse(payload, headers);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.deep.equal(data);
|
expect(actual.data).to.deep.equal(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,8 +10,8 @@ const receiver = new HTTPStructuredReceiver(SPEC_V1);
|
||||||
|
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resource/123";
|
const source = "urn:event:from:myapi/resource/123";
|
||||||
const now = new Date();
|
const time = new Date();
|
||||||
const dataschema = "http://cloudevents.io/schema.json";
|
const dataSchema = "http://cloudevents.io/schema.json";
|
||||||
|
|
||||||
const ceContentType = "application/json";
|
const ceContentType = "application/json";
|
||||||
|
|
||||||
|
@ -80,13 +80,12 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
describe("Parse", () => {
|
describe("Parse", () => {
|
||||||
it("Throw error when the event does not follow the spec", () => {
|
it("Throw error when the event does not follow the spec", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload =
|
const payload = new CloudEvent({
|
||||||
new CloudEvent()
|
type,
|
||||||
.type(type)
|
source,
|
||||||
.source(source)
|
time,
|
||||||
.time(now)
|
data
|
||||||
.data(data)
|
}).toString();
|
||||||
.toString();
|
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/cloudevents+xml"
|
"Content-Type": "application/cloudevents+xml"
|
||||||
|
@ -100,15 +99,15 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
it("Should accept event that follows the spec", () => {
|
it("Should accept event that follows the spec", () => {
|
||||||
// setup
|
// setup
|
||||||
const id = "id-x0dk";
|
const id = "id-x0dk";
|
||||||
const payload = new CloudEvent(Spec)
|
const payload = new CloudEvent({
|
||||||
.type(type)
|
id,
|
||||||
.source(source)
|
type,
|
||||||
.id(id)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
data,
|
||||||
.dataschema(dataschema)
|
dataSchema,
|
||||||
.data(data)
|
dataContentType: ceContentType,
|
||||||
.toString();
|
}).toString();
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
@ -117,28 +116,26 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
const actual = receiver.parse(payload, headers);
|
const actual = receiver.parse(payload, headers);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual)
|
expect(actual).to.be.an.instanceof(CloudEvent);
|
||||||
.to.be.an("object");
|
|
||||||
|
|
||||||
expect(actual)
|
expect(actual).to.have.property("format");
|
||||||
.to.have.property("format");
|
|
||||||
|
|
||||||
expect(actual.getId())
|
expect(actual.id).to.equal(id);
|
||||||
.to.equals(id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should accept 'extension1'", () => {
|
it("Should accept 'extension1'", () => {
|
||||||
// setup
|
// setup
|
||||||
const extension1 = "mycustom-ext1";
|
const extension1 = "mycustom-ext1";
|
||||||
const payload = new CloudEvent(Spec)
|
const event = new CloudEvent({
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
data,
|
||||||
.dataschema(dataschema)
|
dataSchema,
|
||||||
.data(data)
|
dataContentType: ceContentType
|
||||||
.addExtension("extension1", extension1)
|
});
|
||||||
.toString();
|
event.addExtension("extension1", extension1);
|
||||||
|
const payload = event.toString();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
|
@ -149,20 +146,19 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
const actualExtensions = actual.getExtensions();
|
const actualExtensions = actual.getExtensions();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actualExtensions.extension1)
|
expect(actualExtensions.extension1).to.equal(extension1);
|
||||||
.to.equal(extension1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should parse 'data' stringified json to json object", () => {
|
it("Should parse 'data' stringified json to json object", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = new CloudEvent(Spec)
|
const payload = new CloudEvent({
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
time,
|
||||||
.time(now)
|
dataSchema,
|
||||||
.dataschema(dataschema)
|
data: JSON.stringify(data),
|
||||||
.data(JSON.stringify(data))
|
dataContentType: ceContentType
|
||||||
.toString();
|
}).toString();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
|
@ -172,20 +168,19 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
const actual = receiver.parse(payload, headers);
|
const actual = receiver.parse(payload, headers);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.deep.equal(data);
|
expect(actual.data).to.deep.equal(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should maps 'data_base64' to 'data' attribute", () => {
|
it("Should maps 'data_base64' to 'data' attribute", () => {
|
||||||
// setup
|
// setup
|
||||||
const bindata = Uint32Array
|
const bindata = Uint32Array.from(JSON.stringify(data), (c) => c.codePointAt(0));
|
||||||
.from(JSON.stringify(data), (c) => c.codePointAt(0));
|
|
||||||
const expected = asBase64(bindata);
|
const expected = asBase64(bindata);
|
||||||
const payload = new CloudEvent(Spec)
|
const payload = new CloudEvent({
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
data: bindata,
|
||||||
.data(bindata)
|
dataContentType: ceContentType
|
||||||
.format();
|
}).format();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/cloudevents+json"
|
"content-type": "application/cloudevents+json"
|
||||||
|
@ -195,7 +190,7 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
const actual = receiver.parse(JSON.stringify(payload), headers);
|
const actual = receiver.parse(JSON.stringify(payload), headers);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.getData()).to.equal(expected);
|
expect(actual.data).to.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,175 @@
|
||||||
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
|
const { SPEC_V1, SPEC_V03 } = require("../lib/bindings/http/constants.js");
|
||||||
|
|
||||||
|
const { expect } = require("chai");
|
||||||
|
|
||||||
|
const fixture = {
|
||||||
|
source: "http://unit.test",
|
||||||
|
type: "org.cncf.cloudevents.example"
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("A 1.0 CloudEvent", () => {
|
||||||
|
it("must be created with a source and type", () => {
|
||||||
|
expect(() => new CloudEvent()).to.throw(TypeError, "event type and source are required");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("has retreivable source and type attributes", () => {
|
||||||
|
const ce = new CloudEvent(fixture);
|
||||||
|
expect(ce.source).to.equal("http://unit.test");
|
||||||
|
expect(ce.type).to.equal("org.cncf.cloudevents.example");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("defaults to specversion 1.0", () => {
|
||||||
|
const ce = new CloudEvent(fixture);
|
||||||
|
expect(ce.specversion).to.equal("1.0");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("generates an ID if one is not provided in the constructor", () => {
|
||||||
|
const ce = new CloudEvent(fixture);
|
||||||
|
expect(ce.id).to.not.be.empty;
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can be created with the specversion SPEC_V1", () => {
|
||||||
|
const ce = new CloudEvent({ specversion: SPEC_V1, ...fixture });
|
||||||
|
expect(ce.specversion).to.equal(SPEC_V1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with an ID", () => {
|
||||||
|
const ce = new CloudEvent({ id: 1234, ...fixture });
|
||||||
|
expect(ce.id).to.equal(1234);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("generates a timestamp by default", () => {
|
||||||
|
const ce = new CloudEvent(fixture);
|
||||||
|
expect(ce.time).to.not.be.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a timestamp", () => {
|
||||||
|
const time = new Date();
|
||||||
|
const ce = new CloudEvent({ time, ...fixture });
|
||||||
|
expect(ce.time).to.equal(time.toISOString());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a dataContentType", () => {
|
||||||
|
const ce = new CloudEvent({ dataContentType: "application/json", ...fixture });
|
||||||
|
expect(ce.dataContentType).to.equal("application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a dataSchema", () => {
|
||||||
|
const ce = new CloudEvent({ dataSchema: "http://my.schema", ...fixture });
|
||||||
|
expect(ce.dataSchema).to.equal("http://my.schema");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a subject", () => {
|
||||||
|
const ce = new CloudEvent({ subject: "science", ...fixture });
|
||||||
|
expect(ce.subject).to.equal("science");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle deprecated attribute - should this really throw?
|
||||||
|
it("throws a TypeError when constructed with a schemaurl", () => {
|
||||||
|
expect(() => { new CloudEvent({ schemaURL: "http://throw.com", ...fixture }); })
|
||||||
|
.to.throw(TypeError, "cannot set schemaURL on version 1.0 event");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle deprecated attribute - should this really throw?
|
||||||
|
it("throws a TypeError when getting a schemaURL", () => {
|
||||||
|
const ce = new CloudEvent(fixture);
|
||||||
|
expect(() => { ce.schemaURL; })
|
||||||
|
.to.throw(TypeError, "cannot get schemaURL from version 1.0 event");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with data", () => {
|
||||||
|
const data = { lunch: "tacos" };
|
||||||
|
const ce = new CloudEvent({
|
||||||
|
data, ...fixture
|
||||||
|
});
|
||||||
|
expect(ce.data).to.equal(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws ValidationError if the CloudEvent does not conform to the schema");
|
||||||
|
it("returns a JSON string even if format is invalid");
|
||||||
|
it("correctly formats a CloudEvent as JSON");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("A 0.3 CloudEvent", () => {
|
||||||
|
|
||||||
|
const specversion = { specversion: SPEC_V03 };
|
||||||
|
const v03fixture = { ...specversion, ...fixture };
|
||||||
|
|
||||||
|
it("must be created with a source and type", () => {
|
||||||
|
expect(() => new CloudEvent(specversion)).to.throw(TypeError, "event type and source are required");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("has retreivable source and type attributes", () => {
|
||||||
|
const ce = new CloudEvent(v03fixture);
|
||||||
|
expect(ce.source).to.equal("http://unit.test");
|
||||||
|
expect(ce.type).to.equal("org.cncf.cloudevents.example");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("generates an ID if one is not provided in the constructor", () => {
|
||||||
|
const ce = new CloudEvent(v03fixture);
|
||||||
|
expect(ce.id).to.not.be.empty;
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can be constructed with an ID", () => {
|
||||||
|
const ce = new CloudEvent({ id: 1234, ...v03fixture });
|
||||||
|
expect(ce.id).to.equal(1234);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("generates a timestamp by default", () => {
|
||||||
|
const ce = new CloudEvent(v03fixture);
|
||||||
|
expect(ce.time).to.not.be.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a timestamp", () => {
|
||||||
|
const time = new Date();
|
||||||
|
const ce = new CloudEvent({ time, ...v03fixture });
|
||||||
|
expect(ce.time).to.equal(time.toISOString());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a dataContentType", () => {
|
||||||
|
const ce = new CloudEvent({ dataContentType: "application/json", ...v03fixture });
|
||||||
|
expect(ce.dataContentType).to.equal("application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a dataContentEncoding", () => {
|
||||||
|
const ce = new CloudEvent({ dataContentEncoding: "Base64", ...v03fixture });
|
||||||
|
expect(ce.dataContentEncoding).to.equal("Base64");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a schemaURL", () => {
|
||||||
|
const ce = new CloudEvent({ schemaURL: "http://my.schema", ...v03fixture });
|
||||||
|
expect(ce.schemaURL).to.equal("http://my.schema");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with a subject", () => {
|
||||||
|
const ce = new CloudEvent({ subject: "science", ...v03fixture });
|
||||||
|
expect(ce.subject).to.equal("science");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle 1.0 attribute - should this really throw?
|
||||||
|
it("throws a TypeError when constructed with a dataSchema", () => {
|
||||||
|
expect(() => { new CloudEvent({ dataSchema: "http://throw.com", ...v03fixture }); })
|
||||||
|
.to.throw(TypeError, "cannot set dataSchema on version 0.3 event");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle deprecated attribute - should this really throw?
|
||||||
|
it("throws a TypeError when getting a dataSchema", () => {
|
||||||
|
const ce = new CloudEvent(v03fixture);
|
||||||
|
expect(() => { ce.dataSchema; })
|
||||||
|
.to.throw(TypeError, "cannot get dataSchema from version 0.3 event");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("can be constructed with data", () => {
|
||||||
|
const data = { lunch: "tacos" };
|
||||||
|
const ce = new CloudEvent({
|
||||||
|
data, ...v03fixture
|
||||||
|
});
|
||||||
|
expect(ce.data).to.equal(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws ValidationError if the CloudEvent does not conform to the schema");
|
||||||
|
it("returns a JSON string even if format is invalid");
|
||||||
|
it("correctly formats a CloudEvent as JSON");
|
||||||
|
});
|
|
@ -3,7 +3,6 @@ const nock = require("nock");
|
||||||
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
|
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
|
||||||
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");
|
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");
|
||||||
const CloudEvent = require("../lib/cloudevent.js");
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
const v03 = require("../lib/bindings/http/v03/index.js");
|
|
||||||
const {
|
const {
|
||||||
SPEC_V03
|
SPEC_V03
|
||||||
} = require("../lib/bindings/http/constants.js");
|
} = require("../lib/bindings/http/constants.js");
|
||||||
|
@ -12,8 +11,8 @@ const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resourse/123";
|
const source = "urn:event:from:myapi/resourse/123";
|
||||||
const contentEncoding = "base64";
|
const contentEncoding = "base64";
|
||||||
const contentType = "application/cloudevents+json; charset=utf-8";
|
const contentType = "application/cloudevents+json; charset=utf-8";
|
||||||
const now = new Date();
|
const time = new Date();
|
||||||
const schemaurl = "http://cloudevents.io/schema.json";
|
const schemaURL = "http://cloudevents.io/schema.json";
|
||||||
|
|
||||||
const ceContentType = "application/json";
|
const ceContentType = "application/json";
|
||||||
|
|
||||||
|
@ -27,29 +26,31 @@ const ext1Value = "foobar";
|
||||||
const ext2Name = "extension2";
|
const ext2Name = "extension2";
|
||||||
const ext2Value = "acme";
|
const ext2Value = "acme";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent = new CloudEvent({
|
||||||
new CloudEvent(v03.Spec)
|
specversion: SPEC_V03,
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
dataContentType: ceContentType,
|
||||||
.subject("subject.ext")
|
subject: "subject.ext",
|
||||||
.time(now)
|
time,
|
||||||
.schemaurl(schemaurl)
|
schemaURL,
|
||||||
.data(data)
|
data
|
||||||
.addExtension(ext1Name, ext1Value)
|
});
|
||||||
.addExtension(ext2Name, ext2Value);
|
cloudevent.addExtension(ext1Name, ext1Value);
|
||||||
|
cloudevent.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
const cebase64 =
|
const cebase64 = new CloudEvent({
|
||||||
new CloudEvent(v03.Spec)
|
specversion: SPEC_V03,
|
||||||
.type(type)
|
type,
|
||||||
.source(source)
|
source,
|
||||||
.dataContentType(ceContentType)
|
dataContentType: ceContentType,
|
||||||
.dataContentEncoding(contentEncoding)
|
dataContentEncoding: contentEncoding,
|
||||||
.time(now)
|
time,
|
||||||
.schemaurl(schemaurl)
|
schemaURL,
|
||||||
.data(dataBase64)
|
data: dataBase64
|
||||||
.addExtension(ext1Name, ext1Value)
|
});
|
||||||
.addExtension(ext2Name, ext2Value);
|
cebase64.addExtension(ext1Name, ext1Value);
|
||||||
|
cebase64.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
const webhook = "https://cloudevents.io/webhook";
|
const webhook = "https://cloudevents.io/webhook";
|
||||||
const httpcfg = {
|
const httpcfg = {
|
||||||
|
@ -97,17 +98,17 @@ describe("HTTP Transport Binding - Version 0.3", () => {
|
||||||
|
|
||||||
describe("Binary", () => {
|
describe("Binary", () => {
|
||||||
describe("JSON Format", () => {
|
describe("JSON Format", () => {
|
||||||
it(`requires ${cloudevent.getDataContentType()} in the header`,
|
it(`requires ${cloudevent.dataContentType} in the header`,
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
() => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(response.config.headers["Content-Type"])
|
expect(response.config.headers["Content-Type"])
|
||||||
.to.equal(cloudevent.getDataContentType());
|
.to.equal(cloudevent.dataContentType);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("the request payload should be correct", () => binary.emit(httpcfg, cloudevent)
|
it("the request payload should be correct", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(JSON.parse(response.config.data))
|
expect(JSON.parse(response.config.data))
|
||||||
.to.deep.equal(cloudevent.getData());
|
.to.deep.equal(cloudevent.data);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-type'", () => binary.emit(httpcfg, cloudevent)
|
it("HTTP Header contains 'ce-type'", () => binary.emit(httpcfg, cloudevent)
|
||||||
|
@ -166,40 +167,40 @@ describe("HTTP Transport Binding - Version 0.3", () => {
|
||||||
|
|
||||||
it("should 'ce-type' have the right value", () => binary.emit(httpcfg, cloudevent)
|
it("should 'ce-type' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getType())
|
expect(cloudevent.type)
|
||||||
.to.equal(response.config.headers["ce-type"]);
|
.to.equal(response.config.headers["ce-type"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should 'ce-specversion' have the right value",
|
it("should 'ce-specversion' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
() => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getSpecversion())
|
expect(cloudevent.specversion)
|
||||||
.to.equal(response.config.headers["ce-specversion"]);
|
.to.equal(response.config.headers["ce-specversion"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should 'ce-source' have the right value",
|
it("should 'ce-source' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
() => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getSource())
|
expect(cloudevent.source)
|
||||||
.to.equal(response.config.headers["ce-source"]);
|
.to.equal(response.config.headers["ce-source"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should 'ce-id' have the right value", () => binary.emit(httpcfg, cloudevent)
|
it("should 'ce-id' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getId())
|
expect(cloudevent.id)
|
||||||
.to.equal(response.config.headers["ce-id"]);
|
.to.equal(response.config.headers["ce-id"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should 'ce-time' have the right value", () => binary.emit(httpcfg, cloudevent)
|
it("should 'ce-time' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getTime())
|
expect(cloudevent.time)
|
||||||
.to.equal(response.config.headers["ce-time"]);
|
.to.equal(response.config.headers["ce-time"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("should 'ce-schemaurl' have the right value",
|
it("should 'ce-schemaurl' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
() => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getSchemaurl())
|
expect(cloudevent.schemaURL)
|
||||||
.to.equal(response.config.headers["ce-schemaurl"]);
|
.to.equal(response.config.headers["ce-schemaurl"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -220,7 +221,7 @@ describe("HTTP Transport Binding - Version 0.3", () => {
|
||||||
it("should 'ce-subject' have the right value",
|
it("should 'ce-subject' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
() => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cloudevent.getSubject())
|
expect(cloudevent.subject)
|
||||||
.to.equal(response.config.headers["ce-subject"]);
|
.to.equal(response.config.headers["ce-subject"]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -235,7 +236,7 @@ describe("HTTP Transport Binding - Version 0.3", () => {
|
||||||
it("should 'ce-datacontentencoding' have the right value",
|
it("should 'ce-datacontentencoding' have the right value",
|
||||||
() => binary.emit(httpcfg, cebase64)
|
() => binary.emit(httpcfg, cebase64)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
expect(cebase64.getDataContentEncoding())
|
expect(cebase64.dataContentEncoding)
|
||||||
.to.equal(response.config.headers["ce-datacontentencoding"]);
|
.to.equal(response.config.headers["ce-datacontentencoding"]);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,21 +2,18 @@ const expect = require("chai").expect;
|
||||||
const nock = require("nock");
|
const nock = require("nock");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
|
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
|
||||||
const {
|
const { SPEC_V1 } = require("../lib/bindings/http/constants.js");
|
||||||
SPEC_V1
|
|
||||||
} = require("../lib/bindings/http/constants.js");
|
|
||||||
|
|
||||||
const { Spec } = require("../lib/bindings/http/v1/index.js");
|
|
||||||
const CloudEvent = require("../lib/cloudevent.js");
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
|
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
|
||||||
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");
|
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resource/123";
|
const source = "urn:event:from:myapi/resource/123";
|
||||||
const contentType = "application/cloudevents+json; charset=utf-8";
|
const contentType = "application/cloudevents+json; charset=utf-8";
|
||||||
const now = new Date();
|
const time = new Date();
|
||||||
const dataschema = "http://cloudevents.io/schema.json";
|
const subject = "subject.ext";
|
||||||
|
const dataSchema = "http://cloudevents.io/schema.json";
|
||||||
|
|
||||||
const ceContentType = "application/json";
|
const dataContentType = "application/json";
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
foo: "bar"
|
foo: "bar"
|
||||||
|
@ -27,16 +24,18 @@ const ext1Value = "foobar";
|
||||||
const ext2Name = "extension2";
|
const ext2Name = "extension2";
|
||||||
const ext2Value = "acme";
|
const ext2Value = "acme";
|
||||||
|
|
||||||
const cloudevent = new CloudEvent(Spec)
|
const cloudevent = new CloudEvent({
|
||||||
.type(type)
|
specversion: SPEC_V1,
|
||||||
.source(source)
|
type,
|
||||||
.dataContentType(ceContentType)
|
source,
|
||||||
.subject("subject.ext")
|
dataContentType,
|
||||||
.time(now)
|
subject,
|
||||||
.dataschema(dataschema)
|
time,
|
||||||
.data(data)
|
dataSchema,
|
||||||
.addExtension(ext1Name, ext1Value)
|
data
|
||||||
.addExtension(ext2Name, ext2Value);
|
});
|
||||||
|
cloudevent.addExtension(ext1Name, ext1Value);
|
||||||
|
cloudevent.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
const dataString = ")(*~^my data for ce#@#$%";
|
const dataString = ")(*~^my data for ce#@#$%";
|
||||||
|
|
||||||
|
@ -92,14 +91,14 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
it("the request payload should be correct when data is binary", () => {
|
it("the request payload should be correct when data is binary", () => {
|
||||||
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
||||||
const expected = asBase64(bindata);
|
const expected = asBase64(bindata);
|
||||||
const binevent =
|
const binevent = new CloudEvent({
|
||||||
new CloudEvent(Spec)
|
type,
|
||||||
.type(type)
|
source,
|
||||||
.source(source)
|
dataContentType: "text/plain",
|
||||||
.dataContentType("text/plain")
|
data: bindata,
|
||||||
.data(bindata)
|
});
|
||||||
.addExtension(ext1Name, ext1Value)
|
binevent.addExtension(ext1Name, ext1Value);
|
||||||
.addExtension(ext2Name, ext2Value);
|
binevent.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
return structured.emit(httpcfg, binevent)
|
return structured.emit(httpcfg, binevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -109,14 +108,14 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("the payload must have 'data_base64' when data is binary", () => {
|
it("the payload must have 'data_base64' when data is binary", () => {
|
||||||
const binevent =
|
const binevent = new CloudEvent({
|
||||||
new CloudEvent(Spec)
|
type,
|
||||||
.type(type)
|
source,
|
||||||
.source(source)
|
dataContentType: "text/plain",
|
||||||
.dataContentType("text/plain")
|
data: Uint32Array.from(dataString, (c) => c.codePointAt(0)),
|
||||||
.data(Uint32Array.from(dataString, (c) => c.codePointAt(0)))
|
});
|
||||||
.addExtension(ext1Name, ext1Value)
|
binevent.addExtension(ext1Name, ext1Value);
|
||||||
.addExtension(ext2Name, ext2Value);
|
binevent.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
return structured.emit(httpcfg, binevent)
|
return structured.emit(httpcfg, binevent)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -128,168 +127,167 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Binary", () => {
|
// describe("Binary", () => {
|
||||||
it("works with mTLS authentication", () =>
|
// it("works with mTLS authentication", () =>
|
||||||
binary.emit({
|
// binary.emit({
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
url: `${webhook}/json`,
|
// url: `${webhook}/json`,
|
||||||
httpsAgent: new https.Agent({
|
// httpsAgent: new https.Agent({
|
||||||
cert: "some value",
|
// cert: "some value",
|
||||||
key: "other value"
|
// key: "other value"
|
||||||
})
|
// })
|
||||||
}, cloudevent).then((response) => {
|
// }, cloudevent).then((response) => {
|
||||||
expect(response.config.headers["Content-Type"])
|
// expect(response.config.headers["Content-Type"])
|
||||||
.to.equal(cloudevent.getDataContentType());
|
// .to.equal(cloudevent.dataContentType);
|
||||||
})
|
// })
|
||||||
);
|
// );
|
||||||
|
|
||||||
describe("JSON Format", () => {
|
// describe("JSON Format", () => {
|
||||||
it(`requires '${cloudevent.getDataContentType()}' in the header`,
|
// it(`requires '${cloudevent.dataContentType}' in the header`,
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers["Content-Type"])
|
// expect(response.config.headers["Content-Type"])
|
||||||
.to.equal(cloudevent.getDataContentType());
|
// .to.equal(cloudevent.dataContentType);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("the request payload should be correct", () => binary.emit(httpcfg, cloudevent)
|
// it("the request payload should be correct", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(JSON.parse(response.config.data))
|
// expect(JSON.parse(response.config.data))
|
||||||
.to.deep.equal(cloudevent.getData());
|
// .to.deep.equal(cloudevent.data);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("the request payload should be correct when event data is binary",
|
// it("the request payload should be correct when event data is binary", () => {
|
||||||
() => {
|
// const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
||||||
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
// const expected = asBase64(bindata);
|
||||||
const expected = asBase64(bindata);
|
// const binevent = new CloudEvent({
|
||||||
const binevent =
|
// type,
|
||||||
new CloudEvent(Spec)
|
// source,
|
||||||
.type(type)
|
// dataContentType: "text/plain",
|
||||||
.source(source)
|
// data: bindata,
|
||||||
.dataContentType("text/plain")
|
// });
|
||||||
.data(bindata)
|
// binevent.addExtension(ext1Name, ext1Value);
|
||||||
.addExtension(ext1Name, ext1Value)
|
// binevent.addExtension(ext2Name, ext2Value);
|
||||||
.addExtension(ext2Name, ext2Value);
|
|
||||||
|
|
||||||
return binary.emit(httpcfg, binevent)
|
// return binary.emit(httpcfg, binevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.data)
|
// expect(response.config.data)
|
||||||
.to.equal(expected);
|
// .to.equal(expected);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-type'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-type'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-type");
|
// .to.have.property("ce-type");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-specversion'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-specversion'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-specversion");
|
// .to.have.property("ce-specversion");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-source'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-source'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-source");
|
// .to.have.property("ce-source");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-id'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-id'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-id");
|
// .to.have.property("ce-id");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-time'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-time'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-time");
|
// .to.have.property("ce-time");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-dataschema'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-dataschema'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-dataschema");
|
// .to.have.property("ce-dataschema");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it(`HTTP Header contains 'ce-${ext1Name}'`, () => binary.emit(httpcfg, cloudevent)
|
// it(`HTTP Header contains 'ce-${ext1Name}'`, () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property(`ce-${ext1Name}`);
|
// .to.have.property(`ce-${ext1Name}`);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it(`HTTP Header contains 'ce-${ext2Name}'`, () => binary.emit(httpcfg, cloudevent)
|
// it(`HTTP Header contains 'ce-${ext2Name}'`, () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property(`ce-${ext2Name}`);
|
// .to.have.property(`ce-${ext2Name}`);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("HTTP Header contains 'ce-subject'", () => binary.emit(httpcfg, cloudevent)
|
// it("HTTP Header contains 'ce-subject'", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(response.config.headers)
|
// expect(response.config.headers)
|
||||||
.to.have.property("ce-subject");
|
// .to.have.property("ce-subject");
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-type' have the right value", () => binary.emit(httpcfg, cloudevent)
|
// it("should 'ce-type' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getType())
|
// expect(cloudevent.type)
|
||||||
.to.equal(response.config.headers["ce-type"]);
|
// .to.equal(response.config.headers["ce-type"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-specversion' have the right value",
|
// it("should 'ce-specversion' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getSpecversion())
|
// expect(cloudevent.specversion)
|
||||||
.to.equal(response.config.headers["ce-specversion"]);
|
// .to.equal(response.config.headers["ce-specversion"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-source' have the right value",
|
// it("should 'ce-source' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getSource())
|
// expect(cloudevent.source)
|
||||||
.to.equal(response.config.headers["ce-source"]);
|
// .to.equal(response.config.headers["ce-source"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-id' have the right value", () => binary.emit(httpcfg, cloudevent)
|
// it("should 'ce-id' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getId())
|
// expect(cloudevent.id)
|
||||||
.to.equal(response.config.headers["ce-id"]);
|
// .to.equal(response.config.headers["ce-id"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-time' have the right value", () => binary.emit(httpcfg, cloudevent)
|
// it("should 'ce-time' have the right value", () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getTime())
|
// expect(cloudevent.time)
|
||||||
.to.equal(response.config.headers["ce-time"]);
|
// .to.equal(response.config.headers["ce-time"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-dataschema' have the right value",
|
// it("should 'ce-dataschema' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getDataschema())
|
// expect(cloudevent.dataSchema)
|
||||||
.to.equal(response.config.headers["ce-dataschema"]);
|
// .to.equal(response.config.headers["ce-dataschema"]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it(`should 'ce-${ext1Name}' have the right value`,
|
// it(`should 'ce-${ext1Name}' have the right value`,
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getExtensions()[ext1Name])
|
// expect(cloudevent.getExtensions()[ext1Name])
|
||||||
.to.equal(response.config.headers[`ce-${ext1Name}`]);
|
// .to.equal(response.config.headers[`ce-${ext1Name}`]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it(`should 'ce-${ext2Name}' have the right value`,
|
// it(`should 'ce-${ext2Name}' have the right value`,
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getExtensions()[ext2Name])
|
// expect(cloudevent.getExtensions()[ext2Name])
|
||||||
.to.equal(response.config.headers[`ce-${ext2Name}`]);
|
// .to.equal(response.config.headers[`ce-${ext2Name}`]);
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it("should 'ce-subject' have the right value",
|
// it("should 'ce-subject' have the right value",
|
||||||
() => binary.emit(httpcfg, cloudevent)
|
// () => binary.emit(httpcfg, cloudevent)
|
||||||
.then((response) => {
|
// .then((response) => {
|
||||||
expect(cloudevent.getSubject())
|
// expect(cloudevent.subject)
|
||||||
.to.equal(response.config.headers["ce-subject"]);
|
// .to.equal(response.config.headers["ce-subject"]);
|
||||||
}));
|
// }));
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,9 +7,14 @@ const {
|
||||||
SPEC_V1
|
SPEC_V1
|
||||||
} = require("../lib/bindings/http/constants.js");
|
} = require("../lib/bindings/http/constants.js");
|
||||||
|
|
||||||
|
const fixture = {
|
||||||
|
type: "org.cloudevents.test",
|
||||||
|
source: "http://cloudevents.io"
|
||||||
|
};
|
||||||
|
|
||||||
describe("The SDK Requirements", () => {
|
describe("The SDK Requirements", () => {
|
||||||
it("should expose a CloudEvent type", () => {
|
it("should expose a CloudEvent type", () => {
|
||||||
const event = new CloudEvent();
|
const event = new CloudEvent(fixture);
|
||||||
expect(event instanceof CloudEvent).to.equal(true);
|
expect(event instanceof CloudEvent).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -27,13 +32,16 @@ describe("The SDK Requirements", () => {
|
||||||
|
|
||||||
describe("v0.3", () => {
|
describe("v0.3", () => {
|
||||||
it("should create an event using the right spec version", () => {
|
it("should create an event using the right spec version", () => {
|
||||||
expect(new CloudEvent(SpecV03).spec.payload.specversion).to.equal(SPEC_V03);
|
expect(new CloudEvent({
|
||||||
|
specversion: SPEC_V03,
|
||||||
|
...fixture
|
||||||
|
}).spec.payload.specversion).to.equal(SPEC_V03);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("v1.0", () => {
|
describe("v1.0", () => {
|
||||||
it("should create an event using the right spec version", () => {
|
it("should create an event using the right spec version", () => {
|
||||||
expect(new CloudEvent(SpecV1).spec.payload.specversion).to.equal(SPEC_V1);
|
expect(new CloudEvent(fixture).spec.payload.specversion).to.equal(SPEC_V1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,68 +13,69 @@ const id = "97699ec2-a8d9-47c1-bfa0-ff7aa526f838";
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resourse/123";
|
const source = "urn:event:from:myapi/resourse/123";
|
||||||
const time = new Date();
|
const time = new Date();
|
||||||
const schemaurl = "http://example.com/registry/myschema.json";
|
const schemaURL = "http://example.com/registry/myschema.json";
|
||||||
const data = {
|
const data = {
|
||||||
much: "wow"
|
much: "wow"
|
||||||
};
|
};
|
||||||
const subject = "subject-x0";
|
const subject = "subject-x0";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent = new CloudEvent({
|
||||||
new CloudEvent(Spec03)
|
specversion: SPEC_V03,
|
||||||
.id(id)
|
id,
|
||||||
.source(source)
|
source,
|
||||||
.type(type)
|
type,
|
||||||
.dataContentType(MIME_JSON)
|
subject,
|
||||||
.schemaurl(schemaurl)
|
time,
|
||||||
.subject(subject)
|
data,
|
||||||
.time(time)
|
schemaURL,
|
||||||
.data(data);
|
dataContentType: MIME_JSON
|
||||||
|
});
|
||||||
|
|
||||||
describe("CloudEvents Spec v0.3", () => {
|
describe("CloudEvents Spec v0.3", () => {
|
||||||
describe("REQUIRED Attributes", () => {
|
describe("REQUIRED Attributes", () => {
|
||||||
it("Should have 'id'", () => {
|
it("Should have 'id'", () => {
|
||||||
expect(cloudevent.getId()).to.equal(id);
|
expect(cloudevent.id).to.equal(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'source'", () => {
|
it("Should have 'source'", () => {
|
||||||
expect(cloudevent.getSource()).to.equal(source);
|
expect(cloudevent.source).to.equal(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'specversion'", () => {
|
it("Should have 'specversion'", () => {
|
||||||
expect(cloudevent.getSpecversion()).to.equal(SPEC_V03);
|
expect(cloudevent.specversion).to.equal(SPEC_V03);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'type'", () => {
|
it("Should have 'type'", () => {
|
||||||
expect(cloudevent.getType()).to.equal(type);
|
expect(cloudevent.type).to.equal(type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("OPTIONAL Attributes", () => {
|
describe("OPTIONAL Attributes", () => {
|
||||||
it("Should have 'datacontentencoding'", () => {
|
it("Should have 'datacontentencoding'", () => {
|
||||||
cloudevent.dataContentEncoding(ENCODING_BASE64);
|
cloudevent.dataContentEncoding = ENCODING_BASE64;
|
||||||
expect(cloudevent.spec.payload.datacontentencoding)
|
expect(cloudevent.spec.payload.datacontentencoding)
|
||||||
.to.equal(ENCODING_BASE64);
|
.to.equal(ENCODING_BASE64);
|
||||||
delete cloudevent.spec.payload.datacontentencoding;
|
delete cloudevent.spec.payload.datacontentencoding;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'datacontenttype'", () => {
|
it("Should have 'datacontenttype'", () => {
|
||||||
expect(cloudevent.getDataContentType()).to.equal(MIME_JSON);
|
expect(cloudevent.dataContentType).to.equal(MIME_JSON);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'schemaurl'", () => {
|
it("Should have 'schemaurl'", () => {
|
||||||
expect(cloudevent.getSchemaurl()).to.equal(schemaurl);
|
expect(cloudevent.schemaURL).to.equal(schemaURL);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'subject'", () => {
|
it("Should have 'subject'", () => {
|
||||||
expect(cloudevent.getSubject()).to.equal(subject);
|
expect(cloudevent.subject).to.equal(subject);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'time'", () => {
|
it("Should have 'time'", () => {
|
||||||
expect(cloudevent.getTime()).to.equal(time.toISOString());
|
expect(cloudevent.time).to.equal(time.toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'data'", () => {
|
it("Should have 'data'", () => {
|
||||||
expect(cloudevent.getData()).to.deep.equal(data);
|
expect(cloudevent.data).to.deep.equal(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have the 'extension1'", () => {
|
it("Should have the 'extension1'", () => {
|
||||||
|
@ -98,7 +99,7 @@ describe("CloudEvents Spec v0.3", () => {
|
||||||
cloudevent.spec.payload.id = id;
|
cloudevent.spec.payload.id = id;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an erro when is empty", () => {
|
it("should throw an error when is empty", () => {
|
||||||
cloudevent.spec.payload.id = "";
|
cloudevent.spec.payload.id = "";
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
|
@ -140,83 +141,77 @@ describe("CloudEvents Spec v0.3", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when is an empty string", () => {
|
it("should throw an error when is an empty string", () => {
|
||||||
cloudevent.type("");
|
cloudevent.type = "";
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
cloudevent.type(type);
|
cloudevent.type = type;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("must be a non-empty string", () => {
|
it("must be a non-empty string", () => {
|
||||||
cloudevent.type(type);
|
cloudevent.type = type;
|
||||||
expect(cloudevent.spec.payload.type).to.equal(type);
|
expect(cloudevent.spec.payload.type).to.equal(type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'datacontentencoding'", () => {
|
describe("'datacontentencoding'", () => {
|
||||||
it("should throw an error when is a unsupported encoding", () => {
|
it("should throw an error when is a unsupported encoding", () => {
|
||||||
cloudevent
|
cloudevent.data = "Y2xvdWRldmVudHMK";
|
||||||
.data("Y2xvdWRldmVudHMK")
|
cloudevent.dataContentEncoding = BINARY;
|
||||||
.dataContentEncoding(BINARY);
|
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
delete cloudevent.spec.payload.datacontentencoding;
|
delete cloudevent.spec.payload.datacontentencoding;
|
||||||
cloudevent.data(data);
|
cloudevent.data = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when 'data' does not carry base64",
|
it("should throw an error when 'data' does not carry base64",
|
||||||
() => {
|
() => {
|
||||||
cloudevent
|
cloudevent.data = "no base 64 value";
|
||||||
.data("no base 64 value")
|
cloudevent.dataContentEncoding = ENCODING_BASE64;
|
||||||
.dataContentEncoding(ENCODING_BASE64)
|
cloudevent.dataContentType = "text/plain";
|
||||||
.dataContentType("text/plain");
|
|
||||||
|
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
|
|
||||||
delete cloudevent.spec.payload.datacontentencoding;
|
delete cloudevent.spec.payload.datacontentencoding;
|
||||||
cloudevent.data(data);
|
cloudevent.data = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should accept when 'data' is a string", () => {
|
it("should accept when 'data' is a string", () => {
|
||||||
cloudevent
|
cloudevent.data = "Y2xvdWRldmVudHMK";
|
||||||
.data("Y2xvdWRldmVudHMK")
|
cloudevent.dataContentEncoding = ENCODING_BASE64;
|
||||||
.dataContentEncoding(ENCODING_BASE64);
|
|
||||||
expect(cloudevent.format()).to.have.property("datacontentencoding");
|
expect(cloudevent.format()).to.have.property("datacontentencoding");
|
||||||
delete cloudevent.spec.payload.datacontentencoding;
|
delete cloudevent.spec.payload.datacontentencoding;
|
||||||
cloudevent.data(data);
|
cloudevent.data = data;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'data'", () => {
|
describe("'data'", () => {
|
||||||
it("should maintain the type of data when no data content type", () => {
|
it("should maintain the type of data when no data content type", () => {
|
||||||
delete cloudevent.spec.payload.datacontenttype;
|
delete cloudevent.spec.payload.datacontenttype;
|
||||||
cloudevent
|
cloudevent.data = JSON.stringify(data);
|
||||||
.data(JSON.stringify(data));
|
|
||||||
|
|
||||||
expect(typeof cloudevent.getData()).to.equal("string");
|
expect(typeof cloudevent.data).to.equal("string");
|
||||||
cloudevent.dataContentType(MIME_JSON);
|
cloudevent.dataContentType = MIME_JSON;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert data with stringified json to a json object", () => {
|
it("should convert data with stringified json to a json object", () => {
|
||||||
cloudevent
|
cloudevent.dataContentType = MIME_JSON;
|
||||||
.dataContentType(MIME_JSON)
|
cloudevent.data = JSON.stringify(data);
|
||||||
.data(JSON.stringify(data));
|
expect(cloudevent.data).to.deep.equal(data);
|
||||||
expect(cloudevent.getData()).to.deep.equal(data);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'subject'", () => {
|
describe("'subject'", () => {
|
||||||
it("should throw an error when is an empty string", () => {
|
it("should throw an error when is an empty string", () => {
|
||||||
cloudevent.subject("");
|
cloudevent.subject = "";
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
cloudevent.subject(type);
|
cloudevent.subject = subject;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'time'", () => {
|
describe("'time'", () => {
|
||||||
it("must adhere to the format specified in RFC 3339", () => {
|
it("must adhere to the format specified in RFC 3339", () => {
|
||||||
cloudevent.time(time);
|
|
||||||
expect(cloudevent.format().time).to.equal(time.toISOString());
|
expect(cloudevent.format().time).to.equal(time.toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,66 +1,69 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const Spec1 = require("../lib/bindings/http/v1/spec_1.js");
|
|
||||||
const { CloudEvent } = require("../index.js");
|
const { CloudEvent } = require("../index.js");
|
||||||
const { v4: uuidv4 } = require("uuid");
|
const { v4: uuidv4 } = require("uuid");
|
||||||
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
|
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
|
||||||
const ValidationError = require("../lib/bindings/http/validation/validation_error.js");
|
const ValidationError = require("../lib/bindings/http/validation/validation_error.js");
|
||||||
|
const {
|
||||||
|
SPEC_V1
|
||||||
|
} = require("../lib/bindings/http/constants.js");
|
||||||
|
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
const source = "urn:event:from:myapi/resource/123";
|
const source = "urn:event:from:myapi/resource/123";
|
||||||
const time = new Date();
|
const time = new Date();
|
||||||
const dataschema = "http://example.com/registry/myschema.json";
|
const dataSchema = "http://example.com/registry/myschema.json";
|
||||||
const dataContentType = "application/json";
|
const dataContentType = "application/json";
|
||||||
const data = {
|
const data = {
|
||||||
much: "wow"
|
much: "wow"
|
||||||
};
|
};
|
||||||
const subject = "subject-x0";
|
const subject = "subject-x0";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent = new CloudEvent({
|
||||||
new CloudEvent(Spec1)
|
specversion: SPEC_V1,
|
||||||
.id(id)
|
id,
|
||||||
.source(source)
|
source,
|
||||||
.type(type)
|
type,
|
||||||
.dataContentType(dataContentType)
|
dataContentType,
|
||||||
.dataschema(dataschema)
|
dataSchema,
|
||||||
.subject(subject)
|
subject,
|
||||||
.time(time)
|
time,
|
||||||
.data(data);
|
data
|
||||||
|
});
|
||||||
|
|
||||||
describe("CloudEvents Spec v1.0", () => {
|
describe("CloudEvents Spec v1.0", () => {
|
||||||
describe("REQUIRED Attributes", () => {
|
describe("REQUIRED Attributes", () => {
|
||||||
it("Should have 'id'", () => {
|
it("Should have 'id'", () => {
|
||||||
expect(cloudevent.getId()).to.equal(id);
|
expect(cloudevent.id).to.equal(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'source'", () => {
|
it("Should have 'source'", () => {
|
||||||
expect(cloudevent.getSource()).to.equal(source);
|
expect(cloudevent.source).to.equal(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'specversion'", () => {
|
it("Should have 'specversion'", () => {
|
||||||
expect(cloudevent.getSpecversion()).to.equal("1.0");
|
expect(cloudevent.specversion).to.equal("1.0");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'type'", () => {
|
it("Should have 'type'", () => {
|
||||||
expect(cloudevent.getType()).to.equal(type);
|
expect(cloudevent.type).to.equal(type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("OPTIONAL Attributes", () => {
|
describe("OPTIONAL Attributes", () => {
|
||||||
it("Should have 'datacontenttype'", () => {
|
it("Should have 'datacontenttype'", () => {
|
||||||
expect(cloudevent.getDataContentType()).to.equal(dataContentType);
|
expect(cloudevent.dataContentType).to.equal(dataContentType);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'dataschema'", () => {
|
it("Should have 'dataschema'", () => {
|
||||||
expect(cloudevent.getDataschema()).to.equal(dataschema);
|
expect(cloudevent.dataSchema).to.equal(dataSchema);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'subject'", () => {
|
it("Should have 'subject'", () => {
|
||||||
expect(cloudevent.getSubject()).to.equal(subject);
|
expect(cloudevent.subject).to.equal(subject);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have 'time'", () => {
|
it("Should have 'time'", () => {
|
||||||
expect(cloudevent.getTime()).to.equal(time.toISOString());
|
expect(cloudevent.time).to.equal(time.toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -169,30 +172,30 @@ describe("CloudEvents Spec v1.0", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when is an empty string", () => {
|
it("should throw an error when is an empty string", () => {
|
||||||
cloudevent.type("");
|
cloudevent.type = "";
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
cloudevent.type(type);
|
cloudevent.type = type;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("must be a non-empty string", () => {
|
it("must be a non-empty string", () => {
|
||||||
cloudevent.type(type);
|
cloudevent.type = type;
|
||||||
expect(cloudevent.spec.payload.type).to.equal(type);
|
expect(cloudevent.spec.payload.type).to.equal(type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'subject'", () => {
|
describe("'subject'", () => {
|
||||||
it("should throw an error when is an empty string", () => {
|
it("should throw an error when is an empty string", () => {
|
||||||
cloudevent.subject("");
|
cloudevent.subject = "";
|
||||||
expect(cloudevent.format.bind(cloudevent))
|
expect(cloudevent.format.bind(cloudevent))
|
||||||
.to.throw(ValidationError, "invalid payload");
|
.to.throw(ValidationError, "invalid payload");
|
||||||
cloudevent.subject(type);
|
cloudevent.subject = type;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("'time'", () => {
|
describe("'time'", () => {
|
||||||
it("must adhere to the format specified in RFC 3339", () => {
|
it("must adhere to the format specified in RFC 3339", () => {
|
||||||
cloudevent.time(time);
|
cloudevent.time = time;
|
||||||
expect(cloudevent.format().time).to.equal(time.toISOString());
|
expect(cloudevent.format().time).to.equal(time.toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -200,23 +203,21 @@ describe("CloudEvents Spec v1.0", () => {
|
||||||
|
|
||||||
describe("Event data constraints", () => {
|
describe("Event data constraints", () => {
|
||||||
it("Should have 'data'", () => {
|
it("Should have 'data'", () => {
|
||||||
expect(cloudevent.getData()).to.deep.equal(data);
|
expect(cloudevent.data).to.deep.equal(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should maintain the type of data when no data content type", () => {
|
it("should maintain the type of data when no data content type", () => {
|
||||||
delete cloudevent.spec.payload.datacontenttype;
|
delete cloudevent.spec.payload.datacontenttype;
|
||||||
cloudevent
|
cloudevent.data = JSON.stringify(data);
|
||||||
.data(JSON.stringify(data));
|
|
||||||
|
|
||||||
expect(typeof cloudevent.getData()).to.equal("string");
|
expect(typeof cloudevent.data).to.equal("string");
|
||||||
cloudevent.dataContentType(dataContentType);
|
cloudevent.dataContentType = dataContentType;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert data with stringified json to a json object", () => {
|
it("should convert data with stringified json to a json object", () => {
|
||||||
cloudevent
|
cloudevent.dataContentType = dataContentType;
|
||||||
.dataContentType(dataContentType)
|
cloudevent.data = JSON.stringify(data);
|
||||||
.data(JSON.stringify(data));
|
expect(cloudevent.data).to.deep.equal(data);
|
||||||
expect(cloudevent.getData()).to.deep.equal(data);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be ok when type is 'Uint32Array' for 'Binary'", () => {
|
it("should be ok when type is 'Uint32Array' for 'Binary'", () => {
|
||||||
|
@ -224,14 +225,13 @@ describe("CloudEvents Spec v1.0", () => {
|
||||||
|
|
||||||
const dataBinary = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
const dataBinary = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
||||||
const expected = asBase64(dataBinary);
|
const expected = asBase64(dataBinary);
|
||||||
const olddct = cloudevent.getDataContentType();
|
const olddct = cloudevent.dataContentType;
|
||||||
|
|
||||||
cloudevent
|
cloudevent.dataContentType = "text/plain";
|
||||||
.dataContentType("text/plain")
|
cloudevent.data = dataBinary;
|
||||||
.data(dataBinary);
|
expect(cloudevent.data).to.deep.equal(expected);
|
||||||
expect(cloudevent.getData()).to.deep.equal(expected);
|
|
||||||
|
|
||||||
cloudevent.dataContentType(olddct);
|
cloudevent.dataContentType = olddct;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue