diff --git a/index.d.ts b/index.d.ts
index 3d6551a..b8ce70d 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,37 +1,32 @@
///
///
-export namespace expectedVersion {
- const any: number;
- const noStream: number;
- const emptyStream: number;
-}
-
-export interface Position {
+export class Position {
+ constructor(commitPosition: number|Long, preparePosition: number|Long);
readonly commitPosition: Long;
readonly preparePosition: Long;
}
-export namespace positions {
- const start: Position;
- const end: Position;
+// Expose classes
+
+export class UserCredentials {
+ constructor(username: string, password: string);
+ readonly username: string;
+ readonly password: string;
}
-export interface EventData {
- readonly eventId: string;
- readonly type: string;
- readonly isJson: boolean;
- readonly data: Buffer;
- readonly metadata: Buffer;
+export class PersistentSubscriptionSettings {
+ constructor(resolveLinkTos: boolean, startFrom: number, extraStatistics: boolean, messageTimeout: number,
+ maxRetryCount: number, liveBufferSize: number, readBatchSize: number, historyBufferSize: number,
+ checkPointAfter: number, minCheckPointCount: number, maxCheckPointCount: number,
+ maxSubscriberCount: number, namedConsumerStrategy: string)
+ static create();
}
-export function createJsonEventData(eventId: string, event: any, metadata?: any, type?: string): EventData;
-
-export function createEventData(eventId: string, type: string, isJson: boolean, data: Buffer, metadata?: Buffer): EventData;
-
-export interface TcpEndPoint {
- port: number;
- host: string;
+export namespace SystemConsumerStrategies {
+ const DispatchToSingle: string;
+ const RoundRobin: string;
+ const Pinned: string
}
export class GossipSeed {
@@ -40,50 +35,71 @@ export class GossipSeed {
readonly hostHeader: string;
}
+// Expose errors
+export class WrongExpectedVersionError {
+ readonly name: string;
+ readonly action: string;
+ readonly message: string;
+ readonly stream?: string;
+ readonly expectedVersion?: number;
+ readonly transactionId?: Long;
+}
+
+export class StreamDeletedError {
+ readonly message: string;
+ readonly stream?: string;
+ readonly transactionId?: Long;
+}
+
+export class AccessDeniedError {
+ readonly name: string;
+ readonly action: string;
+ readonly message: string;
+ readonly stream?: string;
+ readonly transactionId?: Long;
+}
+
+// Expose enums/constants
+
+export namespace expectedVersion {
+ const any: number;
+ const noStream: number;
+ const emptyStream: number;
+}
+
+export namespace positions {
+ const start: Position;
+ const end: Position;
+}
+
+// systemMetadata
+// eventReadStatus
+// sliceReadStatus
+
+// Expose loggers
+
export interface Logger {
debug(fmt: string, ...args: any[]): void;
info(fmt: string, ...args: any[]): void;
error(fmt: string, ...args: any[]): void;
}
-export class UserCredentials {
- constructor(username: string, password: string);
- readonly username: string;
- readonly password: string;
+export class NoOpLogger implements Logger {
+ constructor()
+ debug(fmt: string, ...args: any[]): void;
+ info(fmt: string, ...args: any[]): void;
+ error(fmt: string, ...args: any[]): void;
}
-export interface ConnectionSettings {
- log?: Logger,
- verboseLogging?: boolean,
-
- maxQueueSize?: number,
- maxConcurrentItems?: number,
- maxRetries?: number,
- maxReconnections?: number,
-
- requireMaster?: boolean,
-
- reconnectionDelay?: number,
- operationTimeout?: number,
- operationTimeoutCheckPeriod?: number,
-
- defaultUserCredentials?: UserCredentials,
- useSslConnection?: boolean,
- targetHost?: TcpEndPoint,
- validateServer?: boolean,
-
- failOnNoServerResponse?: boolean,
- heartbeatInterval?: number,
- heartbeatTimeout?: number,
- clientConnectionTimeout?: number,
-
- // Cluster Settings
- clusterDns?: string,
- maxDiscoverAttempts?: number,
- externalGossipPort?: number,
- gossipTimeout?: number
+export class FileLogger implements Logger {
+ constructor(filePath: string, append: boolean);
+ debug(fmt: string, ...args: any[]): void;
+ info(fmt: string, ...args: any[]): void;
+ error(fmt: string, ...args: any[]): void;
}
+//
+
export interface WriteResult {
readonly nextExpectedVersion: number;
readonly logPosition: Position;
@@ -182,6 +198,19 @@ export interface SubscriptionDroppedCallback {
(subscription: TSubscription, reason: string, error?: Error): void;
}
+export interface TcpEndPoint {
+ port: number;
+ host: string;
+}
+
+export interface EventData {
+ readonly eventId: string;
+ readonly type: string;
+ readonly isJson: boolean;
+ readonly data: Buffer;
+ readonly metadata: Buffer;
+}
+
export interface EventStoreNodeConnection {
connect(): Promise;
close(): void;
@@ -209,4 +238,40 @@ export interface EventStoreNodeConnection {
once(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error", listener: (arg: Error | string | TcpEndPoint) => void): this;
}
+// Expose helper functions
+
+export interface ConnectionSettings {
+ log?: Logger,
+ verboseLogging?: boolean,
+
+ maxQueueSize?: number,
+ maxConcurrentItems?: number,
+ maxRetries?: number,
+ maxReconnections?: number,
+
+ requireMaster?: boolean,
+
+ reconnectionDelay?: number,
+ operationTimeout?: number,
+ operationTimeoutCheckPeriod?: number,
+
+ defaultUserCredentials?: UserCredentials,
+ useSslConnection?: boolean,
+ targetHost?: TcpEndPoint,
+ validateServer?: boolean,
+
+ failOnNoServerResponse?: boolean,
+ heartbeatInterval?: number,
+ heartbeatTimeout?: number,
+ clientConnectionTimeout?: number,
+
+ // Cluster Settings
+ clusterDns?: string,
+ maxDiscoverAttempts?: number,
+ externalGossipPort?: number,
+ gossipTimeout?: number
+}
+
export function createConnection(settings: ConnectionSettings, endPointOrGossipSeed: string | TcpEndPoint | GossipSeed[], connectionName?: string): EventStoreNodeConnection;
+export function createJsonEventData(eventId: string, event: any, metadata?: any, type?: string): EventData;
+export function createEventData(eventId: string, type: string, isJson: boolean, data: Buffer, metadata?: Buffer): EventData;
diff --git a/package.json b/package.json
index de4e89a..bcc299a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "eventstore-node",
- "version": "0.0.26",
+ "version": "0.0.27",
"description": "A port of the EventStore .Net ClientAPI to Node.js",
"main": "index.js",
"types": "index.d.ts",
diff --git a/src/client.js b/src/client.js
index 90382aa..d78825c 100644
--- a/src/client.js
+++ b/src/client.js
@@ -20,13 +20,13 @@ const positions = {
* @param {string} [type] Event type
* @returns {EventData}
*/
-module.exports.createJsonEventData = function (eventId, event, metadata, type) {
+function createJsonEventData(eventId, event, metadata, type) {
if (!event || typeof event !== 'object') throw new TypeError("data must be an object.");
var eventBuf = new Buffer(JSON.stringify(event));
var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null;
return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf);
-};
+}
/**
* Create an EventData object from event/metadata buffer(s)
@@ -38,17 +38,17 @@ module.exports.createJsonEventData = function (eventId, event, metadata, type) {
* @param {Buffer} [metadata] Metadata buffer
* @returns {EventData}
*/
-module.exports.createEventData = function (eventId, type, isJson, data, metadata) {
+function createEventData(eventId, type, isJson, data, metadata) {
return new EventData(eventId, type, isJson, data, metadata);
-};
+}
// Expose classes
-module.exports.EventStoreConnection = require('./eventStoreConnection');
+module.exports.Position = results.Position;
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');
+module.exports.EventStoreConnection = require('./eventStoreConnection');
// Expose errors
module.exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError');
module.exports.StreamDeletedError = require('./errors/streamDeletedError');
@@ -63,4 +63,6 @@ module.exports.sliceReadStatus = require('./sliceReadStatus');
module.exports.NoopLogger = require('./common/log/noopLogger');
module.exports.FileLogger = require('./common/log/fileLogger');
// Expose Helper functions
-module.exports.createConnection = module.exports.EventStoreConnection.create;
\ No newline at end of file
+module.exports.createConnection = require('./eventStoreConnection').create;
+module.exports.createJsonEventData = createJsonEventData;
+module.exports.createEventData = createEventData;
diff --git a/src/persistentSubscriptionSettings.js b/src/persistentSubscriptionSettings.js
index 9ab5185..fe3623f 100644
--- a/src/persistentSubscriptionSettings.js
+++ b/src/persistentSubscriptionSettings.js
@@ -21,6 +21,8 @@ function PersistentSubscriptionSettings(
this.namedConsumerStrategy = namedConsumerStrategy;
}
-module.exports.create = function() {
+PersistentSubscriptionSettings.create = function() {
return new PersistentSubscriptionSettings(false, -1, false, 30000, 500, 500, 10, 20, 2000, 10, 1000, 0, SystemConsumerStrategies.RoundRobin);
-};
\ No newline at end of file
+};
+
+module.exports = PersistentSubscriptionSettings;
\ No newline at end of file