|
| 1 | +/*! |
| 2 | + * cloudevents.io |
| 3 | + * Apache-2.0 Licensed |
| 4 | + */ |
| 5 | + |
| 6 | +"use strict"; |
| 7 | + |
| 8 | +/** |
| 9 | + * CloudEvent prototype |
| 10 | + * |
| 11 | + * @example |
| 12 | + * let event = new CloudEvent("A234-1234-1234", "https://github.com/cloudevents/spec/pull", "com.github.pull.create", { |
| 13 | + * "comexampleextension1" : "value", |
| 14 | + * "comexampleextension2" : { |
| 15 | + * "othervalue" : 5 |
| 16 | + * } |
| 17 | + * }); |
| 18 | + * |
| 19 | + * @constructor |
| 20 | + * @class |
| 21 | + * @param {String} id - Identifies the event |
| 22 | + * @param {String} source - Identifies the context in which an event happened |
| 23 | + * @param {String} type - The originating occurrence |
| 24 | + * @param {Object} extensions - Custom additional context attributes |
| 25 | +
|
| 26 | + * @param {Object} data - Data attribute |
| 27 | + * @public |
| 28 | + */ |
| 29 | +function CloudEvent(id, source, type, extensions, data) { |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | +CloudEvent.prototype.id = () => { |
| 34 | + |
| 35 | +}; |
| 36 | + |
| 37 | +CloudEvent.prototype.source = () => { |
| 38 | + |
| 39 | +}; |
| 40 | + |
| 41 | +/** |
| 42 | + * The CloudEvents Spec version |
| 43 | + * @public |
| 44 | + * @return {String} Always set to '0.2' |
| 45 | + */ |
| 46 | +CloudEvent.prototype.specversion = () => { |
| 47 | + return "0.2"; |
| 48 | +}; |
| 49 | + |
| 50 | +CloudEvent.prototype.type = () => { |
| 51 | + |
| 52 | +}; |
| 53 | + |
| 54 | +CloudEvent.prototype.get = (extension) => { |
| 55 | + |
| 56 | +}; |
| 57 | + |
| 58 | +CloudEvent.prototype.data = (data) => { |
| 59 | + |
| 60 | +}; |
| 61 | + |
| 62 | +/** |
| 63 | + * Returns the internal representation of context attributes, extension |
| 64 | + * attribute and data attribute. |
| 65 | + * |
| 66 | + * @example |
| 67 | + * let event = new CloudEvent("A234-1234-1234", "https://github.com/cloudevents/spec/pull", "com.github.pull.create"); |
| 68 | + * event |
| 69 | + * .then((payload) => { |
| 70 | + * // use the event payload, which is valid |
| 71 | + * payload.id; |
| 72 | + * payload.source; |
| 73 | + * payload.specversion; |
| 74 | + * }) |
| 75 | + * .catch((err) => { |
| 76 | + * // threat the err reporting an invalid payload |
| 77 | + * }); |
| 78 | + * |
| 79 | + * @return {Promise} To resolve the event as object notation |
| 80 | + * @public |
| 81 | + */ |
| 82 | +CloudEvent.prototype.asObject = () => { |
| 83 | + |
| 84 | +}; |
| 85 | + |
| 86 | +/** |
| 87 | + * Validates the payload against the definitions, but if something |
| 88 | + * is wrong throws and exception. |
| 89 | + * |
| 90 | + */ |
| 91 | +CloudEvent.prototype.validate = () => { |
| 92 | + |
| 93 | +}; |
| 94 | + |
| 95 | +module.exports = CloudEvent; |
0 commit comments