sdk-javascript/docs/CloudEvent.html

2130 lines
29 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
CloudEvent - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<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>
<div id="main">
<h1 class="page-title">
CloudEvent
</h1>
<section>
<header>
<h2>
CloudEvent
</h2>
<div class="class-description">
<p>An CloudEvent describes event data in common formats to provide
interopability across services, platforms and systems.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#CloudEvent">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="CloudEvent">
<span class="type-signature"></span>new CloudEvent<span class="signature">(options)</span><span class="type-signature"></span>
</h4>
</span>
<div class="description">
<p>Creates a new CloudEvent instance</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
object
</span>
</td>
<td class="description last">
<p>CloudEvent properties as a simple object</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>source</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>Identifies the context in which an event happened as a URI reference</p>
</td>
</tr>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>Describes the type of event related to the originating occurrence</p>
</td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>A unique ID for this event - if not supplied, will be autogenerated</p>
</td>
</tr>
<tr>
<td class="name"><code>time</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>A timestamp for this event. May also be provided as a Date</p>
</td>
</tr>
<tr>
<td class="name"><code>subject</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>Describes the subject of the event in the context of the event producer</p>
</td>
</tr>
<tr>
<td class="name"><code>dataContentType</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The mime content type for the event data</p>
</td>
</tr>
<tr>
<td class="name"><code>dataSchema</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The URI of the schema that the event data adheres to (v1.0 events)</p>
</td>
</tr>
<tr>
<td class="name"><code>schemaURL</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The URI of the schema that the event data adheres to (v0.3 events)</p>
</td>
</tr>
<tr>
<td class="name"><code>dataContentEncoding</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The content encoding for the event data (v0.3 events)</p>
</td>
</tr>
<tr>
<td class="name"><code>specversion</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The CloudEvent specification version for this event - default: 1.0</p>
</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">
*
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The event payload</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line29">line 29</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md">https://github.com/cloudevents/spec/blob/v1.0/spec.md</a>
</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="data">
<span class="type-signature"></span>data<span class="type-signature"> :*</span>
</h4>
<div class="description">
<p>Gets or sets the data for this event</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line252">line 252</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#event-data">https://github.com/cloudevents/spec/blob/master/spec.md#event-data</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="dataContentEncoding">
<span class="type-signature"></span>dataContentEncoding<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the event's data content encoding</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line183">line 183</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding">https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="dataContentType">
<span class="type-signature"></span>dataContentType<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the content type of the data value for this event</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line150">line 150</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype">https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="dataSchema">
<span class="type-signature"></span>dataSchema<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the event's data schema</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line163">line 163</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema">https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="id">
<span class="type-signature"></span>id<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the event id. Source + id must be unique for each distinct event.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line102">line 102</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#id">https://github.com/cloudevents/spec/blob/master/spec.md#id</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="schemaURL">
<span class="type-signature"></span>schemaURL<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError}
if this is a version 1.0 event.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line230">line 230</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl">https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="source">
<span class="type-signature"></span>source<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the origination source of this event as a URI.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line115">line 115</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#source-1">https://github.com/cloudevents/spec/blob/master/spec.md#source-1</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="specversion">
<span class="type-signature"></span>specversion<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets the CloudEvent specification version</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line128">line 128</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#specversion">https://github.com/cloudevents/spec/blob/master/spec.md#specversion</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="subject">
<span class="type-signature"></span>subject<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the event subject</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line203">line 203</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject">https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="time">
<span class="type-signature"></span>time<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the timestamp for this event as an ISO formatted date string</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line216">line 216</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#time">https://github.com/cloudevents/spec/blob/master/spec.md#time</a>
</li>
</ul>
</dd>
</dl>
<h4 class="name" id="type">
<span class="type-signature"></span>type<span class="type-signature"> :string</span>
</h4>
<div class="description">
<p>Gets or sets the event type</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line137">line 137</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#type">https://github.com/cloudevents/spec/blob/master/spec.md#type</a>
</li>
</ul>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#addExtension">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="addExtension">
<span class="type-signature"></span>addExtension<span class="signature">(key, value)</span><span class="type-signature"> &rarr; {void}</span>
</h4>
</span>
<div class="description">
<p>Adds an extension attribute to this CloudEvent</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>key</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="description last">
<p>the name of the extension attribute</p>
</td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">
*
</span>
</td>
<td class="description last">
<p>the value of the extension attribute</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line303">line 303</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes">https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#format">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="format">
<span class="type-signature"></span>format<span class="signature">()</span><span class="type-signature"> &rarr; {JSON}</span>
</h4>
</span>
<div class="description">
<p>Formats the CloudEvent as JSON. Validates the event according
to the CloudEvent specification and throws an exception if
it's invalid.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line267">line 267</a>
</li>
</ul>
</dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>if this event cannot be validated against the specification</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>Type</dt>
<dd>
<span class="param-type">
<a href="ValidationError.html">ValidationError</a>
</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#getExtensions">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="getExtensions">
<span class="type-signature"></span>getExtensions<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span>
</h4>
</span>
<div class="description">
<p>Gets the extension attributes, if any, associated with this event</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line313">line 313</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes">https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#toString">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="toString">
<span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span>
</h4>
</span>
<div class="description">
<p>Formats the CloudEvent as JSON. No specification validation is performed.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="cloudevent.js.html">cloudevent.js</a>, <a href="cloudevent.js.html#line292">line 292</a>
</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>