|
| 1 | +export = CloudEvent; |
| 2 | +/** |
| 3 | + * An CloudEvent describes event data in common formats to provide |
| 4 | + * interopability across services, platforms and systems. |
| 5 | + * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md |
| 6 | + */ |
| 7 | +declare class CloudEvent { |
| 8 | + /** |
| 9 | + * Creates a new CloudEvent instance |
| 10 | + * @param {object} options CloudEvent properties as a simple object |
| 11 | + * @param {string} options.source Identifies the context in which an event happened as a URI reference |
| 12 | + * @param {string} options.type Describes the type of event related to the originating occurrence |
| 13 | + * @param {string} [options.id] A unique ID for this event - if not supplied, will be autogenerated |
| 14 | + * @param {string} [options.time] A timestamp for this event. May also be provided as a Date |
| 15 | + * @param {string} [options.subject] Describes the subject of the event in the context of the event producer |
| 16 | + * @param {string} [options.dataContentType] The mime content type for the event data |
| 17 | + * @param {string} [options.dataSchema] The URI of the schema that the event data adheres to (v1.0 events) |
| 18 | + * @param {string} [options.schemaURL] The URI of the schema that the event data adheres to (v0.3 events) |
| 19 | + * @param {string} [options.dataContentEncoding] The content encoding for the event data (v0.3 events) |
| 20 | + * @param {string} [options.specversion] The CloudEvent specification version for this event - default: 1.0 |
| 21 | + * @param {*} [options.data] The event payload |
| 22 | + */ |
| 23 | + constructor({ id, source, type, dataContentType, time, subject, dataSchema, schemaURL, dataContentEncoding, data, specversion }: { |
| 24 | + source: string; |
| 25 | + type: string; |
| 26 | + id?: string; |
| 27 | + time?: string; |
| 28 | + subject?: string; |
| 29 | + dataContentType?: string; |
| 30 | + dataSchema?: string; |
| 31 | + schemaURL?: string; |
| 32 | + dataContentEncoding?: string; |
| 33 | + specversion?: string; |
| 34 | + data?: any; |
| 35 | + }); |
| 36 | + spec: import("./bindings/http/v1/spec_1.js") | import("./bindings/http/v03/spec_0_3.js"); |
| 37 | + set source(arg: string); |
| 38 | + /** |
| 39 | + * Gets or sets the origination source of this event as a URI. |
| 40 | + * @type {string} |
| 41 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1 |
| 42 | + */ |
| 43 | + get source(): string; |
| 44 | + set type(arg: string); |
| 45 | + /** |
| 46 | + * Gets or sets the event type |
| 47 | + * @type {string} |
| 48 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#type |
| 49 | + */ |
| 50 | + get type(): string; |
| 51 | + set dataContentType(arg: string); |
| 52 | + /** |
| 53 | + * Gets or sets the content type of the data value for this event |
| 54 | + * @type {string} |
| 55 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype |
| 56 | + */ |
| 57 | + get dataContentType(): string; |
| 58 | + set data(arg: any); |
| 59 | + /** |
| 60 | + * Gets or sets the data for this event |
| 61 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data |
| 62 | + * @type {*} |
| 63 | + */ |
| 64 | + get data(): any; |
| 65 | + set subject(arg: string); |
| 66 | + /** |
| 67 | + * Gets or sets the event subject |
| 68 | + * @type {string} |
| 69 | + * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject |
| 70 | + */ |
| 71 | + get subject(): string; |
| 72 | + set dataSchema(arg: string); |
| 73 | + /** |
| 74 | + * Gets or sets the event's data schema |
| 75 | + * @type {string} |
| 76 | + * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema |
| 77 | + */ |
| 78 | + get dataSchema(): string; |
| 79 | + set dataContentEncoding(arg: string); |
| 80 | + /** |
| 81 | + * Gets or sets the event's data content encoding |
| 82 | + * @type {string} |
| 83 | + * @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding |
| 84 | + */ |
| 85 | + get dataContentEncoding(): string; |
| 86 | + set schemaURL(arg: string); |
| 87 | + /** |
| 88 | + * DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError} |
| 89 | + * if this is a version 1.0 event. |
| 90 | + * @type {string} |
| 91 | + * @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl |
| 92 | + */ |
| 93 | + get schemaURL(): string; |
| 94 | + set id(arg: string); |
| 95 | + /** |
| 96 | + * Gets or sets the event id. Source + id must be unique for each distinct event. |
| 97 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#id |
| 98 | + * @type {string} |
| 99 | + */ |
| 100 | + get id(): string; |
| 101 | + set time(arg: string); |
| 102 | + /** |
| 103 | + * Gets or sets the timestamp for this event as an ISO formatted date string |
| 104 | + * @type {string} |
| 105 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#time |
| 106 | + */ |
| 107 | + get time(): string; |
| 108 | + formatter: import("./formats/json/formatter.js"); |
| 109 | + /** |
| 110 | + * Gets the CloudEvent specification version |
| 111 | + * @type {string} |
| 112 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion |
| 113 | + */ |
| 114 | + get specversion(): string; |
| 115 | + /** |
| 116 | + * Formats the CloudEvent as JSON. Validates the event according |
| 117 | + * to the CloudEvent specification and throws an exception if |
| 118 | + * it's invalid. |
| 119 | + * @returns {JSON} the CloudEvent in JSON form |
| 120 | + * @throws {ValidationError} if this event cannot be validated against the specification |
| 121 | + */ |
| 122 | + format(): JSON; |
| 123 | + /** |
| 124 | + * Formats the CloudEvent as JSON. No specification validation is performed. |
| 125 | + * @returns {string} the CloudEvent as a JSON string |
| 126 | + */ |
| 127 | + toString(): string; |
| 128 | + /** |
| 129 | + * Adds an extension attribute to this CloudEvent |
| 130 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes |
| 131 | + * @param {string} key the name of the extension attribute |
| 132 | + * @param {*} value the value of the extension attribute |
| 133 | + * @returns {void} |
| 134 | + */ |
| 135 | + addExtension(key: string, value: any): void; |
| 136 | + extensions: any; |
| 137 | + /** |
| 138 | + * Gets the extension attributes, if any, associated with this event |
| 139 | + * @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes |
| 140 | + * @returns {Object} the extensions attributes - if none exist will will be {} |
| 141 | + */ |
| 142 | + getExtensions(): any; |
| 143 | +} |
0 commit comments