Initial commit

This commit is contained in:
Nicolas Dextraze
2016-03-09 12:46:15 -08:00
parent 3a5a4111c1
commit 9be67bf7c7
54 changed files with 5172 additions and 1 deletions

36
src/eventData.js Normal file
View File

@@ -0,0 +1,36 @@
var uuid = require('uuid');
function isValidId(id) {
if (typeof id !== 'string') return false;
var buf = uuid.parse(id);
var valid = false;
for(var i=0;i<buf.length;i++)
if (buf[i] !== 0)
valid = true;
return valid;
}
/**
* Create an EventData
* @param {string} eventId
* @param {string} type
* @param {boolean} [isJson]
* @param {Buffer} [data]
* @param {Buffer} [metadata]
* @constructor
*/
function EventData(eventId, type, isJson, data, metadata) {
if (!isValidId(eventId)) throw new TypeError("eventId must be a string containing a UUID.");
if (typeof type !== 'string' || type === '') throw new TypeError("type must be a non-empty string.");
if (isJson && typeof isJson !== 'boolean') throw new TypeError("isJson must be a boolean.");
if (data && !Buffer.isBuffer(data)) throw new TypeError("data must be a Buffer.");
if (metadata && !Buffer.isBuffer(metadata)) throw new TypeError("metadata must be a Buffer.");
this.eventId = eventId;
this.type = type;
this.isJson = isJson || false;
this.data = data || new Buffer(0);
this.metadata = metadata || new Buffer(0);
}
module.exports = EventData;