Browse Source

Merge branch 'v4_proto'

master
Nicolas Dextraze 5 years ago
parent
commit
a5807483a2
  1. 43
      index.d.ts
  2. 2
      package.json
  3. 13
      src/common/utils/ensure.js
  4. 33
      src/core/eventStoreConnectionLogicHandler.js
  5. 66
      src/eventStoreNodeConnection.js
  6. 13
      src/eventStoreStreamCatchUpSubscription.js
  7. 21899
      src/messages/messages.js
  8. 41
      src/messages/messages.proto
  9. 5
      src/persistentSubscriptionSettings.js
  10. 26
      src/results.js
  11. 4
      src/systemData/tcpCommand.js
  12. 30
      test/appendToStream_test.js
  13. 4
      test/common/base_test.js
  14. 11
      test/deleteStream_test.js
  15. 7
      test/metadata_test.js
  16. 32
      test/readEvent_test.js
  17. 34
      test/readStreamEventsBackward_test.js
  18. 32
      test/readStreamEventsForward_test.js
  19. 29
      test/subscribeToStreamFrom_test.js
  20. 3
      test/subscribeToStream_test.js
  21. 26
      test/transactions_test.js

43
index.d.ts vendored

@ -16,7 +16,7 @@ export class UserCredentials {
}
export class PersistentSubscriptionSettings {
constructor(resolveLinkTos: boolean, startFrom: number, extraStatistics: boolean, messageTimeout: number,
constructor(resolveLinkTos: boolean, startFrom: Long|number, extraStatistics: boolean, messageTimeout: number,
maxRetryCount: number, liveBufferSize: number, readBatchSize: number, historyBufferSize: number,
checkPointAfter: number, minCheckPointCount: number, maxCheckPointCount: number,
maxSubscriberCount: number, namedConsumerStrategy: string)
@ -41,7 +41,7 @@ export class WrongExpectedVersionError {
readonly action: string;
readonly message: string;
readonly stream?: string;
readonly expectedVersion?: number;
readonly expectedVersion?: Long;
readonly transactionId?: Long;
}
@ -98,17 +98,16 @@ export class FileLogger implements Logger {
error(fmt: string, ...args: any[]): void;
}
//
// Expose results
export interface WriteResult {
readonly nextExpectedVersion: number;
readonly nextExpectedVersion: Long;
readonly logPosition: Position;
}
export interface RecordedEvent {
readonly eventStreamId: string;
readonly eventId: string;
readonly eventNumber: number;
readonly eventNumber: Long;
readonly eventType: string;
readonly createdEpoch: number;
readonly data?: Buffer;
@ -123,17 +122,17 @@ export interface ResolvedEvent {
readonly isResolved: boolean;
readonly originalPosition?: Position;
readonly originalStreamId: string;
readonly originalEventNumber: number;
readonly originalEventNumber: Long;
}
export interface StreamEventsSlice {
readonly status: string; // TODO: enum
readonly stream: string;
readonly fromEventNumber: number;
readonly fromEventNumber: Long;
readonly readDirection: string; // TODO: enum
readonly events: ResolvedEvent[];
readonly nextEventNumber: number;
readonly lastEventNumber: number;
readonly nextEventNumber: Long;
readonly lastEventNumber: Long;
readonly isEndOfStream: boolean;
}
@ -159,7 +158,7 @@ export interface EventStoreTransaction {
export interface EventReadResult {
readonly status: string;
readonly stream: string;
readonly eventNumber: number;
readonly eventNumber: Long;
readonly event: ResolvedEvent | null;
}
@ -167,7 +166,7 @@ export interface EventStoreSubscription {
readonly isSubscribedToAll: boolean;
readonly streamId: string;
readonly lastCommitPosition: Position;
readonly lastEventNumber: number;
readonly lastEventNumber: Long;
close(): void;
unsubscribe(): void;
@ -194,7 +193,7 @@ export interface EventStorePersistentSubscription {
export interface RawStreamMetadataResult {
readonly stream: string;
readonly isStreamDeleted: boolean;
readonly metastreamVersion: number;
readonly metastreamVersion: Long;
readonly streamMetadata: any;
}
@ -249,28 +248,28 @@ export interface EventStoreNodeConnection {
connect(): Promise<void>;
close(): void;
// write actions
deleteStream(stream: string, expectedVersion: number, hardDelete?: boolean, userCredentials?: UserCredentials): Promise<DeleteResult>;
appendToStream(stream: string, expectedVersion: number, eventOrEvents: EventData | EventData[], userCredentials?: UserCredentials): Promise<WriteResult>;
startTransaction(stream: string, expectedVersion: number, userCredentials?: UserCredentials): Promise<EventStoreTransaction>;
deleteStream(stream: string, expectedVersion: Long|number, hardDelete?: boolean, userCredentials?: UserCredentials): Promise<DeleteResult>;
appendToStream(stream: string, expectedVersion: Long|number, eventOrEvents: EventData | EventData[], userCredentials?: UserCredentials): Promise<WriteResult>;
startTransaction(stream: string, expectedVersion: Long|number, userCredentials?: UserCredentials): Promise<EventStoreTransaction>;
continueTransaction(transactionId: number, userCredentials?: UserCredentials): EventStoreTransaction;
// read actions
readEvent(stream: string, eventNumber: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<EventReadResult>;
readStreamEventsForward(stream: string, start: number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
readStreamEventsBackward(stream: string, start: number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
readEvent(stream: string, eventNumber: Long|number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<EventReadResult>;
readStreamEventsForward(stream: string, start: Long|number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
readStreamEventsBackward(stream: string, start: Long|number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
readAllEventsForward(position: Position, maxCount: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<AllEventsSlice>;
readAllEventsBackward(position: Position, maxCount: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<AllEventsSlice>;
// subscription actions
subscribeToStream(stream: string, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
subscribeToStreamFrom(stream: string, lastCheckpoint: number | null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
subscribeToStreamFrom(stream: string, lastCheckpoint: Long|number|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
subscribeToAll(resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
subscribeToAllFrom(lastCheckpoint: Position | null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
subscribeToAllFrom(lastCheckpoint: Position|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
// persistent subscriptions
createPersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: PersistentSubscriptionSettings): Promise<PersistentSubscriptionCreateResult>;
updatePersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: PersistentSubscriptionSettings): Promise<PersistentSubscriptionUpdateResult>;
deletePersistentSubscription(stream: string, groupName: string, userCredentials?: PersistentSubscriptionSettings): Promise<PersistentSubscriptionDeleteResult>
connectToPersistentSubscription(stream: string, groupName: string, eventAppeared: EventAppearedCallback<EventStorePersistentSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStorePersistentSubscription>, userCredentials?: UserCredentials, bufferSize?: number, autoAck?: boolean): Promise<EventStorePersistentSubscription>;
// metadata actions
setStreamMetadataRaw(stream: string, expectedMetastreamVersion: number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
setStreamMetadataRaw(stream: string, expectedMetastreamVersion: Long|number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
getStreamMetadataRaw(stream: string, userCredentials?: UserCredentials): Promise<RawStreamMetadataResult>;
on(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error" | "heartbeatInfo", listener: (arg: Error | string | TcpEndPoint | HeartbeatInfo) => void): this;

2
package.json

@ -1,6 +1,6 @@
{
"name": "node-eventstore-client",
"version": "0.1.9",
"version": "0.2.0",
"description": "A port of the EventStore .Net ClientAPI to Node.js",
"main": "index.js",
"types": "index.d.ts",

13
src/common/utils/ensure.js

@ -1,3 +1,5 @@
var Long = require('long');
module.exports.notNullOrEmpty = function(value, name) {
if (value === null)
throw new TypeError(name + " should not be null.");
@ -10,9 +12,18 @@ module.exports.notNull = function(value, name) {
throw new TypeError(name + " should not be null.");
};
module.exports.isInteger = function(value, name) {
function isInteger(value, name) {
if (typeof value !== 'number' || value % 1 !== 0)
throw new TypeError(name + " should be an integer.");
}
module.exports.isInteger = isInteger;
module.exports.isLongOrInteger = function(value, name) {
if (typeof value === 'number') {
return isInteger(value, name);
} else if (!Long.isLong(value)) {
throw new TypeError(name + " should be a Long|number.");
}
};
module.exports.isArrayOf = function(expectedType, value, name) {

33
src/core/eventStoreConnectionLogicHandler.js

@ -9,6 +9,8 @@ var SubscriptionsManager = require('./subscriptionsManager');
var VolatileSubscriptionOperation = require('../clientOperations/volatileSubscriptionOperation');
var ConnectToPersistentSubscriptionOperation = require('../clientOperations/connectToPersistentSubscriptionOperation');
var messages = require('./messages');
var ClientMessage = require('../messages/clientMessage');
var createBufferSegment = require('../common/bufferSegment');
var TcpPackage = require('../systemData/tcpPackage');
var TcpCommand = require('../systemData/tcpCommand');
@ -28,12 +30,14 @@ const ConnectingPhase = {
EndPointDiscovery: 'endpointDiscovery',
ConnectionEstablishing: 'connectionEstablishing',
Authentication: 'authentication',
Identification: 'identification',
Connected: 'connected'
};
const TimerPeriod = 200;
const TimerTickMessage = new messages.TimerTickMessage();
const EmptyGuid = '00000000-0000-0000-0000-000000000000';
const ClientVersion = 1;
/**
* @private
@ -391,10 +395,21 @@ EventStoreConnectionLogicHandler.prototype._tcpConnectionEstablished = function(
}
else
{
this._goToConnectedState();
this._goToIdentifiedState();
}
};
EventStoreConnectionLogicHandler.prototype._goToIdentifiedState = function() {
this._connectingPhase = ConnectingPhase.Identification;
this._identityInfo = {
correlationId: uuid.v4(),
timeStamp: Date.now()
};
var dto = new ClientMessage.IdentifyClient({version: ClientVersion, connectionName: this._esConnection.connectionName});
var buf = dto.constructor.encode(dto).finish();
this._connection.enqueueSend(new TcpPackage(TcpCommand.IdentifyClient, TcpFlags.None, this._identityInfo.correlationId, null, null, createBufferSegment(buf)))
};
EventStoreConnectionLogicHandler.prototype._goToConnectedState = function() {
this._state = ConnectionState.Connected;
this._connectingPhase = ConnectingPhase.Connected;
@ -498,6 +513,16 @@ EventStoreConnectionLogicHandler.prototype._handleTcpPackage = function(connecti
if (pkg.command === TcpCommand.NotAuthenticated)
this.emit('authenticationFailed', "Not authenticated");
this._goToIdentifiedState();
return;
}
}
if (pkg.command === TcpCommand.ClientIdentified)
{
if (this._state === ConnectionState.Connecting
&& this._identityInfo.correlationId === pkg.correlationId)
{
this._goToConnectedState();
return;
}
@ -617,7 +642,11 @@ EventStoreConnectionLogicHandler.prototype._timerTick = function() {
else if (this._connectingPhase === ConnectingPhase.Authentication && (Date.now() - this._authInfo.timeStamp) >= this._settings.operationTimeout)
{
this.emit('authenticationFailed', "Authentication timed out.");
this._goToConnectedState();
if (this._clientVersion === 1) {
this._goToIdentifiedState();
} else {
this._goToConnectedState();
}
}
else if (this._connectingPhase === ConnectingPhase.Authentication || this._connectingPhase === ConnectingPhase.Connected)
this._manageHeartbeats();

66
src/eventStoreNodeConnection.js

@ -1,5 +1,6 @@
var util = require('util');
var uuid = require('uuid');
var Long = require('long');
var EventEmitter = require('events').EventEmitter;
var ensure = require('./common/utils/ensure');
@ -100,15 +101,16 @@ EventStoreNodeConnection.prototype.close = function() {
* Delete a stream (async)
* @public
* @param {string} stream
* @param {number} expectedVersion
* @param {Long|number} expectedVersion
* @param {boolean} [hardDelete]
* @param {UserCredentials} [userCredentials]
* @returns {Promise.<DeleteResult>}
*/
EventStoreNodeConnection.prototype.deleteStream = function(stream, expectedVersion, hardDelete, userCredentials) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(expectedVersion, "expectedVersion");
hardDelete = !!hardDelete;
ensure.isLongOrInteger(expectedVersion, "expectedVersion");
expectedVersion = Long.fromValue(expectedVersion);
hardDelete = Boolean(hardDelete);
userCredentials = userCredentials || null;
var self = this;
@ -128,14 +130,15 @@ EventStoreNodeConnection.prototype.deleteStream = function(stream, expectedVersi
* Append events to a stream (async)
* @public
* @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 {Long|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 {UserCredentials} [userCredentials] User credentials
* @returns {Promise.<WriteResult>}
*/
EventStoreNodeConnection.prototype.appendToStream = function(stream, expectedVersion, events, userCredentials) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(expectedVersion, "expectedVersion");
ensure.isLongOrInteger(expectedVersion, "expectedVersion");
expectedVersion = Long.fromValue(expectedVersion);
if (!Array.isArray(events))
events = [events];
ensure.isArrayOf(EventData, events, "events");
@ -157,13 +160,14 @@ EventStoreNodeConnection.prototype.appendToStream = function(stream, expectedVer
* Start a transaction (async)
* @public
* @param {string} stream
* @param {number} expectedVersion
* @param {Long|number} expectedVersion
* @param {UserCredentials} [userCredentials]
* @returns {Promise.<EventStoreTransaction>}
*/
EventStoreNodeConnection.prototype.startTransaction = function(stream, expectedVersion, userCredentials) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(expectedVersion, "expectedVersion");
ensure.isLongOrInteger(expectedVersion, "expectedVersion");
expectedVersion = Long.fromValue(expectedVersion);
userCredentials = userCredentials || null;
var self = this;
@ -234,21 +238,20 @@ EventStoreNodeConnection.prototype.commitTransaction = function(transaction, use
* Read a single event (async)
* @public
* @param {string} stream
* @param {number} eventNumber
* @param {Long|number} eventNumber
* @param {boolean} [resolveLinkTos]
* @param {UserCredentials} [userCredentials]
* @returns {Promise.<EventReadResult>}
*/
EventStoreNodeConnection.prototype.readEvent = function(stream, eventNumber, resolveLinkTos, userCredentials) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(eventNumber, "eventNumber");
if (eventNumber < -1) throw new Error("eventNumber out of range.");
resolveLinkTos = !!resolveLinkTos;
ensure.isLongOrInteger(eventNumber, "eventNumber");
eventNumber = Long.fromValue(eventNumber);
resolveLinkTos = Boolean(resolveLinkTos);
userCredentials = userCredentials || null;
if (typeof stream !== 'string' || stream === '') throw new TypeError("stream must be an non-empty string.");
if (typeof eventNumber !== 'number' || eventNumber % 1 !== 0) throw new TypeError("eventNumber must be an integer.");
if (eventNumber < -1) throw new Error("eventNumber out of range.");
if (eventNumber.compare(-1) < 0) throw new Error("eventNumber out of range.");
if (resolveLinkTos && typeof resolveLinkTos !== 'boolean') throw new TypeError("resolveLinkTos must be a boolean.");
var self = this;
@ -267,7 +270,7 @@ EventStoreNodeConnection.prototype.readEvent = function(stream, eventNumber, res
* Reading a specific stream forwards (async)
* @public
* @param {string} stream
* @param {number} start
* @param {Long|number} start
* @param {number} count
* @param {boolean} [resolveLinkTos]
* @param {UserCredentials} [userCredentials]
@ -277,12 +280,13 @@ EventStoreNodeConnection.prototype.readStreamEventsForward = function(
stream, start, count, resolveLinkTos, userCredentials
) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(start, "start");
ensure.isLongOrInteger(start, "start");
start = Long.fromValue(start);
ensure.nonNegative(start, "start");
ensure.isInteger(count, "count");
ensure.positive(count, "count");
if (count > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
resolveLinkTos = !!resolveLinkTos;
resolveLinkTos = Boolean(resolveLinkTos);
userCredentials = userCredentials || null;
var self = this;
@ -301,7 +305,7 @@ EventStoreNodeConnection.prototype.readStreamEventsForward = function(
* Reading a specific stream backwards (async)
* @public
* @param {string} stream
* @param {number} start
* @param {Long|number} start
* @param {number} count
* @param {boolean} [resolveLinkTos]
* @param {UserCredentials} [userCredentials]
@ -311,11 +315,12 @@ EventStoreNodeConnection.prototype.readStreamEventsBackward = function(
stream, start, count, resolveLinkTos, userCredentials
) {
ensure.notNullOrEmpty(stream, "stream");
ensure.isInteger(start, "start");
ensure.isLongOrInteger(start, "start");
start = Long.fromValue(start);
ensure.isInteger(count, "count");
ensure.positive(count, "count");
if (count > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
resolveLinkTos = !!resolveLinkTos;
resolveLinkTos = Boolean(resolveLinkTos);
userCredentials = userCredentials || null;
var self = this;
@ -346,7 +351,7 @@ EventStoreNodeConnection.prototype.readAllEventsForward = function(
ensure.isInteger(maxCount, "maxCount");
ensure.positive(maxCount, "maxCount");
if (maxCount > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
resolveLinkTos = !!resolveLinkTos;
resolveLinkTos = Boolean(resolveLinkTos);
userCredentials = userCredentials || null;
var self = this;
@ -377,7 +382,7 @@ EventStoreNodeConnection.prototype.readAllEventsBackward = function(
ensure.isInteger(maxCount, "maxCount");
ensure.positive(maxCount, "maxCount");
if (maxCount > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
resolveLinkTos = !!resolveLinkTos;
resolveLinkTos = Boolean(resolveLinkTos);
userCredentials = userCredentials || null;
var self = this;
@ -427,7 +432,7 @@ EventStoreNodeConnection.prototype.subscribeToStream = function(
* Subscribe to a stream from position
* @public
* @param {!string} stream
* @param {?number} lastCheckpoint
* @param {?number|Position} lastCheckpoint
* @param {!boolean} resolveLinkTos
* @param {!function} eventAppeared
* @param {function} [liveProcessingStarted]
@ -441,7 +446,10 @@ EventStoreNodeConnection.prototype.subscribeToStreamFrom = function(
userCredentials, readBatchSize
) {
if (typeof stream !== 'string' || stream === '') throw new TypeError("stream must be a non-empty string.");
if (lastCheckpoint !== null && typeof lastCheckpoint !== 'number') throw new TypeError("lastCheckpoint must be a number or null.");
if (lastCheckpoint !== null) {
ensure.isLongOrInteger(lastCheckpoint);
lastCheckpoint = Long.fromValue(lastCheckpoint);
}
if (typeof eventAppeared !== 'function') throw new TypeError("eventAppeared must be a function.");
var catchUpSubscription =
@ -531,7 +539,7 @@ EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
subscriptionDropped = subscriptionDropped || null;
userCredentials = userCredentials || null;
bufferSize = bufferSize === undefined ? 10 : bufferSize;
autoAck = autoAck === undefined ? true : !!autoAck;
autoAck = autoAck === undefined ? true : Boolean(autoAck);
var subscription = new EventStorePersistentSubscription(
groupName, stream, eventAppeared, subscriptionDropped, userCredentials, this._settings.log,
@ -623,7 +631,7 @@ EventStoreNodeConnection.prototype.setStreamMetadata = function() {
* Set stream metadata with raw object (async)
* @public
* @param {string} stream
* @param {number} expectedMetastreamVersion
* @param {Long|number} expectedMetastreamVersion
* @param {object} metadata
* @param {UserCredentials} [userCredentials]
* @returns {Promise.<WriteResult>}
@ -634,6 +642,8 @@ EventStoreNodeConnection.prototype.setStreamMetadataRaw = function(
ensure.notNullOrEmpty(stream, "stream");
if (systemStreams.isMetastream(stream))
throw new Error(util.format("Setting metadata for metastream '%s' is not supported.", stream));
ensure.isLongOrInteger(expectedMetastreamVersion, "expectedMetastreamVersion");
expectedMetastreamVersion = Long.fromValue(expectedMetastreamVersion);
var self = this;
return new Promise(function(resolve, reject) {
function cb(err, result) {
@ -676,12 +686,12 @@ EventStoreNodeConnection.prototype.getStreamMetadataRaw = function(stream, userC
var evnt = res.event.originalEvent;
var version = evnt ? evnt.eventNumber : -1;
var data = evnt ? JSON.parse(evnt.data.toString()) : null;
return new results.RawStreamMetadataResult(stream, false, version, data);
return new results.RawStreamMetadataResult(stream, false, Long.fromValue(version), data);
case results.EventReadStatus.NotFound:
case results.EventReadStatus.NoStream:
return new results.RawStreamMetadataResult(stream, false, -1, null);
return new results.RawStreamMetadataResult(stream, false, Long.fromValue(-1), null);
case results.EventReadStatus.StreamDeleted:
return new results.RawStreamMetadataResult(stream, true, 0x7fffffff, null);
return new results.RawStreamMetadataResult(stream, true, Long.fromValue(0x7fffffff), null);
default:
throw new Error(util.format("Unexpected ReadEventResult: %s.", res.status));
}

13
src/eventStoreStreamCatchUpSubscription.js

@ -1,4 +1,5 @@
var util = require('util');
var Long = require('long');
var EventStoreCatchUpSubscription = require('./eventStoreCatchUpSubscription');
var SliceReadStatus = require('./sliceReadStatus');
@ -14,8 +15,8 @@ function EventStoreStreamCatchUpSubscription(
//Ensure.NotNullOrEmpty(streamId, "streamId");
this._lastProcessedEventNumber = fromEventNumberExclusive === null ? -1 : fromEventNumberExclusive;
this._nextReadEventNumber = fromEventNumberExclusive === null ? 0 : fromEventNumberExclusive + 1;
this._lastProcessedEventNumber = fromEventNumberExclusive === null ? Long.fromNumber(-1) : fromEventNumberExclusive;
this._nextReadEventNumber = fromEventNumberExclusive === null ? Long.fromNumber(0) : fromEventNumberExclusive.add(1);
}
util.inherits(EventStoreStreamCatchUpSubscription, EventStoreCatchUpSubscription);
@ -47,14 +48,14 @@ EventStoreStreamCatchUpSubscription.prototype._readEventsTill = function(
return processEvents(slice.events, 0)
.then(function() {
self._nextReadEventNumber = slice.nextEventNumber;
var done = Promise.resolve(lastEventNumber === null ? slice.isEndOfStream : slice.nextEventNumber > lastEventNumber);
var done = Promise.resolve(lastEventNumber === null ? slice.isEndOfStream : slice.nextEventNumber.compare(lastEventNumber) > 0);
if (!done && slice.isEndOfStream)
return delay(100, false);
return done;
});
break;
case SliceReadStatus.StreamNotFound:
if (lastEventNumber && lastEventNumber !== -1)
if (lastEventNumber && lastEventNumber.compare(-1) !== 0)
throw new Error(util.format("Impossible: stream %s disappeared in the middle of catching up subscription.", self.streamId));
return true;
case SliceReadStatus.StreamDeleted:
@ -80,7 +81,7 @@ EventStoreStreamCatchUpSubscription.prototype._readEventsTill = function(
EventStoreStreamCatchUpSubscription.prototype._tryProcess = function(e) {
var processed = false;
var promise;
if (e.originalEventNumber > this._lastProcessedEventNumber) {
if (e.originalEventNumber.compare(this._lastProcessedEventNumber) > 0) {
promise = this._eventAppeared(this, e);
this._lastProcessedEventNumber = e.originalEventNumber;
processed = true;
@ -88,7 +89,7 @@ EventStoreStreamCatchUpSubscription.prototype._tryProcess = function(e) {
if (this._verbose)
this._log.debug("Catch-up Subscription to %s: %s event (%s, %d, %s @ %d).",
this.isSubscribedToAll ? '<all>' : this.streamId, processed ? "processed" : "skipping",
e.originalEvent.eventStreamId, e.originalEvent.eventNumber, e.originalEvent.eventType, e.originalEventNumber)
e.originalEvent.eventStreamId, e.originalEvent.eventNumber, e.originalEvent.eventType, e.originalEventNumber);
return (promise && promise.then) ? promise : Promise.resolve();
};

21899
src/messages/messages.js

File diff suppressed because it is too large Load Diff

41
src/messages/messages.proto

@ -23,7 +23,7 @@ message NewEvent {
message EventRecord {
required string event_stream_id = 1;
required int32 event_number = 2;
required int64 event_number = 2;
required bytes event_id = 3;
required string event_type = 4;
required int32 data_content_type = 5;
@ -48,7 +48,7 @@ message ResolvedEvent {
message WriteEvents {
required string event_stream_id = 1;
required int32 expected_version = 2;
required int64 expected_version = 2;
repeated NewEvent events = 3;
required bool require_master = 4;
}
@ -56,15 +56,16 @@ message WriteEvents {
message WriteEventsCompleted {
required OperationResult result = 1;
optional string message = 2;
required int32 first_event_number = 3;
required int32 last_event_number = 4;
required int64 first_event_number = 3;
required int64 last_event_number = 4;
optional int64 prepare_position = 5;
optional int64 commit_position = 6;
optional int64 current_version = 7;
}
message DeleteStream {
required string event_stream_id = 1;
required int32 expected_version = 2;
required int64 expected_version = 2;
required bool require_master = 3;
optional bool hard_delete = 4;
}
@ -78,7 +79,7 @@ message DeleteStreamCompleted {
message TransactionStart {
required string event_stream_id = 1;
required int32 expected_version = 2;
required int64 expected_version = 2;
required bool require_master = 3;
}
@ -109,15 +110,15 @@ message TransactionCommitCompleted {
required int64 transaction_id = 1;
required OperationResult result = 2;
optional string message = 3;
required int32 first_event_number = 4;
required int32 last_event_number = 5;
required int64 first_event_number = 4;
required int64 last_event_number = 5;
optional int64 prepare_position = 6;
optional int64 commit_position = 7;
}
message ReadEvent {
required string event_stream_id = 1;
required int32 event_number = 2;
required int64 event_number = 2;
required bool resolve_link_tos = 3;
required bool require_master = 4;
}
@ -141,7 +142,7 @@ message ReadEventCompleted {
message ReadStreamEvents {
required string event_stream_id = 1;
required int32 from_event_number = 2;
required int64 from_event_number = 2;
required int32 max_count = 3;
required bool resolve_link_tos = 4;
required bool require_master = 5;
@ -160,8 +161,8 @@ message ReadStreamEventsCompleted {
repeated ResolvedIndexedEvent events = 1;
required ReadStreamResult result = 2;
required int32 next_event_number = 3;
required int32 last_event_number = 4;
required int64 next_event_number = 3;
required int64 last_event_number = 4;
required bool is_end_of_stream = 5;
required int64 last_commit_position = 6;
@ -199,7 +200,7 @@ message CreatePersistentSubscription {
required string subscription_group_name = 1;
required string event_stream_id = 2;
required bool resolve_link_tos = 3;
required int32 start_from = 4;
required int64 start_from = 4;
required int32 message_timeout_milliseconds = 5;
required bool record_statistics = 6;
required int32 live_buffer_size = 7;
@ -223,7 +224,7 @@ message UpdatePersistentSubscription {
required string subscription_group_name = 1;
required string event_stream_id = 2;
required bool resolve_link_tos = 3;
required int32 start_from = 4;
required int64 start_from = 4;
required int32 message_timeout_milliseconds = 5;
required bool record_statistics = 6;
required int32 live_buffer_size = 7;
@ -301,7 +302,7 @@ message PersistentSubscriptionNakEvents {
message PersistentSubscriptionConfirmation {
required int64 last_commit_position = 1;
required string subscription_id = 2;
optional int32 last_event_number = 3;
optional int64 last_event_number = 3;
}
message PersistentSubscriptionStreamEventAppeared {
@ -315,7 +316,7 @@ message SubscribeToStream {
message SubscriptionConfirmation {
required int64 last_commit_position = 1;
optional int32 last_event_number = 2;
optional int64 last_event_number = 2;
}
message StreamEventAppeared {
@ -375,3 +376,11 @@ message ScavengeDatabaseCompleted {
required int32 total_time_ms = 3;
required int64 total_space_saved = 4;
}
message IdentifyClient {
required int32 version = 1;
optional string connection_name = 2;
}
message ClientIdentified {
}

5
src/persistentSubscriptionSettings.js

@ -1,4 +1,6 @@
var SystemConsumerStrategies = require('./systemConsumerStrategies');
var ensure = require('./common/utils/ensure');
var Long = require('long');
function PersistentSubscriptionSettings(
resolveLinkTos, startFrom, extraStatistics, messageTimeout,
@ -6,6 +8,9 @@ function PersistentSubscriptionSettings(
checkPointAfter, minCheckPointCount, maxCheckPointCount,
maxSubscriberCount, namedConsumerStrategy
) {
ensure.isLongOrInteger(startFrom);
startFrom = Long.fromValue(startFrom);
this.resolveLinkTos = resolveLinkTos;
this.startFrom = startFrom;
this.extraStatistics = extraStatistics;

26
src/results.js

@ -44,7 +44,7 @@ Object.freeze(EventReadStatus);
* @constructor
* @property {string} eventStreamId
* @property {string} eventId
* @property {number} eventNumber
* @property {Long} eventNumber
* @property {string} eventType
* @property {number} createdEpoch
* @property {?Buffer} data
@ -73,7 +73,7 @@ function RecordedEvent(ev) {
* @property {boolean} isResolved
* @property {?Position} originalPosition
* @property {string} originalStreamId
* @property {number} originalEventNumber
* @property {Long} originalEventNumber
*/
function ResolvedEvent(ev) {
this.event = ev.event === null ? null : new RecordedEvent(ev.event);
@ -90,12 +90,12 @@ function ResolvedEvent(ev) {
*
* @param {string} status
* @param {string} stream
* @param {number} eventNumber
* @param {Long} eventNumber
* @param {object} event
* @constructor
* @property {string} status
* @property {string} stream
* @property {number} eventNumber
* @property {Long} eventNumber
* @property {ResolvedEvent} event
*/
function EventReadResult(status, stream, eventNumber, event) {
@ -110,7 +110,7 @@ function EventReadResult(status, stream, eventNumber, event) {
* @param {number} nextExpectedVersion
* @param {Position} logPosition
* @constructor
* @property {number} nextExpectedVersion
* @property {Long} nextExpectedVersion
* @property {Position} logPosition
*/
function WriteResult(nextExpectedVersion, logPosition) {
@ -122,20 +122,20 @@ function WriteResult(nextExpectedVersion, logPosition) {
/**
* @param {string} status
* @param {string} stream
* @param {number} fromEventNumber
* @param {Long} fromEventNumber
* @param {string} readDirection
* @param {object[]} events
* @param {number} nextEventNumber
* @param {number} lastEventNumber
* @param {Long} nextEventNumber
* @param {Long} lastEventNumber
* @param {boolean} isEndOfStream
* @constructor
* @property {string} status
* @property {string} stream
* @property {number} fromEventNumber
* @property {Long} fromEventNumber
* @property {string} readDirection
* @property {ResolvedEvent[]} events
* @property {number} nextEventNumber
* @property {number} lastEventNumber
* @property {Long} nextEventNumber
* @property {Long} lastEventNumber
* @property {boolean} isEndOfStream
*/
function StreamEventsSlice(
@ -185,12 +185,12 @@ function DeleteResult(logPosition) {
/**
* @param {string} stream
* @param {boolean} isStreamDeleted
* @param {number} metastreamVersion
* @param {Long} metastreamVersion
* @param {object} streamMetadata
* @constructor
* @property {string} stream
* @property {boolean} isStreamDeleted
* @property {number} metastreamVersion
* @property {Long} metastreamVersion
* @property {object} streamMetadata
*/
function RawStreamMetadataResult(stream, isStreamDeleted, metastreamVersion, streamMetadata) {

4
src/systemData/tcpCommand.js

@ -71,7 +71,9 @@ const TcpCommand = {
NotHandled: 0xF1,
Authenticate: 0xF2,
Authenticated: 0xF3,
NotAuthenticated: 0xF4
NotAuthenticated: 0xF4,
IdentifyClient: 0xF5,
ClientIdentified: 0xF6
};
var _reverseLookup = {};

30
test/appendToStream_test.js

@ -1,13 +1,17 @@
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
var ANY_VERSION = Long.fromNumber(client.expectedVersion.any);
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
module.exports = {
'Append One Event To Stream Happy Path': function(test) {
test.expect(2);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, event)
.then(function(result) {
test.areEqual("nextExpectedVersion", result.nextExpectedVersion, 0);
test.areEqual("nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(0));
test.ok(result.logPosition, "No log position in result.");
test.done();
})
@ -25,9 +29,9 @@ module.exports = {
else
events.push(client.createJsonEventData(uuid.v4(), {b: Math.random(), a: uuid.v4()}, null, 'otherEvent'));
}
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, events)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, events)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, expectedVersion);
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(expectedVersion));
test.ok(result.logPosition, "No log position in result.");
test.done();
})
@ -45,9 +49,9 @@ module.exports = {
else
events.push(client.createJsonEventData(uuid.v4(), {b: Math.random(), a: uuid.v4()}, null, 'otherEvent'));
}
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, events)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, events)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, expectedVersion);
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(expectedVersion));
test.ok(result.logPosition, "No log position in result.");
test.done();
})
@ -60,9 +64,9 @@ module.exports = {
const largeData = Buffer.alloc(3 * 1024 *1024, " ");
const event = client.createJsonEventData(uuid.v4(), {a: largeData.toString()}, null, 'largePayloadEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, event)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, 0);
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(0));
test.ok(result.logPosition, "No log position in result.");
test.done();
})
@ -73,7 +77,7 @@ module.exports = {
'Append To Stream Wrong Expected Version': function(test) {
test.expect(1);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, 10, event)
this.conn.appendToStream(this.testStreamName, Long.fromNumber(10), event)
.then(function(result) {
test.fail("Append succeeded but should have failed.");
test.done();
@ -88,10 +92,10 @@ module.exports = {
'Append To Stream Deleted': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true)
this.conn.deleteStream(this.testStreamName, NOSTREAM_VERSION, true)
.then(function() {
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, event)
return self.conn.appendToStream(self.testStreamName, ANY_VERSION, event)
})
.then(function(result) {
test.fail("Append succeeded but should have failed.");
@ -108,10 +112,10 @@ module.exports = {
test.expect(1);
var self = this;
var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(this.testStreamName, NOSTREAM_VERSION, metadata)
.then(function() {
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, event)
return self.conn.appendToStream(self.testStreamName, ANY_VERSION, event)
})
.then(function(result) {
test.fail("Append succeeded but should have failed.");

4
test/common/base_test.js

@ -78,7 +78,7 @@ function testLiveEvent(name, event, evNumber) {
this.ok(event.originalPosition instanceof client.Position, name + ".originalPosition is not an instance of Position");
this.ok(event.originalStreamId, name + ".originalStreamId not defined (or null)");
if (typeof evNumber === 'number') {
this.ok(event.originalEventNumber === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber);
this.ok(event.originalEventNumber.toNumber() === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber);
} else {
this.ok(typeof event.originalEventNumber === 'number', name + ".originalEventNumber is not a number");
}
@ -91,7 +91,7 @@ function testReadEvent(name, event, evNumber) {
this.ok(event.originalPosition === null, name + ".originalPosition is not null");
this.ok(event.originalStreamId, name + ".originalStreamId not defined (or null)");
if (typeof evNumber === 'number') {
this.ok(event.originalEventNumber === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber);
this.ok(event.originalEventNumber.toNumber() === evNumber, name + '.originalEventNumber expected ' + evNumber + ' got ' + event.originalEventNumber);
} else {
this.ok(typeof event.originalEventNumber === 'number', name + ".originalEventNumber is not a number");
}

11
test/deleteStream_test.js

@ -1,5 +1,6 @@
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
module.exports = {
setUp: function(cb) {
@ -16,7 +17,7 @@ module.exports = {
'Test Delete Stream Soft Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, false)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(1), false)
.then(function(result) {
test.ok(result.logPosition, "No log position in result.");
return self.conn.getStreamMetadataRaw(self.testStreamName);
@ -34,7 +35,7 @@ module.exports = {
'Test Delete Stream Hard Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(1), true)
.then(function(result) {
test.ok(result.logPosition, "No log position in result.");
return self.conn.getStreamMetadataRaw(self.testStreamName);
@ -51,7 +52,7 @@ module.exports = {
},
'Test Delete Stream With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.deleteStream(this.testStreamName, 10)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(10))
.then(function(result) {
test.fail("Delete succeeded but should have failed.");
test.done();
@ -68,7 +69,7 @@ module.exports = {
var self = this;
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}})
.then(function() {
return self.conn.deleteStream(self.testStreamName, 10);
return self.conn.deleteStream(self.testStreamName, Long.fromNumber(10));
})
.then(function(result) {
test.fail("Delete succeeded but should have failed.");
@ -86,7 +87,7 @@ module.exports = {
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
.then(function() {
return self.conn.deleteStream(self.testStreamName, 1, true);
return self.conn.deleteStream(self.testStreamName, Long.fromNumber(1), true);
})
.then(function(result) {
test.fail("Delete succeeded but should have failed.");

7
test/metadata_test.js

@ -1,10 +1,11 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
const Long = require('long');
const EMPTY_VERSION = Long.fromNumber(client.expectedVersion.emptyStream);
module.exports = {
'Test Set Stream Metadata Raw': function(test) {
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.emptyStream, {$maxCount: 100})
this.conn.setStreamMetadataRaw(this.testStreamName, EMPTY_VERSION, {$maxCount: 100})
.then(function(result) {
test.done();
})

32
test/readEvent_test.js

@ -1,7 +1,9 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
var ANY_VERSION = Long.fromNumber(client.expectedVersion.any);
module.exports = {
setUp: function(cb) {
@ -12,7 +14,7 @@ module.exports = {
this.expectedEventType = 'anEvent';
this.expectedEventId = uuid.v4();
var event = client.createJsonEventData(this.expectedEventId, this.expectedEvent, null, this.expectedEventType);
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, event)
this.conn.appendToStream(this.testStreamName, NOSTREAM_VERSION, event)
.then(function() {
cb();
})
@ -21,11 +23,11 @@ module.exports = {
'Read Event Happy Path': function(test) {
test.expect(8);
var self = this;
this.conn.readEvent(this.testStreamName, 0)
this.conn.readEvent(this.testStreamName, Long.fromNumber(0))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.Success);
test.areEqual('stream', result.stream, self.testStreamName);
test.areEqual('eventNumber', result.eventNumber, 0);
test.areEqual('eventNumber', result.eventNumber, Long.fromNumber(0));
test.ok(result.event !== null, "event is null.");
test.ok(result.event.originalEvent !== null, "event.originalEvent is null.");
var event = JSON.parse(result.event.originalEvent.data.toString());
@ -41,11 +43,11 @@ module.exports = {
'Read Event From Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readEvent(anotherStream, 0)
this.conn.readEvent(anotherStream, Long.fromNumber(0))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.NoStream);
test.areEqual('stream', result.stream, anotherStream);
test.areEqual('eventNumber', result.eventNumber, 0);
test.areEqual('eventNumber', result.eventNumber, Long.fromNumber(0));
test.areEqual('event', result.event, null);
test.done();
})
@ -58,12 +60,12 @@ module.exports = {
var self = this;
this.conn.deleteStream(this.testStreamName, 0, true)
.then(function() {
return self.conn.readEvent(self.testStreamName, 0)
return self.conn.readEvent(self.testStreamName, Long.fromNumber(0))
})
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.StreamDeleted);
test.areEqual('stream', result.stream, self.testStreamName);
test.areEqual('eventNumber', result.eventNumber, 0);
test.areEqual('eventNumber', result.eventNumber, Long.fromNumber(0));
test.areEqual('event', result.event, null);
test.done();
})
@ -74,11 +76,11 @@ module.exports = {
'Read Event With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readEvent(self.testStreamName, 1)
return self.conn.readEvent(self.testStreamName, Long.fromNumber(1))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.NotFound);
test.areEqual('stream', result.stream, self.testStreamName);
test.areEqual('eventNumber', result.eventNumber, 1);
test.areEqual('eventNumber', result.eventNumber, Long.fromNumber(1));
test.areEqual('event', result.event, null);
test.done();
})
@ -94,9 +96,9 @@ module.exports = {
$r: '$admins'
}
};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(self.testStreamName, NOSTREAM_VERSION, metadata)
.then(function() {
return self.conn.readEvent(self.testStreamName, 0);
return self.conn.readEvent(self.testStreamName, Long.fromNumber(0));
})
.then(function(result) {
test.fail("readEvent succeeded but should have failed.");
@ -118,13 +120,13 @@ module.exports = {
a: largeData.toString()
}, null, 'largePayloadEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, largeEvent)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, largeEvent)
.then(function(result) {
self.conn.readEvent(self.testStreamName, 1)
self.conn.readEvent(self.testStreamName, Long.fromNumber(1))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.Success);
test.areEqual('stream', result.stream, self.testStreamName);
test.areEqual('eventNumber', result.eventNumber, 1);
test.areEqual('eventNumber', result.eventNumber, Long.fromNumber(1));
test.ok(result.event !== null, "event is null.");
test.ok(result.event.originalEvent !== null, "event.originalEvent is null.");
var event = JSON.parse(result.event.originalEvent.data.toString());

34
test/readStreamEventsBackward_test.js

@ -1,15 +1,17 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
const streamSize = 100;
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
module.exports = {
setUp: function(cb) {
this.eventsData = [];
for(var i = 0; i < streamSize; i++)
this.eventsData.push(client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, null, 'anEvent'));
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, this.eventsData)
this.conn.appendToStream(this.testStreamName, NOSTREAM_VERSION, this.eventsData)
.then(function() {
cb();
})
@ -18,19 +20,19 @@ module.exports = {
'Read Stream Events Backward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this;
this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize)
this.conn.readStreamEventsBackward(this.testStreamName, Long.fromNumber(streamSize-1), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.Success);
test.areEqual('slice.stream', slice.stream, self.testStreamName);
test