UNPKG

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