2016-11-14 07:21:01 +00:00
|
|
|
/// <reference types="node" />
|
2017-02-03 02:02:14 +00:00
|
|
|
/// <reference types="Long" />
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export class Position {
|
|
|
|
constructor(commitPosition: number|Long, preparePosition: number|Long);
|
2017-02-03 02:02:14 +00:00
|
|
|
readonly commitPosition: Long;
|
|
|
|
readonly preparePosition: Long;
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// Expose classes
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export class UserCredentials {
|
|
|
|
constructor(username: string, password: string);
|
|
|
|
readonly username: string;
|
|
|
|
readonly password: string;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export class PersistentSubscriptionSettings {
|
2017-10-17 22:55:07 +00:00
|
|
|
constructor(resolveLinkTos: boolean, startFrom: Long|number, extraStatistics: boolean, messageTimeout: number,
|
2017-02-19 07:10:15 +00:00
|
|
|
maxRetryCount: number, liveBufferSize: number, readBatchSize: number, historyBufferSize: number,
|
|
|
|
checkPointAfter: number, minCheckPointCount: number, maxCheckPointCount: number,
|
|
|
|
maxSubscriberCount: number, namedConsumerStrategy: string)
|
2017-04-01 21:56:34 +00:00
|
|
|
static create(): PersistentSubscriptionSettings;
|
2017-02-19 07:10:15 +00:00
|
|
|
}
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export namespace SystemConsumerStrategies {
|
|
|
|
const DispatchToSingle: string;
|
|
|
|
const RoundRobin: string;
|
|
|
|
const Pinned: string
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 17:20:55 +00:00
|
|
|
export class GossipSeed {
|
|
|
|
constructor(endPoint: TcpEndPoint, hostHeader: string);
|
2016-11-14 07:21:01 +00:00
|
|
|
readonly endPoint: TcpEndPoint;
|
|
|
|
readonly hostHeader: string;
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// Expose errors
|
|
|
|
export class WrongExpectedVersionError {
|
|
|
|
readonly name: string;
|
|
|
|
readonly action: string;
|
|
|
|
readonly message: string;
|
|
|
|
readonly stream?: string;
|
2017-10-17 21:31:26 +00:00
|
|
|
readonly expectedVersion?: Long;
|
2017-02-19 07:10:15 +00:00
|
|
|
readonly transactionId?: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export class StreamDeletedError {
|
|
|
|
readonly message: string;
|
|
|
|
readonly stream?: string;
|
|
|
|
readonly transactionId?: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export class AccessDeniedError {
|
|
|
|
readonly name: string;
|
|
|
|
readonly action: string;
|
|
|
|
readonly message: string;
|
|
|
|
readonly stream?: string;
|
|
|
|
readonly transactionId?: Long;
|
|
|
|
}
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// Expose enums/constants
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export namespace expectedVersion {
|
|
|
|
const any: number;
|
|
|
|
const noStream: number;
|
|
|
|
const emptyStream: number;
|
|
|
|
}
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export namespace positions {
|
|
|
|
const start: Position;
|
|
|
|
const end: Position;
|
|
|
|
}
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// systemMetadata
|
|
|
|
// eventReadStatus
|
|
|
|
// sliceReadStatus
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// Expose loggers
|
2016-11-14 07:21:01 +00:00
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export interface Logger {
|
|
|
|
debug(fmt: string, ...args: any[]): void;
|
|
|
|
info(fmt: string, ...args: any[]): void;
|
|
|
|
error(fmt: string, ...args: any[]): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 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;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 20:45:22 +00:00
|
|
|
// Expose results
|
2016-11-14 07:21:01 +00:00
|
|
|
export interface WriteResult {
|
2017-10-17 21:31:26 +00:00
|
|
|
readonly nextExpectedVersion: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
readonly logPosition: Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RecordedEvent {
|
|
|
|
readonly eventStreamId: string;
|
|
|
|
readonly eventId: string;
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly eventNumber: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
readonly eventType: string;
|
|
|
|
readonly createdEpoch: number;
|
|
|
|
readonly data?: Buffer;
|
|
|
|
readonly metadata?: Buffer;
|
|
|
|
readonly isJson: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResolvedEvent {
|
|
|
|
readonly event?: RecordedEvent;
|
|
|
|
readonly link?: RecordedEvent;
|
|
|
|
readonly originalEvent?: RecordedEvent;
|
|
|
|
readonly isResolved: boolean;
|
|
|
|
readonly originalPosition?: Position;
|
|
|
|
readonly originalStreamId: string;
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly originalEventNumber: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface StreamEventsSlice {
|
|
|
|
readonly status: string; // TODO: enum
|
|
|
|
readonly stream: string;
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly fromEventNumber: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
readonly readDirection: string; // TODO: enum
|
|
|
|
readonly events: ResolvedEvent[];
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly nextEventNumber: Long;
|
|
|
|
readonly lastEventNumber: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
readonly isEndOfStream: boolean;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:33:33 +00:00
|
|
|
export interface AllEventsSlice {
|
|
|
|
readonly readDirection: string; // TODO enum
|
|
|
|
readonly fromPosition: Position;
|
|
|
|
readonly nextPosition: Position;
|
|
|
|
readonly events: ResolvedEvent[];
|
|
|
|
readonly isEndOfStream: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DeleteResult {
|
|
|
|
readonly logPosition: Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EventStoreTransaction {
|
|
|
|
readonly transactionId: number;
|
|
|
|
commit(): Promise<WriteResult>;
|
|
|
|
write(eventOrEvents: EventData | EventData[]): Promise<void>;
|
|
|
|
rollback(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EventReadResult {
|
|
|
|
readonly status: string;
|
|
|
|
readonly stream: string;
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly eventNumber: Long;
|
2016-11-15 06:33:33 +00:00
|
|
|
readonly event: ResolvedEvent | null;
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:21:01 +00:00
|
|
|
export interface EventStoreSubscription {
|
|
|
|
readonly isSubscribedToAll: boolean;
|
|
|
|
readonly streamId: string;
|
|
|
|
readonly lastCommitPosition: Position;
|
2017-10-17 22:55:07 +00:00
|
|
|
readonly lastEventNumber: Long;
|
2016-11-14 07:21:01 +00:00
|
|
|
|
|
|
|
close(): void;
|
|
|
|
unsubscribe(): void;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:33:33 +00:00
|
|
|
export interface EventStoreCatchUpSubscription {
|
2017-07-01 01:54:56 +00:00
|
|
|
stop(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum PersistentSubscriptionNakEventAction {
|
|
|
|
Unknown = 0,
|
|
|
|
Park = 1,
|
|
|
|
Retry = 2,
|
|
|
|
Skip = 3,
|
|
|
|
Stop = 4
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EventStorePersistentSubscription {
|
|
|
|
acknowledge(events: ResolvedEvent | ResolvedEvent[]): void;
|
|
|
|
fail(events: ResolvedEvent | ResolvedEvent[], action: PersistentSubscriptionNakEventAction, reason: string): void;
|
2016-11-15 06:33:33 +00:00
|
|
|
stop(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RawStreamMetadataResult {
|
|
|
|
readonly stream: string;
|
|
|
|
readonly isStreamDeleted: boolean;
|
2017-10-17 21:31:26 +00:00
|
|
|
readonly metastreamVersion: Long;
|
2016-11-15 06:33:33 +00:00
|
|
|
readonly streamMetadata: any;
|
|
|
|
}
|
|
|
|
|
2017-07-01 01:54:56 +00:00
|
|
|
export interface PersistentSubscriptionCreateResult {
|
|
|
|
readonly status: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PersistentSubscriptionUpdateResult {
|
|
|
|
readonly status: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PersistentSubscriptionDeleteResult {
|
|
|
|
readonly status: string;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:33:33 +00:00
|
|
|
// Callbacks
|
|
|
|
export interface EventAppearedCallback<TSubscription> {
|
2017-07-17 00:11:54 +00:00
|
|
|
(subscription: TSubscription, event: ResolvedEvent): void | Promise<void>;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:33:33 +00:00
|
|
|
export interface LiveProcessingStartedCallback {
|
|
|
|
(subscription: EventStoreCatchUpSubscription): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SubscriptionDroppedCallback<TSubscription> {
|
2017-01-04 16:58:00 +00:00
|
|
|
(subscription: TSubscription, reason: string, error?: Error): void;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export interface TcpEndPoint {
|
|
|
|
port: number;
|
|
|
|
host: string;
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:55:14 +00:00
|
|
|
export interface HeartbeatInfo {
|
|
|
|
connectionId: string;
|
|
|
|
remoteEndPoint: TcpEndPoint;
|
|
|
|
requestSentAt: number;
|
|
|
|
requestPkgNumber: number;
|
|
|
|
responseReceivedAt: number;
|
|
|
|
responsePkgNumber: number;
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
export interface EventData {
|
|
|
|
readonly eventId: string;
|
|
|
|
readonly type: string;
|
|
|
|
readonly isJson: boolean;
|
|
|
|
readonly data: Buffer;
|
|
|
|
readonly metadata: Buffer;
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:21:01 +00:00
|
|
|
export interface EventStoreNodeConnection {
|
|
|
|
connect(): Promise<void>;
|
|
|
|
close(): void;
|
2016-11-15 06:33:33 +00:00
|
|
|
// write actions
|
2017-10-17 21:31:26 +00:00
|
|
|
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>;
|
2016-11-15 06:33:33 +00:00
|
|
|
continueTransaction(transactionId: number, userCredentials?: UserCredentials): EventStoreTransaction;
|
|
|
|
// read actions
|
2017-10-17 22:55:07 +00:00
|
|
|
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>;
|
2016-11-15 06:33:33 +00:00
|
|
|
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>;
|
2017-11-08 20:45:22 +00:00
|
|
|
subscribeToStreamFrom(stream: string, lastCheckpoint: Long|number|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
2016-11-15 06:33:33 +00:00
|
|
|
subscribeToAll(resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
|
2017-11-08 20:45:22 +00:00
|
|
|
subscribeToAllFrom(lastCheckpoint: Position|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
2017-07-01 01:54:56 +00:00
|
|
|
// 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>;
|
2016-11-15 06:33:33 +00:00
|
|
|
// metadata actions
|
2017-10-17 21:31:26 +00:00
|
|
|
setStreamMetadataRaw(stream: string, expectedMetastreamVersion: Long|number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
|
2016-11-15 06:33:33 +00:00
|
|
|
getStreamMetadataRaw(stream: string, userCredentials?: UserCredentials): Promise<RawStreamMetadataResult>;
|
|
|
|
|
2017-05-15 19:55:14 +00:00
|
|
|
on(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error" | "heartbeatInfo", listener: (arg: Error | string | TcpEndPoint | HeartbeatInfo) => void): this;
|
|
|
|
once(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error" | "heartbeatInfo", listener: (arg: Error | string | TcpEndPoint | HeartbeatInfo) => void): this;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:10:15 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:21:01 +00:00
|
|
|
export function createConnection(settings: ConnectionSettings, endPointOrGossipSeed: string | TcpEndPoint | GossipSeed[], connectionName?: string): EventStoreNodeConnection;
|
2017-02-19 07:10:15 +00:00
|
|
|
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;
|