Working on documentation (wip)

This commit is contained in:
Nicolas Dextraze 2016-11-06 22:58:11 -08:00
parent 90e7ef1a9d
commit 454b150fb6
16 changed files with 87 additions and 25 deletions

2
.gitignore vendored
View File

@ -39,4 +39,4 @@ node_modules
lib/ lib/
.eslintrc.json .eslintrc.json
jsconfig.json jsconfig.json
docs/

View File

@ -3,6 +3,7 @@
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/lib" /> <excludeFolder url="file://$MODULE_DIR$/lib" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

View File

@ -8,7 +8,8 @@
"build": "webpack", "build": "webpack",
"pretest": "npm run build", "pretest": "npm run build",
"test": "nodeunit", "test": "nodeunit",
"prepublish": "npm run build" "prepublish": "npm run build",
"gendocs": "rm -rf docs && jsdoc src -r -R README.md -P package.json -d docs"
}, },
"files": [ "files": [
"lib", "lib",

View File

@ -12,31 +12,35 @@ const positions = {
}; };
/** /**
* @param {string} eventId * Create an EventData object from JavaScript event/metadata that will be serialized as json
* @param {object} event * @public
* @param {object} [metadata] * @param {string} eventId Event UUID
* @param {string} [type] * @param {object} event Event object
* @param {object} [metadata] Event metadata
* @param {string} [type] Event type
* @returns {EventData} * @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."); if (!event || typeof event !== 'object') throw new TypeError("data must be an object.");
var eventBuf = new Buffer(JSON.stringify(event)); var eventBuf = new Buffer(JSON.stringify(event));
var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null; var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null;
return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf); return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf);
} };
/** /**
* @param {string} eventId * Create an EventData object from event/metadata buffer(s)
* @param {string} type * @public
* @param {boolean} isJson * @param {string} eventId Event UUID
* @param {Buffer} data * @param {string} type Event type
* @param {Buffer} [metadata] * @param {boolean} isJson is buffer(s) content json
* @param {Buffer} data Data buffer
* @param {Buffer} [metadata] Metadata buffer
* @returns {EventData} * @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); return new EventData(eventId, type, isJson, data, metadata);
} };
// Expose classes // Expose classes
module.exports.EventStoreConnection = require('./eventStoreConnection'); module.exports.EventStoreConnection = require('./eventStoreConnection');
@ -60,5 +64,3 @@ module.exports.NoopLogger = require('./common/log/noopLogger');
module.exports.FileLogger = require('./common/log/fileLogger'); module.exports.FileLogger = require('./common/log/fileLogger');
// Expose Helper functions // Expose Helper functions
module.exports.createConnection = module.exports.EventStoreConnection.create; module.exports.createConnection = module.exports.EventStoreConnection.create;
module.exports.createEventData = eventDataFactory;
module.exports.createJsonEventData = jsonEventDataFactory;

View File

@ -75,7 +75,7 @@ OperationBase.prototype.inspectPackage = function(pkg) {
case TcpCommand.NotHandled: case TcpCommand.NotHandled:
return this._inspectNotHandled(pkg); return this._inspectNotHandled(pkg);
default: default:
return this._inspectUnexpectedCommand(package, this._responseCommand); return this._inspectUnexpectedCommand(pkg, this._responseCommand);
} }
} catch(e) { } catch(e) {
this.fail(e); this.fail(e);
@ -136,7 +136,7 @@ OperationBase.prototype._inspectUnexpectedCommand = function(pkg, expectedComman
this.log.error("Unexpected TcpCommand received.\n" this.log.error("Unexpected TcpCommand received.\n"
+ "Expected: %s, Actual: %s, Flags: %s, CorrelationId: %s\n" + "Expected: %s, Actual: %s, Flags: %s, CorrelationId: %s\n"
+ "Operation (%s): %s\n" + "Operation (%s): %s\n"
+"TcpPackage Data Dump:\n%j", + "TcpPackage Data Dump:\n%j",
expectedCommand, TcpCommand.getName(pkg.command), pkg.flags, pkg.correlationId, expectedCommand, TcpCommand.getName(pkg.command), pkg.flags, pkg.correlationId,
this.constructor.name, this, pkg.data); this.constructor.name, this, pkg.data);

View File

@ -1,5 +1,6 @@
/** /**
* Create a buffer segment * Create a buffer segment
* @private
* @param {Buffer} buf * @param {Buffer} buf
* @param {number} [offset] * @param {number} [offset]
* @param {number} [count] * @param {number} [count]

View File

@ -1,4 +1,5 @@
/** /**
* @private
* @constructor * @constructor
* @property {number} length * @property {number} length
*/ */

View File

@ -36,6 +36,7 @@ const TimerTickMessage = new messages.TimerTickMessage();
const EmptyGuid = '00000000-0000-0000-0000-000000000000'; const EmptyGuid = '00000000-0000-0000-0000-000000000000';
/** /**
* @private
* @param {EventStoreNodeConnection} esConnection * @param {EventStoreNodeConnection} esConnection
* @param {Object} settings * @param {Object} settings
* @constructor * @constructor

View File

@ -41,6 +41,7 @@ function StartSubscriptionMessage(
util.inherits(StartSubscriptionMessage, Message); util.inherits(StartSubscriptionMessage, Message);
/** /**
* @private
* @constructor * @constructor
* @property {object} endPoints * @property {object} endPoints
* @property {object} endPoints.secureTcpEndPoint * @property {object} endPoints.secureTcpEndPoint

View File

@ -5,6 +5,7 @@ var Hash = require('../common/hash');
var TcpCommand = require('../systemData/tcpCommand'); var TcpCommand = require('../systemData/tcpCommand');
/** /**
* @private
* @param {string} connectionName * @param {string} connectionName
* @param {object} settings * @param {object} settings
* @constructor * @constructor

View File

@ -12,6 +12,7 @@ function isValidId(id) {
/** /**
* Create an EventData * Create an EventData
* @private
* @param {string} eventId * @param {string} eventId
* @param {string} type * @param {string} type
* @param {boolean} [isJson] * @param {boolean} [isJson]

View File

@ -97,6 +97,8 @@ function createFromGossipSeeds(connectionSettings, gossipSeeds, connectionName)
/** /**
* Create an EventStore connection * Create an EventStore connection
* @public
* @alias createConnection
* @param {object} settings * @param {object} settings
* @param {string|object|array} endPointOrGossipSeeds * @param {string|object|array} endPointOrGossipSeeds
* @param {string} [connectionName] * @param {string} [connectionName]

View File

@ -33,12 +33,8 @@ var EventData = require('./eventData');
const MaxReadSize = 4096; const MaxReadSize = 4096;
/** /**
* @param settings * @protected
* @param clusterSettings
* @param endpointDiscoverer
* @param connectionName
* @constructor * @constructor
* @property {string} connectionName
*/ */
function EventStoreNodeConnection(settings, clusterSettings, endpointDiscoverer, connectionName) { function EventStoreNodeConnection(settings, clusterSettings, endpointDiscoverer, connectionName) {
this._connectionName = connectionName || ['ES-', uuid.v4()].join(''); this._connectionName = connectionName || ['ES-', uuid.v4()].join('');
@ -73,6 +69,8 @@ Object.defineProperty(EventStoreNodeConnection.prototype, 'connectionName', {
}); });
/** /**
* Start connection task
* @public
* @returns {Promise} * @returns {Promise}
*/ */
EventStoreNodeConnection.prototype.connect = function() { EventStoreNodeConnection.prototype.connect = function() {
@ -87,12 +85,17 @@ EventStoreNodeConnection.prototype.connect = function() {
}); });
}; };
/**
* Close connection
* @public
*/
EventStoreNodeConnection.prototype.close = function() { EventStoreNodeConnection.prototype.close = function() {
this._handler.enqueueMessage(new messages.CloseConnectionMessage("Connection close requested by client.", null)); this._handler.enqueueMessage(new messages.CloseConnectionMessage("Connection close requested by client.", null));
}; };
/** /**
* Delete a stream (async) * Delete a stream (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} expectedVersion * @param {number} expectedVersion
* @param {boolean} [hardDelete] * @param {boolean} [hardDelete]
@ -120,6 +123,7 @@ EventStoreNodeConnection.prototype.deleteStream = function(stream, expectedVersi
/** /**
* Append events to a stream (async) * Append events to a stream (async)
* @public
* @param {string} stream The name of the stream to which to append. * @param {string} stream The name of the stream to which to append.
* @param {number} expectedVersion The version at which we currently expect the stream to be in order that an optimistic concurrency check can be performed. * @param {number} expectedVersion The version at which we currently expect the stream to be in order that an optimistic concurrency check can be performed.
* @param {EventData[]|EventData} events The event(s) to append. * @param {EventData[]|EventData} events The event(s) to append.
@ -148,6 +152,7 @@ EventStoreNodeConnection.prototype.appendToStream = function(stream, expectedVer
/** /**
* Start a transaction (async) * Start a transaction (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} expectedVersion * @param {number} expectedVersion
* @param {UserCredentials} [userCredentials] * @param {UserCredentials} [userCredentials]
@ -172,6 +177,7 @@ EventStoreNodeConnection.prototype.startTransaction = function(stream, expectedV
/** /**
* Continue a transaction * Continue a transaction
* @public
* @param {number} transactionId * @param {number} transactionId
* @param {UserCredentials} userCredentials * @param {UserCredentials} userCredentials
* @returns {EventStoreTransaction} * @returns {EventStoreTransaction}
@ -199,6 +205,13 @@ EventStoreNodeConnection.prototype.transactionalWrite = function(transaction, ev
}); });
}; };
/**
* Commit a transaction
* @public
* @param transaction
* @param userCredentials
* @returns {Promise.<WriteResult>}
*/
EventStoreNodeConnection.prototype.commitTransaction = function(transaction, userCredentials) { EventStoreNodeConnection.prototype.commitTransaction = function(transaction, userCredentials) {
ensure.isTypeOf(EventStoreTransaction, transaction, "transaction"); ensure.isTypeOf(EventStoreTransaction, transaction, "transaction");
@ -216,6 +229,7 @@ EventStoreNodeConnection.prototype.commitTransaction = function(transaction, use
/** /**
* Read a single event (async) * Read a single event (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} eventNumber * @param {number} eventNumber
* @param {boolean} [resolveLinkTos] * @param {boolean} [resolveLinkTos]
@ -248,6 +262,7 @@ EventStoreNodeConnection.prototype.readEvent = function(stream, eventNumber, res
/** /**
* Reading a specific stream forwards (async) * Reading a specific stream forwards (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} start * @param {number} start
* @param {number} count * @param {number} count
@ -281,6 +296,7 @@ EventStoreNodeConnection.prototype.readStreamEventsForward = function(
/** /**
* Reading a specific stream backwards (async) * Reading a specific stream backwards (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} start * @param {number} start
* @param {number} count * @param {number} count
@ -313,6 +329,7 @@ EventStoreNodeConnection.prototype.readStreamEventsBackward = function(
/** /**
* Reading all events forwards (async) * Reading all events forwards (async)
* @public
* @param {Position} position * @param {Position} position
* @param {number} maxCount * @param {number} maxCount
* @param {boolean} [resolveLinkTos] * @param {boolean} [resolveLinkTos]
@ -343,6 +360,7 @@ EventStoreNodeConnection.prototype.readAllEventsForward = function(
/** /**
* Reading all events backwards (async) * Reading all events backwards (async)
* @public
* @param {Position} position * @param {Position} position
* @param {number} maxCount * @param {number} maxCount
* @param {boolean} [resolveLinkTos] * @param {boolean} [resolveLinkTos]
@ -373,6 +391,7 @@ EventStoreNodeConnection.prototype.readAllEventsBackward = function(
/** /**
* Subscribe to a stream (async) * Subscribe to a stream (async)
* @public
* @param {!string} stream * @param {!string} stream
* @param {!boolean} resolveLinkTos * @param {!boolean} resolveLinkTos
* @param {function} eventAppeared * @param {function} eventAppeared
@ -402,6 +421,8 @@ EventStoreNodeConnection.prototype.subscribeToStream = function(
}; };
/** /**
* Subscribe to a stream from position
* @public
* @param {!string} stream * @param {!string} stream
* @param {?number} lastCheckpoint * @param {?number} lastCheckpoint
* @param {!boolean} resolveLinkTos * @param {!boolean} resolveLinkTos
@ -430,6 +451,7 @@ EventStoreNodeConnection.prototype.subscribeToStreamFrom = function(
/** /**
* Subscribe to all (async) * Subscribe to all (async)
* @public
* @param {!boolean} resolveLinkTos * @param {!boolean} resolveLinkTos
* @param {!function} eventAppeared * @param {!function} eventAppeared
* @param {function} [subscriptionDropped] * @param {function} [subscriptionDropped]
@ -456,6 +478,7 @@ EventStoreNodeConnection.prototype.subscribeToAll = function(
/** /**
* Subscribe to all from * Subscribe to all from
* @public
* @param {?Position} lastCheckpoint * @param {?Position} lastCheckpoint
* @param {!boolean} resolveLinkTos * @param {!boolean} resolveLinkTos
* @param {!function} eventAppeared * @param {!function} eventAppeared
@ -481,6 +504,7 @@ EventStoreNodeConnection.prototype.subscribeToAllFrom = function(
/** /**
* Subscribe to a persistent subscription * Subscribe to a persistent subscription
* @public
* @param {string} stream * @param {string} stream
* @param {string} groupName * @param {string} groupName
* @param {function} eventAppeared * @param {function} eventAppeared
@ -488,6 +512,7 @@ EventStoreNodeConnection.prototype.subscribeToAllFrom = function(
* @param {UserCredentials} [userCredentials] * @param {UserCredentials} [userCredentials]
* @param {number} [bufferSize] * @param {number} [bufferSize]
* @param {boolean} [autoAck] * @param {boolean} [autoAck]
* @return {EventStorePersistentSubscription}
*/ */
EventStoreNodeConnection.prototype.connectToPersistentSubscription = function( EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
stream, groupName, eventAppeared, subscriptionDropped, userCredentials, bufferSize, autoAck stream, groupName, eventAppeared, subscriptionDropped, userCredentials, bufferSize, autoAck
@ -510,6 +535,8 @@ EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
}; };
/** /**
* Create a persistent subscription
* @public
* @param {string} stream * @param {string} stream
* @param {string} groupName * @param {string} groupName
* @param {PersistentSubscriptionSettings} settings * @param {PersistentSubscriptionSettings} settings
@ -533,6 +560,8 @@ EventStoreNodeConnection.prototype.createPersistentSubscription = function(strea
}; };
/** /**
* Update a persistent subscription
* @public
* @param {string} stream * @param {string} stream
* @param {string} groupName * @param {string} groupName
* @param {string} settings * @param {string} settings
@ -555,6 +584,8 @@ EventStoreNodeConnection.prototype.updatePersistentSubscription = function(strea
}; };
/** /**
* Delete a persistent subscription
* @public
* @param {string} stream * @param {string} stream
* @param {string} groupName * @param {string} groupName
* @param {UserCredentials} [userCredentials] * @param {UserCredentials} [userCredentials]
@ -574,6 +605,10 @@ EventStoreNodeConnection.prototype.deletePersistentSubscription = function(strea
}); });
}; };
/**
* Set stream metadata
* @private
*/
EventStoreNodeConnection.prototype.setStreamMetadata = function() { EventStoreNodeConnection.prototype.setStreamMetadata = function() {
//TODO: set stream metadata (non-raw) //TODO: set stream metadata (non-raw)
throw new Error("Not implemented."); throw new Error("Not implemented.");
@ -581,6 +616,7 @@ EventStoreNodeConnection.prototype.setStreamMetadata = function() {
/** /**
* Set stream metadata with raw object (async) * Set stream metadata with raw object (async)
* @public
* @param {string} stream * @param {string} stream
* @param {number} expectedMetastreamVersion * @param {number} expectedMetastreamVersion
* @param {object} metadata * @param {object} metadata
@ -608,6 +644,12 @@ EventStoreNodeConnection.prototype.setStreamMetadataRaw = function(
}); });
}; };
/**
* Get stream metadata
* @private
* @param stream
* @param userCredentials
*/
EventStoreNodeConnection.prototype.getStreamMetadata = function(stream, userCredentials) { EventStoreNodeConnection.prototype.getStreamMetadata = function(stream, userCredentials) {
//TODO: get stream metadata (non-raw) //TODO: get stream metadata (non-raw)
throw new Error("Not implemented."); throw new Error("Not implemented.");
@ -615,6 +657,7 @@ EventStoreNodeConnection.prototype.getStreamMetadata = function(stream, userCred
/** /**
* Get stream metadata as raw object (async) * Get stream metadata as raw object (async)
* @public
* @param {string} stream * @param {string} stream
* @param {UserCredentials} [userCredentials] * @param {UserCredentials} [userCredentials]
* @returns {Promise.<RawStreamMetadataResult>} * @returns {Promise.<RawStreamMetadataResult>}
@ -640,6 +683,10 @@ EventStoreNodeConnection.prototype.getStreamMetadataRaw = function(stream, userC
}); });
}; };
/**
* Set system settings
* @private
*/
EventStoreNodeConnection.prototype.setSystemSettings = function() { EventStoreNodeConnection.prototype.setSystemSettings = function() {
//TODO: set system settings //TODO: set system settings
throw new Error("Not implemented."); throw new Error("Not implemented.");

View File

@ -4,6 +4,7 @@ var Long = require('long');
var ensure = require('./common/utils/ensure'); var ensure = require('./common/utils/ensure');
/** /**
* @public
* @param {!number|!Long} commitPosition * @param {!number|!Long} commitPosition
* @param {!number|!Long} preparePosition * @param {!number|!Long} preparePosition
* @constructor * @constructor

View File

@ -7,6 +7,7 @@ var TcpPackage = require('../../systemData/tcpPackage');
var TcpCommand = require('../../systemData/tcpCommand'); var TcpCommand = require('../../systemData/tcpCommand');
/** /**
* @private
* @param log * @param log
* @param remoteEndPoint * @param remoteEndPoint
* @param connectionId * @param connectionId

View File

@ -3,6 +3,7 @@ var util = require('util');
var EventStoreSubsription = require('./eventStoreSubscription'); var EventStoreSubsription = require('./eventStoreSubscription');
/** /**
* @private
* @param {SubscriptionOperation} subscriptionOperation * @param {SubscriptionOperation} subscriptionOperation
* @param {string} streamId * @param {string} streamId
* @param {Position} lastCommitPosition * @param {Position} lastCommitPosition