2016-03-09 23:37:54 +00:00
|
|
|
var EventData = require('./eventData');
|
|
|
|
var results = require('./results');
|
|
|
|
|
|
|
|
const expectedVersion = {
|
|
|
|
any: -2,
|
|
|
|
noStream: -1,
|
|
|
|
emptyStream: -1
|
|
|
|
};
|
|
|
|
const positions = {
|
|
|
|
start: new results.Position(0, 0),
|
|
|
|
end: new results.Position(-1, -1)
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-11-07 06:58:11 +00:00
|
|
|
* 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
|
2016-03-09 23:37:54 +00:00
|
|
|
* @returns {EventData}
|
|
|
|
*/
|
2016-11-07 06:58:11 +00:00
|
|
|
module.exports.createJsonEventData = function (eventId, event, metadata, type) {
|
2016-03-15 00:55:35 +00:00
|
|
|
if (!event || typeof event !== 'object') throw new TypeError("data must be an object.");
|
2016-03-09 23:37:54 +00:00
|
|
|
|
2016-03-15 00:55:35 +00:00
|
|
|
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);
|
2016-11-07 06:58:11 +00:00
|
|
|
};
|
2016-03-09 23:37:54 +00:00
|
|
|
|
|
|
|
/**
|
2016-11-07 06:58:11 +00:00
|
|
|
* 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
|
2016-03-09 23:37:54 +00:00
|
|
|
* @returns {EventData}
|
|
|
|
*/
|
2016-11-07 06:58:11 +00:00
|
|
|
module.exports.createEventData = function (eventId, type, isJson, data, metadata) {
|
2016-03-09 23:37:54 +00:00
|
|
|
return new EventData(eventId, type, isJson, data, metadata);
|
2016-11-07 06:58:11 +00:00
|
|
|
};
|
2016-03-09 23:37:54 +00:00
|
|
|
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose classes
|
2016-03-09 23:37:54 +00:00
|
|
|
module.exports.EventStoreConnection = require('./eventStoreConnection');
|
|
|
|
module.exports.UserCredentials = require('./systemData/userCredentials');
|
|
|
|
module.exports.EventData = EventData;
|
2016-03-11 06:57:39 +00:00
|
|
|
module.exports.PersistentSubscriptionSettings = require('./persistentSubscriptionSettings');
|
|
|
|
module.exports.SystemConsumerStrategies = require('./systemConsumerStrategies');
|
2016-10-15 22:41:25 +00:00
|
|
|
module.exports.GossipSeed = require('./gossipSeed');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose errors
|
2016-03-11 23:55:27 +00:00
|
|
|
module.exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError');
|
|
|
|
module.exports.StreamDeletedError = require('./errors/streamDeletedError');
|
|
|
|
module.exports.AccessDeniedError = require('./errors/accessDeniedError');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose enums/constants
|
2016-03-09 23:37:54 +00:00
|
|
|
module.exports.expectedVersion = expectedVersion;
|
|
|
|
module.exports.positions = positions;
|
2016-03-11 23:55:27 +00:00
|
|
|
module.exports.systemMetadata = require('./common/systemMetadata');
|
2016-03-14 01:38:42 +00:00
|
|
|
module.exports.eventReadStatus = results.EventReadStatus;
|
2016-03-15 00:55:35 +00:00
|
|
|
module.exports.sliceReadStatus = require('./sliceReadStatus');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose loggers
|
|
|
|
module.exports.NoopLogger = require('./common/log/noopLogger');
|
|
|
|
module.exports.FileLogger = require('./common/log/fileLogger');
|
|
|
|
// Expose Helper functions
|
2016-11-07 06:58:11 +00:00
|
|
|
module.exports.createConnection = module.exports.EventStoreConnection.create;
|