CARVIEW |
- Preparing search index...
- The search index is not available
Class CloudEvent<T>
Type Parameters
T = undefined
Hierarchy
- CloudEvent
Implements
- CloudEventV1<T>
Indexable
Index
Constructors
constructor
- new
Cloud Event<T>(event: Partial<CloudEventV1<T>>, strict?: boolean): CloudEvent<T>
Creates a new CloudEvent object with the provided properties. If there is a chance that the event properties will not conform to the CloudEvent specification, you may pass a boolean
false
as a second parameter to bypass event validation.Type Parameters
T = undefined
Parameters
event: Partial<CloudEventV1<T>>
the event properties
strict: boolean = true
whether to perform event validation when creating the object - default: true
Returns CloudEvent<T>
Properties
Optional data
[OPTIONAL] The event payload. This specification does not place any restriction on the type of this information. It is encoded into a media format which is specified by the datacontenttype attribute (e.g. application/json), and adheres to the dataschema format when those respective attributes are present.
Optional data_ base64
[OPTIONAL] The event payload encoded as base64 data. This is used when the data is in binary form.
Optional datacontenttype
[OPTIONAL] Content type of data
value. This attribute enables data
to
carry any type of content, whereby format and encoding might differ from that
of the chosen event format. For example, an event rendered using the
JSON envelope format might carry an XML payload
in data
, and the consumer is informed by this attribute being set to
"application/xml". The rules for how data
content is rendered for different
datacontenttype
values are defined in the event format specifications; for
example, the JSON event format defines the relationship in
section 3.1.
Optional dataschema
[OPTIONAL] Identifies the schema that data
adheres to. Incompatible
changes to the schema SHOULD be reflected by a different URI. See
Versioning of Attributes in the Primer
for more information.
If present, MUST be a non-empty URI.
id
[REQUIRED] Identifies the event. Producers MUST ensure that source
+ id
is unique for each distinct event. If a duplicate event is re-sent (e.g. due
to a network error) it MAY have the same id
. Consumers MAY assume that
Events with identical source
and id
are duplicates.
source
[REQUIRED] Identifies the context in which an event happened. Often this
will include information such as the type of the event source, the
organization publishing the event or the process that produced the event. The
exact syntax and semantics behind the data encoded in the URI is defined by
the event producer.
Producers MUST ensure that source
+ id
is unique for each distinct event.
An application MAY assign a unique source
to each distinct producer, which
makes it easy to produce unique IDs since no other producer will have the same
source. The application MAY use UUIDs, URNs, DNS authorities or an
application-specific scheme to create unique source
identifiers.
A source MAY include more than one producer. In that case the producers MUST
collaborate to ensure that source
+ id
is unique for each distinct event.
specversion
[REQUIRED] The version of the CloudEvents specification which the event
uses. This enables the interpretation of the context. Compliant event
producers MUST use a value of 1.0
when referring to this version of the
specification.
Optional subject
[OPTIONAL] This describes the subject of the event in the context of the
event producer (identified by source
). In publish-subscribe scenarios, a
subscriber will typically subscribe to events emitted by a source
, but the
source
identifier alone might not be sufficient as a qualifier for any
specific event if the source
context has internal sub-structure.
Identifying the subject of the event in context metadata (opposed to only in
the data
payload) is particularly helpful in generic subscription filtering
scenarios where middleware is unable to interpret the data
content. In the
above example, the subscriber might only be interested in blobs with names
ending with '.jpg' or '.jpeg' and the subject
attribute allows for
constructing a simple and efficient string-suffix filter for that subset of
events.
If present, MUST be a non-empty string.
Optional time
[OPTIONAL] Timestamp of when the occurrence happened. If the time of the
occurrence cannot be determined then this attribute MAY be set to some other
time (such as the current time) by the CloudEvents producer, however all
producers for the same source
MUST be consistent in this respect. In other
words, either they all use the actual time of the occurrence or they all use
the same algorithm to determine the value used.
type
[REQUIRED] This attribute contains a value describing the type of event
related to the originating occurrence. Often this attribute is used for
routing, observability, policy enforcement, etc. The format of this is
producer defined and might include information such as the version of the
type
- see
Versioning of Attributes in the Primer
for more information.
Methods
clone With
- clone
With(options: Partial<CloudEventV1<never>>, strict?: boolean): CloudEvent<T> - clone
With<D>(options: Partial<CloudEventV1<D>>, strict?: boolean): CloudEvent<D>
Clone a CloudEvent with new/updated attributes
- throws
if the CloudEvent does not conform to the schema
Parameters
options: Partial<CloudEventV1<never>>
attributes to augment the CloudEvent without a
data
propertyOptional strict: boolean
whether or not to use strict validation when cloning (default: true)
Returns CloudEvent<T>
returns a new CloudEvent
Clone a CloudEvent with new/updated attributes and new data
- throws
if the CloudEvent does not conform to the schema
Type Parameters
D
Parameters
options: Partial<CloudEventV1<D>>
attributes to augment the CloudEvent with a
data
property and typeOptional strict: boolean
whether or not to use strict validation when cloning (default: true)
Returns CloudEvent<D>
returns a new CloudEvent
emit
- emit(ensureDelivery?: boolean): Promise<CloudEvent<T>>
Emit this CloudEvent through the application
Parameters
ensureDelivery: boolean = true
fail the promise if one listener fail
Returns Promise<CloudEvent<T>>
this
toJSON
- toJSON(): Record<string, unknown>
Used by JSON.stringify(). The name is confusing, but this method is called by JSON.stringify() when converting this object to JSON.
Returns Record<string, unknown>
this event as a plain object
to String
- to
String(): string
Returns string
validate
- validate(): boolean
Validates this CloudEvent against the schema
- throws
if the CloudEvent does not conform to the schema
Returns boolean
true if this event is valid
Static clone With
- clone
With(event: CloudEventV1<any>, options: Partial<CloudEventV1<any>>, strict?: boolean): CloudEvent<any>
Clone a CloudEvent with new or updated attributes.
- throws
{ValidationError} if
strict
istrue
and the resulting event is invalid
Parameters
event: CloudEventV1<any>
an object that implements the
CloudEventV1
interfaceoptions: Partial<CloudEventV1<any>>
an object with new or updated attributes
strict: boolean = true
true
if the resulting event should be valid per the CloudEvent specification
Returns CloudEvent<any>
a CloudEvent cloned from
event
withoptions
applied.
Generated using TypeDoc
A CloudEvent describes event data in common formats to provide interoperability across services, platforms and systems.
https://github.com/cloudevents/spec/blob/v1.0/spec.md