chore: use es6 for cloudevents.js (#73)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
This commit is contained in:
		
							parent
							
								
									d042ef1dbb
								
							
						
					
					
						commit
						12ac181300
					
				|  | @ -6,18 +6,20 @@ const Formatter = require("./formats/json/formatter.js"); | |||
|  * | ||||
|  * https://en.wikipedia.org/wiki/Builder_pattern
 | ||||
|  */ | ||||
| function Cloudevent(_spec, _formatter) { | ||||
|   this.spec = (_spec) ? new _spec(Cloudevent) : new Spec(Cloudevent); | ||||
| class CloudEvent { | ||||
|   constructor(_spec, _formatter) { | ||||
|     this.spec = (_spec) ? new _spec(CloudEvent) : new Spec(CloudEvent); | ||||
|     this.formatter = (_formatter) ? new _formatter() : new Formatter(); | ||||
| 
 | ||||
|     // The map of extensions
 | ||||
|     this.extensions = {}; | ||||
|   } | ||||
| 
 | ||||
| /* | ||||
|  * To format the payload using the formatter | ||||
|  */ | ||||
| Cloudevent.prototype.format = function() { | ||||
|   getFormats() { | ||||
|     return { json: Formatter }; | ||||
|   } | ||||
| 
 | ||||
|   format() { | ||||
|     // Check the constraints
 | ||||
|     this.spec.check(); | ||||
| 
 | ||||
|  | @ -26,102 +28,95 @@ Cloudevent.prototype.format = function() { | |||
| 
 | ||||
|     // Then, format
 | ||||
|     return this.formatter.format(this.spec.payload); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.toString = function() { | ||||
|   toString() { | ||||
|     return this.formatter.toString(this.spec.payload); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.type = function(type) { | ||||
|   type(type) { | ||||
|     this.spec.type(type); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getType = function() { | ||||
|   getType() { | ||||
|     return this.spec.getType(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.specversion = function(version) { | ||||
|   specversion(version) { | ||||
|     return this.spec.specversion(version); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getSpecversion = function() { | ||||
|   getSpecversion() { | ||||
|     return this.spec.getSpecversion(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.source = function(_source) { | ||||
|   source(_source) { | ||||
|     this.spec.source(_source); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getSource = function() { | ||||
|   getSource() { | ||||
|     return this.spec.getSource(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.id = function(_id) { | ||||
|   id(_id) { | ||||
|     this.spec.id(_id); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getId = function() { | ||||
|   getId() { | ||||
|     return this.spec.getId(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.time = function(_time) { | ||||
|   time(_time) { | ||||
|     this.spec.time(_time); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getTime = function() { | ||||
|   getTime() { | ||||
|     return this.spec.getTime(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.schemaurl = function(_schemaurl) { | ||||
|   schemaurl(_schemaurl) { | ||||
|     this.spec.schemaurl(_schemaurl); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getSchemaurl = function() { | ||||
|   getSchemaurl() { | ||||
|     return this.spec.getSchemaurl(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.dataContenttype = function(_contenttype) { | ||||
|   dataContenttype(_contenttype) { | ||||
|     this.spec.dataContenttype(_contenttype); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getDataContenttype = function() { | ||||
|   getDataContenttype() { | ||||
|     return this.spec.getDataContenttype(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.data = function(_data) { | ||||
|   data(_data) { | ||||
|     this.spec.data(_data); | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getData = function() { | ||||
|   getData() { | ||||
|     return this.spec.getData(); | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.addExtension = function(key, value) { | ||||
|   addExtension(key, value) { | ||||
|     this.spec.addExtension(key, value); | ||||
| 
 | ||||
|   // Stores localy
 | ||||
|     // Stores locally
 | ||||
|     this.extensions[key] = value; | ||||
| 
 | ||||
|     return this; | ||||
| }; | ||||
|   } | ||||
| 
 | ||||
| Cloudevent.prototype.getExtensions = function() { | ||||
|   getExtensions() { | ||||
|     return this.extensions; | ||||
| }; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* | ||||
|  * Export the formats | ||||
|  */ | ||||
| Cloudevent.formats = { | ||||
|   json: Formatter, | ||||
|   "json0.1": Formatter | ||||
| }; | ||||
| 
 | ||||
| module.exports = Cloudevent; | ||||
| module.exports = CloudEvent; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue