Expose Position, publish version 0.0.27

This commit is contained in:
Nicolas Dextraze 2017-02-18 23:10:15 -08:00
parent 212dd10ce2
commit 34e928c440
4 changed files with 136 additions and 67 deletions

179
index.d.ts vendored
View File

@ -1,37 +1,32 @@
/// <reference types="node" />
/// <reference types="Long" />
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<TSubscription> {
(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<void>;
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;

View File

@ -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",

View File

@ -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;
module.exports.createConnection = require('./eventStoreConnection').create;
module.exports.createJsonEventData = createJsonEventData;
module.exports.createEventData = createEventData;

View File

@ -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);
};
module.exports = PersistentSubscriptionSettings;