2016-03-09 23:37:54 +00:00
|
|
|
var EventData = require('./eventData');
|
|
|
|
var results = require('./results');
|
|
|
|
|
|
|
|
const expectedVersion = {
|
|
|
|
any: -2,
|
|
|
|
noStream: -1,
|
2018-02-19 18:06:33 +00:00
|
|
|
emptyStream: -1,
|
|
|
|
streamExists: -4
|
2016-03-09 23:37:54 +00:00
|
|
|
};
|
2017-04-16 19:51:17 +00:00
|
|
|
Object.freeze(expectedVersion);
|
2018-02-19 18:06:33 +00:00
|
|
|
|
2016-03-09 23:37:54 +00:00
|
|
|
const positions = {
|
|
|
|
start: new results.Position(0, 0),
|
|
|
|
end: new results.Position(-1, -1)
|
|
|
|
};
|
2017-04-16 19:51:17 +00:00
|
|
|
Object.freeze(positions);
|
2016-03-09 23:37:54 +00:00
|
|
|
|
2018-02-19 18:06:33 +00:00
|
|
|
const streamPosition = {
|
|
|
|
start: 0,
|
|
|
|
end: -1
|
|
|
|
};
|
|
|
|
Object.freeze(streamPosition);
|
|
|
|
|
2016-03-09 23:37:54 +00:00
|
|
|
/**
|
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}
|
|
|
|
*/
|
2017-02-19 07:10:15 +00:00
|
|
|
function createJsonEventData(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);
|
2017-02-19 07:10:15 +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}
|
|
|
|
*/
|
2017-02-19 07:10:15 +00:00
|
|
|
function createEventData(eventId, type, isJson, data, metadata) {
|
2016-03-09 23:37:54 +00:00
|
|
|
return new EventData(eventId, type, isJson, data, metadata);
|
2017-02-19 07:10:15 +00:00
|
|
|
}
|
2016-03-09 23:37:54 +00:00
|
|
|
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose classes
|
2018-07-09 17:27:12 +00:00
|
|
|
exports.Position = results.Position;
|
|
|
|
exports.UserCredentials = require('./systemData/userCredentials');
|
|
|
|
exports.PersistentSubscriptionSettings = require('./persistentSubscriptionSettings');
|
|
|
|
exports.SystemConsumerStrategies = require('./systemConsumerStrategies');
|
|
|
|
exports.GossipSeed = require('./gossipSeed');
|
|
|
|
exports.EventStoreConnection = require('./eventStoreConnection');
|
|
|
|
exports.ProjectionsManager = require('./projections/projectionsManager');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose errors
|
2018-07-09 17:27:12 +00:00
|
|
|
exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError');
|
|
|
|
exports.StreamDeletedError = require('./errors/streamDeletedError');
|
|
|
|
exports.AccessDeniedError = require('./errors/accessDeniedError');
|
|
|
|
exports.ProjectionCommandFailedError = require('./errors/projectionCommandFailedError');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose enums/constants
|
2018-07-09 17:27:12 +00:00
|
|
|
exports.expectedVersion = expectedVersion;
|
|
|
|
exports.positions = positions;
|
|
|
|
exports.streamPosition = streamPosition;
|
|
|
|
exports.systemMetadata = require('./common/systemMetadata');
|
|
|
|
exports.eventReadStatus = results.EventReadStatus;
|
|
|
|
exports.sliceReadStatus = require('./sliceReadStatus');
|
2019-01-17 18:00:49 +00:00
|
|
|
exports.persistentSubscriptionNakEventAction =
|
|
|
|
exports.PersistentSubscriptionNakEventAction = require('./persistentSubscriptionNakEventAction');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose loggers
|
2018-07-09 17:27:12 +00:00
|
|
|
exports.NoopLogger = require('./common/log/noopLogger');
|
|
|
|
exports.FileLogger = require('./common/log/fileLogger');
|
2016-10-20 11:40:46 +00:00
|
|
|
// Expose Helper functions
|
2018-07-09 17:27:12 +00:00
|
|
|
exports.createConnection = require('./eventStoreConnection').create;
|
|
|
|
exports.createJsonEventData = createJsonEventData;
|
|
|
|
exports.createEventData = createEventData;
|