Bumping version to 0.0.7, exposing loggers, minor bug fixes, cluster connection (wip)

This commit is contained in:
Nicolas Dextraze 2016-10-20 04:40:46 -07:00
parent f951a625f4
commit 830a317f0d
6 changed files with 51 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "eventstore-node",
"version": "0.0.6",
"version": "0.0.7",
"description": "A port of the EventStore .Net ClientAPI to Node.js",
"main": "index.js",
"scripts": {

39
samples/simple.js Normal file
View File

@ -0,0 +1,39 @@
var client = require('../src/client');
var uuid = require('uuid');
var settings = {
verboseLogging: true,
log: new client.FileLogger('./simple-verbose.log')
};
var gossipSeeds = [
new client.GossipSeed({hostname: 'localhost', port: 1113}),
new client.GossipSeed({hostname: 'localhost', port: 2113}),
new client.GossipSeed({hostname: 'localhost', port: 3113})
];
var conn = client.createConnection(settings, gossipSeeds);
conn.connect()
.catch(function (err) {
console.log(err);
//process.exit(-1);
});
conn.on('connected', function (endPoint) {
console.log('connected to endPoint', endPoint);
//Start some work
setInterval(function () {
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
client.createJsonEventData(uuid.v4(), {abc: 123}, null, 'MyEvent')
]).then(function (writeResult) {
console.log(writeResult);
});
}, 1000);
});
conn.on('error', function (err) {
console.log('Error occurred on connection:', err);
});
conn.on('closed', function (reason) {
console.log('Connection closed, reason:', reason);
//process.exit(-1);
});
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));

View File

@ -38,24 +38,27 @@ function eventDataFactory(eventId, type, isJson, data, metadata) {
return new EventData(eventId, type, isJson, data, metadata);
}
// Exporting classes
// Expose classes
module.exports.EventStoreConnection = require('./eventStoreConnection');
module.exports.UserCredentials = require('./systemData/userCredentials');
module.exports.EventData = EventData;
module.exports.PersistentSubscriptionSettings = require('./persistentSubscriptionSettings');
module.exports.SystemConsumerStrategies = require('./systemConsumerStrategies');
module.exports.GossipSeed = require('./gossipSeed');
// Exporting errors
// Expose errors
module.exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError');
module.exports.StreamDeletedError = require('./errors/streamDeletedError');
module.exports.AccessDeniedError = require('./errors/accessDeniedError');
// Exporting enums/constants
// Expose enums/constants
module.exports.expectedVersion = expectedVersion;
module.exports.positions = positions;
module.exports.systemMetadata = require('./common/systemMetadata');
module.exports.eventReadStatus = results.EventReadStatus;
module.exports.sliceReadStatus = require('./sliceReadStatus');
// Helper functions
// Expose loggers
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;

View File

@ -6,7 +6,7 @@ function FileLogger(filePath, append) {
this._filePath = filePath;
if (!append) {
try {
fs.unlink(filePath);
fs.unlinkSync(filePath);
} catch(e) {}
}
}

View File

@ -18,7 +18,7 @@ SimpleQueuedHandler.prototype.registerHandler = function(type, handler) {
try {
handler(msg);
} catch(e) {
console.log('ERROR: ', e);
console.log('ERROR: ', e.stack);
}
};
};

View File

@ -34,7 +34,8 @@ function setUp(cb) {
settings.log.error(error, "Connection to %j failed.", tcpEndPoint);
cb(error);
});
this.conn.on('connected', function () {
this.conn.on('connected', function (tcpEndPoint) {
if (connected) return;
settings.log.debug("Connected to %j.", tcpEndPoint);
connected = true;
cb();