Constructor
new CloudEvent(idnon-null, typenon-null, sourcenon-null, datanullable, optionsopt, extensionsnullable)
Create a new instance of a CloudEvent object.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
id |
string | the ID of the event (unique), mandatory | ||
type |
string | the type of the event (usually prefixed with a reverse-DNS name), mandatory | ||
source |
uri | the source uri of the event (use '/' if empty), mandatory | ||
data |
object | Map | Set | string |
<nullable> |
the real event data | |
options |
object |
<optional> |
{} | optional attributes of the event; some has default values chosen here: - time (timestamp in string ISO representation, from a date, default now), - datainbase64 (string) base64 encoded value for the data (data attribute must not be present when this is defined), - datacontenttype (string, default 'application/json') is the content type of the data attribute, - dataschema (uri) optional, reference to the schema that data adheres to, - subject (string) optional, describes the subject of the event in the context of the event producer (identified by source), - strict (boolean, default false) tell if object instance will be validated in a more strict way |
extensions |
object |
<nullable> |
optional, contains extension properties (each extension as a key/value property, and no nested objects) but if given any object must contain at least 1 property |
Throws:
-
-
if strict is true and id or type is undefined or null
- Type
- Error
-
-
-
if data and data_base64 are defined
- Type
- Error
-
Members
(static) standardProps :Array
Getter method to return the list of standard property names, as an array of strings.
Type:
- Array
- Source:
dataType :string
Getter method to tell if CloudEvent data is text or binary, or unknown if not clear.
Type:
- string
- Source:
extensions :object
Getter method to return a copy of CloudEvent extensions.
Type:
- object
- Source:
isDatacontenttypeJSON :boolean
Getter method to tell if data content type is a JSON-derived format, so data must be encoded/decoded accordingly.
Type:
- boolean
- Source:
isStrict :boolean
Getter method to tell if the object has the strict flag enabled.
Type:
- boolean
- Source:
payload :object|Map|Set|Array|string|boolean|number
Getter method to return a copy of CloudEvent data attribute (or data_base64 if defined), but transformed/decoded if possible.
Type:
- object | Map | Set | Array | string | boolean | number
- Source:
schema :object
Getter method to return JSON Schema for a CloudEvent.
Type:
- object
- Source:
timeAsDate :Date
Getter method to return the CloudEvent time but as a Date object.
Type:
- Date
- Source:
Methods
(static) datacontenttypeDefault() → {string}
Return the default data content Type for a CloudEvent.
- Source:
Returns:
- Type
- string
(static) deserializeEvent(sernon-null, optionsopt) → {object}
Deserialize/parse the given CloudEvent from JSON format.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ser |
string | the serialized CloudEvent to parse/deserialize | ||
options |
object |
<optional> |
{} | optional deserialization attributes: - decoder (function, no default) a function that takes data and returns decoder data as a string, - decodedData (string, no default) already decoded data (but consistency with the datacontenttype is not checked), - onlyValid (boolean, default false) to deserialize only if it's a valid instance, - onlyIfLessThan64KB (boolean, default false) to return the deserialized string only if it's less than 64 KB, - printDebugInfo (boolean, default false) to print some debug info to the console, - timezoneOffset (number, default 0) to apply a different timezone offset |
- Source:
Throws:
-
-
if ser is undefined or null, or an option is undefined/null/wrong
- Type
- Error
-
-
-
in case of JSON parsing error
- Type
- Error
-
Returns:
- Type
- object
(static) dumpValidationResults(ce, optionsopt, nameopt) → {string}
Utility function that return a dump of validation results on the given CloudEvent.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ce |
object | the CloudEvent object to dump | ||
options |
object |
<optional> |
{} | optional validation options |
name |
string |
<optional> |
'noname' | the name to assign in the returned string, or 'noname' as default value |
- Source:
Returns:
- Type
- string
(static) ensureTypeOfDataIsRight(cenon-null, optionsopt, nameopt) → {string|null}
Tell the type of data of the CloudEvent, if it's right (depending even on related datacontenttype), from the validator point of view.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ce |
object | the CloudEvent to validate | ||
options |
object |
<optional> |
{} | optional validation options |
name |
string |
<optional> |
'data' | the name to assign in the returned error string (if any), or 'data' as default value |
- Source:
Throws:
-
-
if event is not a CloudEvent instance or subclass
- Type
- TypeError
-
-
-
if event is undefined or null
- Type
- Error
-
Returns:
- Type
- string | null
(static) getJSONSchema() → {object}
Get the JSON Schema for a CloudEvent.
- Source:
Returns:
- Type
- object
(static) isCloudEvent(eventnon-null) → {boolean}
Tell the given CloudEvent, if it's instance of the CloudEvent class or a subclass of it.
Parameters:
Name | Type | Description |
---|---|---|
event |
object | the CloudEvent to check |
- Source:
Throws:
-
if event is undefined or null
- Type
- Error
Returns:
- Type
- boolean
(static) isDatacontenttypeJSONEvent(eventnon-null) → {boolean}
Tell the data content Type for a CloudEvent, if is a JSON-derived format, so data must be encoded/decoded accordingly.
Parameters:
Name | Type | Description |
---|---|---|
event |
object | the CloudEvent to validate |
- Source:
Throws:
-
-
if event is not a CloudEvent instance or subclass
- Type
- TypeError
-
-
-
if event is undefined or null
- Type
- Error
-
Returns:
- Type
- boolean
(static) isExtensionProperty(propertynon-null) → {boolean}
Tell the given property, if it's an extension CloudEvent property/attribute.
Parameters:
Name | Type | Description |
---|---|---|
property |
string | the property/attribute to check |
- Source:
Returns:
- Type
- boolean
(static) isStandardProperty(propertynon-null) → {boolean}
Tell the given property, if it's a standard CloudEvent property/attribute.
Parameters:
Name | Type | Description |
---|---|---|
property |
string | the property/attribute to check |
- Source:
Returns:
- Type
- boolean
(static) isStrictEvent(eventnon-null) → {boolean}
Tell if the object has the strict flag enabled.
Parameters:
Name | Type | Description |
---|---|---|
event |
object | the CloudEvent to validate |
- Source:
Throws:
-
-
if event is not a CloudEvent instance or subclass
- Type
- TypeError
-
-
-
if event is undefined or null
- Type
- Error
-
Returns:
- Type
- boolean
(static) isValidEvent(eventnon-null, optionsopt) → {boolean}
Tell the given CloudEvent, if it's valid.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
object | the CloudEvent to validate | ||
options |
object |
<optional> |
{} | containing: - strict (boolean, default null so no override) to validate it in a more strict way (if null it will be used strict mode in the given event), - dataschemavalidator (function(data, dataschema) boolean, optional) a function to validate data of current CloudEvent instance with its dataschema - printDebugInfo (boolean, default false) to print some debug info to the console, - timezoneOffset (number, default 0) to apply a different timezone offset |
- Source:
Returns:
- Type
- boolean
(static) mediaType() → {string}
Return the MIME Type for a CloudEvent.
- Source:
Returns:
- Type
- string
(static) serializeEvent(eventnon-null, optionsopt) → {string}
Serialize the given CloudEvent in JSON format.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
object | the CloudEvent to serialize | ||
options |
object |
<optional> |
{} | optional serialization attributes: - encoder (function, no default) a function that takes data and returns encoded data as a string, - encodedData (string, no default) already encoded data (but consistency with the datacontenttype is not checked), - onlyValid (boolean, default false) to serialize only if it's a valid instance, - onlyIfLessThan64KB (boolean, default false) to return the serialized string only if it's less than 64 KB, - printDebugInfo (boolean, default false) to print some debug info to the console, - timezoneOffset (number, default 0) to apply a different timezone offset |
- Source:
Throws:
-
if event is undefined or null, or an option is undefined/null/wrong
- Type
- Error
Returns:
- Type
- string
(static) validateEvent(eventnon-null, optionsopt) → {Array.<object>}
Validate the given CloudEvent.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
object | the CloudEvent to validate | ||
options |
object |
<optional> |
{} | containing: - strict (boolean, default null so no override) to validate it in a more strict way (if null it will be used strict mode in the given event), - dataschemavalidator (function(data, dataschema) boolean, optional) a function to validate data of current CloudEvent instance with its dataschema - timezoneOffset (number, default 0) to apply a different timezone offset |
- Source:
Returns:
- Type
- Array.<object>
(static) version() → {string}
Return the version of the CloudEvent Specification implemented here.
- Source:
Returns:
- Type
- string
isValid(optionsopt) → {boolean}
Tell the current CloudEvent, if it's valid.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
object |
<optional> |
{} | containing: - strict (boolean, default null so no override) to validate it in a more strict way (if null it will be used strict mode in the given event), - dataschemavalidator (function(data, dataschema) boolean, optional) a function to validate data of current CloudEvent instance with its dataschema - printDebugInfo (boolean, default false) to print some debug info to the console, - timezoneOffset (number, default 0) to apply a different timezone offset |
- Source:
Returns:
- Type
- boolean
serialize(optionsopt) → {string}
Serialize the current CloudEvent.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
object |
<optional> |
{} | optional serialization attributes: - encoder (function, default null) a function that takes data and returns encoded data, - encodedData (string, default null) already encoded data (but consistency with the datacontenttype is not checked), |
- Source:
Returns:
- Type
- string
toString() → {string}
Override the usual toString method, to show a summary (only some info) on current instance.
- Source:
Returns:
- Type
- string
validate(optionsopt) → {Array.<object>}
Validate the current CloudEvent.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
object |
<optional> |
{} | containing: - strict (boolean, default null so no override) to validate it in a more strict way (if null it will be used strict mode in the given event), - dataschemavalidator (function(data, dataschema) boolean, optional) a function to validate data of current CloudEvent instance with its dataschema |
- Source:
Returns:
- Type
- Array.<object>