UNPKG

15.2 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="Long" />
3
4import { EventEmitter } from "events";
5import { StrictEventEmitter } from "strict-event-emitter-types";
6
7// Expose classes
8export class Position {
9 constructor(commitPosition: number|Long, preparePosition: number|Long);
10 readonly commitPosition: Long;
11 readonly preparePosition: Long;
12 static readonly start: number;
13 static readonly end: number;
14}
15
16export class UserCredentials {
17 constructor(username: string, password: string);
18 readonly username: string;
19 readonly password: string;
20}
21
22export class PersistentSubscriptionSettings {
23 constructor(resolveLinkTos: boolean, startFrom: Long|number, extraStatistics: boolean, messageTimeout: number,
24 maxRetryCount: number, liveBufferSize: number, readBatchSize: number, historyBufferSize: number,
25 checkPointAfter: number, minCheckPointCount: number, maxCheckPointCount: number,
26 maxSubscriberCount: number, namedConsumerStrategy: string)
27 static create(): PersistentSubscriptionSettings;
28}
29
30export namespace SystemConsumerStrategies {
31 const DispatchToSingle: string;
32 const RoundRobin: string;
33 const Pinned: string;
34}
35
36export class GossipSeed {
37 constructor(endPoint: TcpEndPoint, hostHeader: string);
38 readonly endPoint: TcpEndPoint;
39 readonly hostHeader: string;
40}
41
42export interface ProjectionDetails {
43 readonly coreProcessingTime: number,
44 readonly version: number,
45 readonly epoch: number,
46 readonly effectiveName: string,
47 readonly writesInProgress: number,
48 readonly readsInProgress: number,
49 readonly partitionsCached: number,
50 readonly status: string,
51 readonly stateReason: string,
52 readonly name: string,
53 readonly mode: string,
54 readonly position: string,
55 readonly progress: number,
56 readonly lastCheckpoint: string,
57 readonly eventsProcessedAfterRestart: number,
58 readonly statusUrl: string,
59 readonly stateUrl: string,
60 readonly resultUrl: string,
61 readonly queryUrl: string,
62 readonly enableCommandUrl: string,
63 readonly disableCommandUrl: string,
64 readonly checkpointStatus: string,
65 readonly bufferedEvents: number,
66 readonly writePendingEventsBeforeCheckpoint: number,
67 readonly writePendingEventsAfterCheckpoint: number
68}
69
70export class ProjectionsManager {
71 constructor(log: Logger, httpEndPoint: string, operationTimeout: number);
72 enable(name: string, userCredentials: UserCredentials): Promise<void>;
73 disable(name: string, userCredentials: UserCredentials): Promise<void>;
74 abort(name: string, userCredentials: UserCredentials): Promise<void>;
75 createOneTime(query: string, userCredentials: UserCredentials): Promise<void>;
76 createTransient(name: string, query: string, userCredentials: UserCredentials): Promise<void>;
77 createContinuous(name: string, query: string, trackEmittedStreams: boolean, userCredentials: UserCredentials): Promise<void>;
78 listAll(userCredentials: UserCredentials): Promise<ProjectionDetails[]>;
79 listOneTime(userCredentials: UserCredentials): Promise<ProjectionDetails[]>;
80 listContinuous(userCredentials: UserCredentials): Promise<ProjectionDetails[]>;
81 getStatus(name: string, userCredentials: UserCredentials): Promise<string>;
82 getState(name: string, userCredentials: UserCredentials): Promise<string>;
83 getPartitionState(name: string, partitionId: string, userCredentials: UserCredentials): Promise<string>;
84 getResult(name: string, userCredentials: UserCredentials): Promise<string>;
85 getPartitionResult(name: string, partitionId: string, userCredentials: UserCredentials): Promise<string>;
86 getStatistics(name: string, userCredentials: UserCredentials): Promise<string>;
87 getQuery(name: string, userCredentials: UserCredentials): Promise<string>;
88 getState(name: string, userCredentials: UserCredentials): Promise<string>;
89 updateQuery(name: string, query: string, userCredentials: UserCredentials): Promise<void>;
90 deleteQuery(name: string, deleteEmittedStreams: boolean, userCredentials: UserCredentials): Promise<void>;
91}
92
93// Expose errors
94export class WrongExpectedVersionError {
95 readonly name: string;
96 readonly action: string;
97 readonly message: string;
98 readonly stream?: string;
99 readonly expectedVersion?: Long;
100 readonly transactionId?: Long;
101}
102
103export class StreamDeletedError {
104 readonly message: string;
105 readonly stream?: string;
106 readonly transactionId?: Long;
107}
108
109export class AccessDeniedError {
110 readonly name: string;
111 readonly action: string;
112 readonly message: string;
113 readonly stream?: string;
114 readonly transactionId?: Long;
115}
116
117export class ProjectionCommandFailedError {
118 readonly httpStatusCode: number;
119 readonly message: string;
120}
121
122// Expose enums/constants
123export namespace expectedVersion {
124 const any: number;
125 const noStream: number;
126 const emptyStream: number;
127}
128
129export namespace positions {
130 const start: Position;
131 const end: Position;
132}
133
134export namespace streamPosition {
135 const start: number;
136 const end: number;
137}
138
139//TODO
140// systemMetadata
141// eventReadStatus
142// sliceReadStatus
143
144// Expose loggers
145export interface Logger {
146 debug(fmt: string, ...args: any[]): void;
147 info(fmt: string, ...args: any[]): void;
148 error(fmt: string, ...args: any[]): void;
149}
150
151export class NoopLogger implements Logger {
152 constructor()
153 debug(fmt: string, ...args: any[]): void;
154 info(fmt: string, ...args: any[]): void;
155 error(fmt: string, ...args: any[]): void;
156}
157
158export class FileLogger implements Logger {
159 constructor(filePath: string, append: boolean);
160 debug(fmt: string, ...args: any[]): void;
161 info(fmt: string, ...args: any[]): void;
162 error(fmt: string, ...args: any[]): void;
163}
164
165// Expose results
166export interface WriteResult {
167 readonly nextExpectedVersion: Long;
168 readonly logPosition: Position;
169}
170
171export interface RecordedEvent {
172 readonly eventStreamId: string;
173 readonly eventId: string;
174 readonly eventNumber: Long;
175 readonly eventType: string;
176 readonly createdEpoch: number;
177 readonly data?: Buffer;
178 readonly metadata?: Buffer;
179 readonly isJson: boolean;
180}
181
182export interface ResolvedEvent {
183 readonly event?: RecordedEvent;
184 readonly link?: RecordedEvent;
185 readonly originalEvent?: RecordedEvent;
186 readonly isResolved: boolean;
187 readonly originalPosition?: Position;
188 readonly originalStreamId: string;
189 readonly originalEventNumber: Long;
190}
191
192export interface StreamEventsSlice {
193 readonly status: string; // TODO: enum
194 readonly stream: string;
195 readonly fromEventNumber: Long;
196 readonly readDirection: string; // TODO: enum
197 readonly events: ResolvedEvent[];
198 readonly nextEventNumber: Long;
199 readonly lastEventNumber: Long;
200 readonly isEndOfStream: boolean;
201}
202
203export interface AllEventsSlice {
204 readonly readDirection: string; // TODO enum
205 readonly fromPosition: Position;
206 readonly nextPosition: Position;
207 readonly events: ResolvedEvent[];
208 readonly isEndOfStream: boolean;
209}
210
211export interface DeleteResult {
212 readonly logPosition: Position;
213}
214
215export interface EventStoreTransaction {
216 readonly transactionId: number;
217 commit(): Promise<WriteResult>;
218 write(eventOrEvents: EventData | EventData[]): Promise<void>;
219 rollback(): void;
220}
221
222export interface EventReadResult {
223 readonly status: string;
224 readonly stream: string;
225 readonly eventNumber: Long;
226 readonly event: ResolvedEvent | null;
227}
228
229export interface EventStoreSubscription {
230 readonly isSubscribedToAll: boolean;
231 readonly streamId: string;
232 readonly lastCommitPosition: Position;
233 readonly lastEventNumber: Long;
234
235 close(): void;
236 unsubscribe(): void;
237}
238
239export interface EventStoreCatchUpSubscription {
240 stop(): void;
241}
242
243export enum PersistentSubscriptionNakEventAction {
244 Unknown = 0,
245 Park = 1,
246 Retry = 2,
247 Skip = 3,
248 Stop = 4
249}
250
251export interface EventStorePersistentSubscription {
252 acknowledge(events: ResolvedEvent | ResolvedEvent[]): void;
253 fail(events: ResolvedEvent | ResolvedEvent[], action: PersistentSubscriptionNakEventAction, reason: string): void;
254 stop(): void;
255}
256
257export interface RawStreamMetadataResult {
258 readonly stream: string;
259 readonly isStreamDeleted: boolean;
260 readonly metastreamVersion: Long;
261 readonly streamMetadata: any;
262}
263
264export interface PersistentSubscriptionCreateResult {
265 readonly status: string;
266}
267
268export interface PersistentSubscriptionUpdateResult {
269 readonly status: string;
270}
271
272export interface PersistentSubscriptionDeleteResult {
273 readonly status: string;
274}
275
276// Callbacks
277export interface EventAppearedCallback<TSubscription> {
278 (subscription: TSubscription, event: ResolvedEvent): void | Promise<void>;
279}
280
281export interface LiveProcessingStartedCallback {
282 (subscription: EventStoreCatchUpSubscription): void;
283}
284
285export interface SubscriptionDroppedCallback<TSubscription> {
286 (subscription: TSubscription, reason: string, error?: Error): void;
287}
288
289export interface TcpEndPoint {
290 port: number;
291 host: string;
292}
293
294export interface HeartbeatInfo {
295 readonly connectionId: string;
296 readonly remoteEndPoint: TcpEndPoint;
297 readonly requestSentAt: number;
298 readonly requestPkgNumber: number;
299 readonly responseReceivedAt: number;
300 readonly responsePkgNumber: number;
301}
302
303export interface EventData {
304 readonly eventId: string;
305 readonly type: string;
306 readonly isJson: boolean;
307 readonly data: Buffer;
308 readonly metadata: Buffer;
309}
310
311interface EventStoreNodeConnectionEvents {
312 connected: TcpEndPoint;
313 disconnected: TcpEndPoint;
314 reconnecting: void;
315 closed:string;
316 error: Error;
317 heartbeatInfo: HeartbeatInfo;
318}
319
320type EventStoreNodeConnectionEventEmitter = StrictEventEmitter<EventEmitter, EventStoreNodeConnectionEvents>;
321
322export class EventStoreNodeConnection extends (EventEmitter as { new(): EventStoreNodeConnectionEventEmitter }) {
323 connect(): Promise<void>;
324 close(): void;
325 // write actions
326 deleteStream(stream: string, expectedVersion: Long|number, hardDelete?: boolean, userCredentials?: UserCredentials): Promise<DeleteResult>;
327 appendToStream(stream: string, expectedVersion: Long|number, eventOrEvents: EventData | EventData[], userCredentials?: UserCredentials): Promise<WriteResult>;
328 startTransaction(stream: string, expectedVersion: Long|number, userCredentials?: UserCredentials): Promise<EventStoreTransaction>;
329 continueTransaction(transactionId: number, userCredentials?: UserCredentials): EventStoreTransaction;
330 // read actions
331 readEvent(stream: string, eventNumber: Long|number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<EventReadResult>;
332 readStreamEventsForward(stream: string, start: Long|number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
333 readStreamEventsBackward(stream: string, start: Long|number, count: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<StreamEventsSlice>;
334 readAllEventsForward(position: Position, maxCount: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<AllEventsSlice>;
335 readAllEventsBackward(position: Position, maxCount: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<AllEventsSlice>;
336 // subscription actions
337 subscribeToStream(stream: string, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
338 subscribeToStreamFrom(stream: string, lastCheckpoint: Long|number|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
339 subscribeToAll(resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
340 subscribeToAllFrom(lastCheckpoint: Position|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
341 // persistent subscriptions
342 createPersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: UserCredentials): Promise<PersistentSubscriptionCreateResult>;
343 updatePersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: UserCredentials): Promise<PersistentSubscriptionUpdateResult>;
344 deletePersistentSubscription(stream: string, groupName: string, userCredentials?: UserCredentials): Promise<PersistentSubscriptionDeleteResult>
345 connectToPersistentSubscription(stream: string, groupName: string, eventAppeared: EventAppearedCallback<EventStorePersistentSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStorePersistentSubscription>, userCredentials?: UserCredentials, bufferSize?: number, autoAck?: boolean): Promise<EventStorePersistentSubscription>;
346 // metadata actions
347 setStreamMetadataRaw(stream: string, expectedMetastreamVersion: Long|number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
348 getStreamMetadataRaw(stream: string, userCredentials?: UserCredentials): Promise<RawStreamMetadataResult>;
349}
350
351// Expose helper functions
352export interface ConnectionSettings {
353 log?: Logger,
354 verboseLogging?: boolean,
355
356 maxQueueSize?: number,
357 maxConcurrentItems?: number,
358 maxRetries?: number,
359 maxReconnections?: number,
360
361 requireMaster?: boolean,
362
363 reconnectionDelay?: number,
364 operationTimeout?: number,
365 operationTimeoutCheckPeriod?: number,
366
367 defaultUserCredentials?: UserCredentials,
368 useSslConnection?: boolean,
369 targetHost?: TcpEndPoint,
370 validateServer?: boolean,
371
372 failOnNoServerResponse?: boolean,
373 heartbeatInterval?: number,
374 heartbeatTimeout?: number,
375 clientConnectionTimeout?: number,
376
377 // Cluster Settings
378 clusterDns?: string,
379 maxDiscoverAttempts?: number,
380 externalGossipPort?: number,
381 gossipTimeout?: number
382}
383
384// Expose Helper functions
385export function createConnection(settings: ConnectionSettings, endPointOrGossipSeed: string | TcpEndPoint | GossipSeed[], connectionName?: string): EventStoreNodeConnection;
386export function createJsonEventData(eventId: string, event: any, metadata?: any, type?: string): EventData;
387export function createEventData(eventId: string, type: string, isJson: boolean, data: Buffer, metadata?: Buffer): EventData;