Update proto

This commit is contained in:
Nicolas Dextraze 2017-10-17 14:31:26 -07:00
parent 18e35c56f9
commit 990351738c
8 changed files with 11403 additions and 10741 deletions

14
index.d.ts vendored
View File

@ -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;
}
@ -101,7 +101,7 @@ export class FileLogger implements Logger {
//
export interface WriteResult {
readonly nextExpectedVersion: number;
readonly nextExpectedVersion: Long;
readonly logPosition: Position;
}
@ -194,7 +194,7 @@ export interface EventStorePersistentSubscription {
export interface RawStreamMetadataResult {
readonly stream: string;
readonly isStreamDeleted: boolean;
readonly metastreamVersion: number;
readonly metastreamVersion: Long;
readonly streamMetadata: any;
}
@ -249,9 +249,9 @@ 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>;
@ -270,7 +270,7 @@ export interface EventStoreNodeConnection {
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;

View File

@ -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,11 +12,19 @@ module.exports.notNull = function(value, name) {
throw new TypeError(name + " should not be null.");
};
module.exports.isInteger = function(value, name) {
module.exports.isInteger = function isInteger(value, name) {
if (typeof value !== 'number' || value % 1 !== 0)
throw new TypeError(name + " should be an integer.");
};
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) {
if (!Array.isArray(value))
throw new TypeError(name + " should be an array.");

View File

@ -9,6 +9,7 @@ var SubscriptionsManager = require('./subscriptionsManager');
var VolatileSubscriptionOperation = require('../clientOperations/volatileSubscriptionOperation');
var ConnectToPersistentSubscriptionOperation = require('../clientOperations/connectToPersistentSubscriptionOperation');
var messages = require('./messages');
var ClientMessage = require('../messages/clientMessage');
var TcpPackage = require('../systemData/tcpPackage');
var TcpCommand = require('../systemData/tcpCommand');
@ -28,12 +29,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 +394,20 @@ 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});
this._connection.enqueueSend(new TcpPackage(TcpCommand.IdentifyClient, this._identityInfo.correlationId, null, null, dto.serialize()))
};
EventStoreConnectionLogicHandler.prototype._goToConnectedState = function() {
this._state = ConnectionState.Connected;
this._connectingPhase = ConnectingPhase.Connected;
@ -498,6 +511,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,8 +640,12 @@ EventStoreConnectionLogicHandler.prototype._timerTick = function() {
else if (this._connectingPhase === ConnectingPhase.Authentication && (Date.now() - this._authInfo.timeStamp) >= this._settings.operationTimeout)
{
this.emit('authenticationFailed', "Authentication timed out.");
if (this._clientVersion === 1) {
this._goToIdentifiedState();
} else {
this._goToConnectedState();
}
}
else if (this._connectingPhase === ConnectingPhase.Authentication || this._connectingPhase === ConnectingPhase.Connected)
this._manageHeartbeats();
break;

View File

@ -100,15 +100,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 +129,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 +159,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 +237,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.");
ensure.isLongOrInteger(eventNumber, "eventNumber");
eventNumber = Long.fromValue(eventNumber);
resolveLinkTos = !!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;
@ -623,7 +625,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 +636,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,7 +680,7 @@ 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);

File diff suppressed because it is too large Load Diff

View File

@ -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 {
}

View File

@ -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) {

View File

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