2016-11-14 07:21:01 +00:00
|
|
|
/// <reference types="node" />
|
|
|
|
/// <reference types="es6-promise" />
|
|
|
|
|
|
|
|
export namespace expectedVersion {
|
|
|
|
const any: number;
|
|
|
|
const noStream: number;
|
|
|
|
const emptyStream: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export namespace positions {
|
|
|
|
const start: Position;
|
|
|
|
const end: Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EventData {
|
2016-11-15 06:33:33 +00:00
|
|
|
readonly eventId: string;
|
|
|
|
readonly type: string;
|
|
|
|
readonly isJson: boolean;
|
|
|
|
readonly data: Buffer;
|
|
|
|
readonly metadata: Buffer;
|
2016-11-14 07:21:01 +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;
|
|
|
|
|
|
|
|
export interface TcpEndPoint {
|
|
|
|
port: number;
|
|
|
|
hostname: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface GossipSeed {
|
|
|
|
new (endPoint: TcpEndPoint, hostHeader: string);
|
|
|
|
readonly endPoint: TcpEndPoint;
|
|
|
|
readonly hostHeader: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Logger {
|
|
|
|
debug(fmt: string, ...args: any[]): void;
|
|
|
|
info(fmt: string, ...args: any[]): void;
|
|
|
|
error(fmt: string, ...args: any[]): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserCredentials {
|
|
|
|
new (username: string, password: string);
|
2016-11-15 06:33:33 +00:00
|
|
|
|
|
|
|
readonly username: string;
|
|
|
|
readonly password: string;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 interface WriteResult {
|
|
|
|
readonly nextExpectedVersion: number;
|
|
|
|
readonly logPosition: Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RecordedEvent {
|
|
|
|
readonly eventStreamId: string;
|
|
|
|
readonly eventId: string;
|
|
|
|
readonly eventNumber: number;
|
|
|
|
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;
|
|
|
|
readonly originalEventNumber: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StreamEventsSlice {
|
|
|
|
readonly status: string; // TODO: enum
|
|
|
|
readonly stream: string;
|
|
|
|
readonly fromEventNumber: number;
|
|
|
|
readonly readDirection: string; // TODO: enum
|
|
|
|
readonly events: ResolvedEvent[];
|
|
|
|
readonly nextEventNumber: number;
|
|
|
|
readonly lastEventNumber: number;
|
|
|
|
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;
|
|
|
|
readonly eventNumber: number;
|
|
|
|
readonly event: ResolvedEvent | null;
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:21:01 +00:00
|
|
|
export interface EventStoreSubscription {
|
|
|
|
readonly isSubscribedToAll: boolean;
|
|
|
|
readonly streamId: string;
|
|
|
|
readonly lastCommitPosition: Position;
|
|
|
|
readonly lastEventNumber: number;
|
|
|
|
|
|
|
|
close(): void;
|
|
|
|
unsubscribe(): void;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:33:33 +00:00
|
|
|
export interface EventStoreCatchUpSubscription {
|
|
|
|
start(): void;
|
|
|
|
stop(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RawStreamMetadataResult {
|
|
|
|
readonly stream: string;
|
|
|
|
readonly isStreamDeleted: boolean;
|
|
|
|
readonly metastreamVersion: number;
|
|
|
|
readonly streamMetadata: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
export interface EventAppearedCallback<TSubscription> {
|
2016-11-21 23:56:04 +00:00
|
|
|
(subscription: TSubscription, event: ResolvedEvent): 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> {
|
|
|
|
(subscription: TSubscription, reason: string, error?: Error);
|
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
|
|
|
|
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>;
|
|
|
|
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>;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
// metadata actions
|
|
|
|
setStreamMetadataRaw(stream: string, expectedMetastreamVersion: number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
|
|
|
|
getStreamMetadataRaw(stream: string, userCredentials?: UserCredentials): Promise<RawStreamMetadataResult>;
|
|
|
|
|
|
|
|
on(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error", listener: (arg: Error | string | TcpEndPoint) => void): this;
|
|
|
|
once(event: "connected" | "disconnected" | "reconnecting" | "closed" | "error", listener: (arg: Error | string | TcpEndPoint) => void): this;
|
2016-11-14 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createConnection(settings: ConnectionSettings, endPointOrGossipSeed: string | TcpEndPoint | GossipSeed[], connectionName?: string): EventStoreNodeConnection;
|