Working on documentation (wip)
This commit is contained in:
@ -12,31 +12,35 @@ const positions = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} eventId
|
||||
* @param {object} event
|
||||
* @param {object} [metadata]
|
||||
* @param {string} [type]
|
||||
* Create an EventData object from JavaScript event/metadata that will be serialized as json
|
||||
* @public
|
||||
* @param {string} eventId Event UUID
|
||||
* @param {object} event Event object
|
||||
* @param {object} [metadata] Event metadata
|
||||
* @param {string} [type] Event type
|
||||
* @returns {EventData}
|
||||
*/
|
||||
function jsonEventDataFactory(eventId, event, metadata, type) {
|
||||
module.exports.createJsonEventData = function (eventId, event, metadata, type) {
|
||||
if (!event || typeof event !== 'object') throw new TypeError("data must be an object.");
|
||||
|
||||
var eventBuf = new Buffer(JSON.stringify(event));
|
||||
var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null;
|
||||
return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} eventId
|
||||
* @param {string} type
|
||||
* @param {boolean} isJson
|
||||
* @param {Buffer} data
|
||||
* @param {Buffer} [metadata]
|
||||
* Create an EventData object from event/metadata buffer(s)
|
||||
* @public
|
||||
* @param {string} eventId Event UUID
|
||||
* @param {string} type Event type
|
||||
* @param {boolean} isJson is buffer(s) content json
|
||||
* @param {Buffer} data Data buffer
|
||||
* @param {Buffer} [metadata] Metadata buffer
|
||||
* @returns {EventData}
|
||||
*/
|
||||
function eventDataFactory(eventId, type, isJson, data, metadata) {
|
||||
module.exports.createEventData = function (eventId, type, isJson, data, metadata) {
|
||||
return new EventData(eventId, type, isJson, data, metadata);
|
||||
}
|
||||
};
|
||||
|
||||
// Expose classes
|
||||
module.exports.EventStoreConnection = require('./eventStoreConnection');
|
||||
@ -59,6 +63,4 @@ module.exports.sliceReadStatus = require('./sliceReadStatus');
|
||||
module.exports.NoopLogger = require('./common/log/noopLogger');
|
||||
module.exports.FileLogger = require('./common/log/fileLogger');
|
||||
// Expose Helper functions
|
||||
module.exports.createConnection = module.exports.EventStoreConnection.create;
|
||||
module.exports.createEventData = eventDataFactory;
|
||||
module.exports.createJsonEventData = jsonEventDataFactory;
|
||||
module.exports.createConnection = module.exports.EventStoreConnection.create;
|
Reference in New Issue
Block a user