|
| 1 | +/** |
| 2 | + * The object interface for CloudEvents 1.0. |
| 3 | + * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md |
| 4 | + */ |
| 5 | +export interface CloudEventV1 extends CloudEventV1Attributes { |
| 6 | + // REQUIRED Attributes |
| 7 | + /** |
| 8 | + * [REQUIRED] Identifies the event. Producers MUST ensure that `source` + `id` |
| 9 | + * is unique for each distinct event. If a duplicate event is re-sent (e.g. due |
| 10 | + * to a network error) it MAY have the same `id`. Consumers MAY assume that |
| 11 | + * Events with identical `source` and `id` are duplicates. |
| 12 | + * @required Non-empty string. Unique within producer. |
| 13 | + * @example An event counter maintained by the producer |
| 14 | + * @example A UUID |
| 15 | + */ |
| 16 | + id: string; |
| 17 | + |
| 18 | + /** |
| 19 | + * [REQUIRED] The version of the CloudEvents specification which the event |
| 20 | + * uses. This enables the interpretation of the context. Compliant event |
| 21 | + * producers MUST use a value of `1.0` when referring to this version of the |
| 22 | + * specification. |
| 23 | + * @required MUST be a non-empty string. |
| 24 | + */ |
| 25 | + specversion: string; |
| 26 | +} |
| 27 | + |
| 28 | +export interface CloudEventV1Attributes extends CloudEventV1OptionalAttributes { |
| 29 | + /** |
| 30 | + * [REQUIRED] Identifies the context in which an event happened. Often this |
| 31 | + * will include information such as the type of the event source, the |
| 32 | + * organization publishing the event or the process that produced the event. The |
| 33 | + * exact syntax and semantics behind the data encoded in the URI is defined by |
| 34 | + * the event producer. |
| 35 | + * Producers MUST ensure that `source` + `id` is unique for each distinct event. |
| 36 | + * An application MAY assign a unique `source` to each distinct producer, which |
| 37 | + * makes it easy to produce unique IDs since no other producer will have the same |
| 38 | + * source. The application MAY use UUIDs, URNs, DNS authorities or an |
| 39 | + * application-specific scheme to create unique `source` identifiers. |
| 40 | + * A source MAY include more than one producer. In that case the producers MUST |
| 41 | + * collaborate to ensure that `source` + `id` is unique for each distinct event. |
| 42 | + * @required Non-empty URI-reference |
| 43 | + */ |
| 44 | + source: string; |
| 45 | + |
| 46 | + /** |
| 47 | + * [REQUIRED] This attribute contains a value describing the type of event |
| 48 | + * related to the originating occurrence. Often this attribute is used for |
| 49 | + * routing, observability, policy enforcement, etc. The format of this is |
| 50 | + * producer defined and might include information such as the version of the |
| 51 | + * `type` - see |
| 52 | + * [Versioning of Attributes in the Primer](primer.md#versioning-of-attributes) |
| 53 | + * for more information. |
| 54 | + * @required MUST be a non-empty string |
| 55 | + * @should SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the |
| 56 | + * organization which defines the semantics of this event type. |
| 57 | + * @example com.github.pull.create |
| 58 | + * @example com.example.object.delete.v2 |
| 59 | + */ |
| 60 | + type: string; |
| 61 | +} |
| 62 | + |
| 63 | +export interface CloudEventV1OptionalAttributes { |
| 64 | + /** |
| 65 | + * The following fields are optional. |
| 66 | + */ |
| 67 | + |
| 68 | + /** |
| 69 | + * [OPTIONAL] Content type of `data` value. This attribute enables `data` to |
| 70 | + * carry any type of content, whereby format and encoding might differ from that |
| 71 | + * of the chosen event format. For example, an event rendered using the |
| 72 | + * [JSON envelope](./json-format.md#3-envelope) format might carry an XML payload |
| 73 | + * in `data`, and the consumer is informed by this attribute being set to |
| 74 | + * "application/xml". The rules for how `data` content is rendered for different |
| 75 | + * `datacontenttype` values are defined in the event format specifications; for |
| 76 | + * example, the JSON event format defines the relationship in |
| 77 | + * [section 3.1](./json-format.md#31-handling-of-data). |
| 78 | + */ |
| 79 | + datacontenttype?: string; |
| 80 | + /** |
| 81 | + * [OPTIONAL] Identifies the schema that `data` adheres to. Incompatible |
| 82 | + * changes to the schema SHOULD be reflected by a different URI. See |
| 83 | + * [Versioning of Attributes in the Primer](primer.md#versioning-of-attributes) |
| 84 | + * for more information. |
| 85 | + * If present, MUST be a non-empty URI. |
| 86 | + */ |
| 87 | + dataschema?: string; |
| 88 | + /** |
| 89 | + * [OPTIONAL] This describes the subject of the event in the context of the |
| 90 | + * event producer (identified by `source`). In publish-subscribe scenarios, a |
| 91 | + * subscriber will typically subscribe to events emitted by a `source`, but the |
| 92 | + * `source` identifier alone might not be sufficient as a qualifier for any |
| 93 | + * specific event if the `source` context has internal sub-structure. |
| 94 | + * |
| 95 | + * Identifying the subject of the event in context metadata (opposed to only in |
| 96 | + * the `data` payload) is particularly helpful in generic subscription filtering |
| 97 | + * scenarios where middleware is unable to interpret the `data` content. In the |
| 98 | + * above example, the subscriber might only be interested in blobs with names |
| 99 | + * ending with '.jpg' or '.jpeg' and the `subject` attribute allows for |
| 100 | + * constructing a simple and efficient string-suffix filter for that subset of |
| 101 | + * events. |
| 102 | + * |
| 103 | + * If present, MUST be a non-empty string. |
| 104 | + * @example "https://example.com/storage/tenant/container" |
| 105 | + * @example "mynewfile.jpg" |
| 106 | + */ |
| 107 | + subject?: string; |
| 108 | + /** |
| 109 | + * [OPTIONAL] Timestamp of when the occurrence happened. If the time of the |
| 110 | + * occurrence cannot be determined then this attribute MAY be set to some other |
| 111 | + * time (such as the current time) by the CloudEvents producer, however all |
| 112 | + * producers for the same `source` MUST be consistent in this respect. In other |
| 113 | + * words, either they all use the actual time of the occurrence or they all use |
| 114 | + * the same algorithm to determine the value used. |
| 115 | + * @example "2020-08-08T14:48:09.769Z" |
| 116 | + */ |
| 117 | + time?: Date | string; |
| 118 | + /** |
| 119 | + * [OPTIONAL] The event payload. This specification does not place any restriction |
| 120 | + * on the type of this information. It is encoded into a media format which is |
| 121 | + * specified by the datacontenttype attribute (e.g. application/json), and adheres |
| 122 | + * to the dataschema format when those respective attributes are present. |
| 123 | + */ |
| 124 | + data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown; |
| 125 | + |
| 126 | + /** |
| 127 | + * [OPTIONAL] The event payload encoded as base64 data. This is used when the |
| 128 | + * data is in binary form. |
| 129 | + * @see https://github.com/cloudevents/spec/blob/v1.0/json-format.md#31-handling-of-data |
| 130 | + */ |
| 131 | + data_base64?: string; |
| 132 | + |
| 133 | + /** |
| 134 | + * [OPTIONAL] CloudEvents extension attributes. |
| 135 | + */ |
| 136 | + [key: string]: unknown; |
| 137 | +} |
| 138 | + |
1 | 139 | /**
|
2 | 140 | * The object interface for CloudEvents 0.3.
|
3 | 141 | * @see https://github.com/cloudevents/spec/blob/v0.3/spec.md
|
|
0 commit comments