node-eventstore-client/src/client.js

56 lines
1.9 KiB
JavaScript
Raw Normal View History

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)
};
/**
* @param {string} eventId
* @param {object} data
* @param {object} [metadata]
* @param {string} [type]
* @returns {EventData}
*/
function jsonEventDataFactory(eventId, data, metadata, type) {
if (!data || typeof data !== 'object') throw new TypeError("data must be an object.");
var d = new Buffer(JSON.stringify(data));
var m = metadata ? new Buffer(JSON.stringify(metadata)) : null;
return new EventData(eventId, type || data.constructor.name, true, d, m);
}
/**
* @param {string} eventId
* @param {string} type
* @param {boolean} isJson
* @param {Buffer} data
* @param {Buffer} [metadata]
* @returns {EventData}
*/
function eventDataFactory(eventId, type, isJson, data, metadata) {
return new EventData(eventId, type, isJson, data, metadata);
}
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');
module.exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError');
module.exports.StreamDeletedError = require('./errors/streamDeletedError');
module.exports.AccessDeniedError = require('./errors/accessDeniedError');
module.exports.expectedVersion = expectedVersion;
module.exports.positions = positions;
module.exports.systemMetadata = require('./common/systemMetadata');
// Helper functions
module.exports.createConnection = module.exports.EventStoreConnection.create;
module.exports.createEventData = eventDataFactory;
module.exports.createJsonEventData = jsonEventDataFactory;