1 |
|
2 |
|
3 |
|
4 | import { EventEmitter } from "events";
|
5 | import { StrictEventEmitter } from "strict-event-emitter-types";
|
6 |
|
7 |
|
8 | export 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 |
|
16 | export class UserCredentials {
|
17 | constructor(username: string, password: string);
|
18 | readonly username: string;
|
19 | readonly password: string;
|
20 | }
|
21 |
|
22 | export 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 |
|
30 | export namespace SystemConsumerStrategies {
|
31 | const DispatchToSingle: string;
|
32 | const RoundRobin: string;
|
33 | const Pinned: string;
|
34 | }
|
35 |
|
36 | export class GossipSeed {
|
37 | constructor(endPoint: TcpEndPoint, hostHeader: string);
|
38 | readonly endPoint: TcpEndPoint;
|
39 | readonly hostHeader: string;
|
40 | }
|
41 |
|
42 | export 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 |
|
70 | export 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
|
94 | export 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 |
|
103 | export class StreamDeletedError {
|
104 | readonly message: string;
|
105 | readonly stream?: string;
|
106 | readonly transactionId?: Long;
|
107 | }
|
108 |
|
109 | export class AccessDeniedError {
|
110 | readonly name: string;
|
111 | readonly action: string;
|
112 | readonly message: string;
|
113 | readonly stream?: string;
|
114 | readonly transactionId?: Long;
|
115 | }
|
116 |
|
117 | export class ProjectionCommandFailedError {
|
118 | readonly httpStatusCode: number;
|
119 | readonly message: string;
|
120 | }
|
121 |
|
122 |
|
123 | export namespace expectedVersion {
|
124 | const any: number;
|
125 | const noStream: number;
|
126 | const emptyStream: number;
|
127 | }
|
128 |
|
129 | export namespace positions {
|
130 | const start: Position;
|
131 | const end: Position;
|
132 | }
|
133 |
|
134 | export namespace streamPosition {
|
135 | const start: number;
|
136 | const end: number;
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | export 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 |
|
151 | export 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 |
|
158 | export 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
|
166 | export interface WriteResult {
|
167 | readonly nextExpectedVersion: Long;
|
168 | readonly logPosition: Position;
|
169 | }
|
170 |
|
171 | export 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 |
|
182 | export 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 |
|
192 | export interface StreamEventsSlice {
|
193 | readonly status: string;
|
194 | readonly stream: string;
|
195 | readonly fromEventNumber: Long;
|
196 | readonly readDirection: string;
|
197 | readonly events: ResolvedEvent[];
|
198 | readonly nextEventNumber: Long;
|
199 | readonly lastEventNumber: Long;
|
200 | readonly isEndOfStream: boolean;
|
201 | }
|
202 |
|
203 | export interface AllEventsSlice {
|
204 | readonly readDirection: string;
|
205 | readonly fromPosition: Position;
|
206 | readonly nextPosition: Position;
|
207 | readonly events: ResolvedEvent[];
|
208 | readonly isEndOfStream: boolean;
|
209 | }
|
210 |
|
211 | export interface DeleteResult {
|
212 | readonly logPosition: Position;
|
213 | }
|
214 |
|
215 | export interface EventStoreTransaction {
|
216 | readonly transactionId: number;
|
217 | commit(): Promise<WriteResult>;
|
218 | write(eventOrEvents: EventData | EventData[]): Promise<void>;
|
219 | rollback(): void;
|
220 | }
|
221 |
|
222 | export interface EventReadResult {
|
223 | readonly status: string;
|
224 | readonly stream: string;
|
225 | readonly eventNumber: Long;
|
226 | readonly event: ResolvedEvent | null;
|
227 | }
|
228 |
|
229 | export 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 |
|
239 | export interface EventStoreCatchUpSubscription {
|
240 | stop(): void;
|
241 | }
|
242 |
|
243 | export enum PersistentSubscriptionNakEventAction {
|
244 | Unknown = 0,
|
245 | Park = 1,
|
246 | Retry = 2,
|
247 | Skip = 3,
|
248 | Stop = 4
|
249 | }
|
250 |
|
251 | export interface EventStorePersistentSubscription {
|
252 | acknowledge(events: ResolvedEvent | ResolvedEvent[]): void;
|
253 | fail(events: ResolvedEvent | ResolvedEvent[], action: PersistentSubscriptionNakEventAction, reason: string): void;
|
254 | stop(): void;
|
255 | }
|
256 |
|
257 | export interface RawStreamMetadataResult {
|
258 | readonly stream: string;
|
259 | readonly isStreamDeleted: boolean;
|
260 | readonly metastreamVersion: Long;
|
261 | readonly streamMetadata: any;
|
262 | }
|
263 |
|
264 | export interface PersistentSubscriptionCreateResult {
|
265 | readonly status: string;
|
266 | }
|
267 |
|
268 | export interface PersistentSubscriptionUpdateResult {
|
269 | readonly status: string;
|
270 | }
|
271 |
|
272 | export interface PersistentSubscriptionDeleteResult {
|
273 | readonly status: string;
|
274 | }
|
275 |
|
276 |
|
277 | export interface EventAppearedCallback<TSubscription> {
|
278 | (subscription: TSubscription, event: ResolvedEvent): void | Promise<void>;
|
279 | }
|
280 |
|
281 | export interface LiveProcessingStartedCallback {
|
282 | (subscription: EventStoreCatchUpSubscription): void;
|
283 | }
|
284 |
|
285 | export interface SubscriptionDroppedCallback<TSubscription> {
|
286 | (subscription: TSubscription, reason: string, error?: Error): void;
|
287 | }
|
288 |
|
289 | export interface TcpEndPoint {
|
290 | port: number;
|
291 | host: string;
|
292 | }
|
293 |
|
294 | export 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 |
|
303 | export interface EventData {
|
304 | readonly eventId: string;
|
305 | readonly type: string;
|
306 | readonly isJson: boolean;
|
307 | readonly data: Buffer;
|
308 | readonly metadata: Buffer;
|
309 | }
|
310 |
|
311 | interface EventStoreNodeConnectionEvents {
|
312 | connected: TcpEndPoint;
|
313 | disconnected: TcpEndPoint;
|
314 | reconnecting: void;
|
315 | closed:string;
|
316 | error: Error;
|
317 | heartbeatInfo: HeartbeatInfo;
|
318 | }
|
319 |
|
320 | type EventStoreNodeConnectionEventEmitter = StrictEventEmitter<EventEmitter, EventStoreNodeConnectionEvents>;
|
321 |
|
322 | export class EventStoreNodeConnection extends (EventEmitter as { new(): EventStoreNodeConnectionEventEmitter }) {
|
323 | connect(): Promise<void>;
|
324 | close(): void;
|
325 |
|
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 |
|
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 |
|
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 |
|
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 |
|
347 | setStreamMetadataRaw(stream: string, expectedMetastreamVersion: Long|number, metadata: any, userCredentials?: UserCredentials): Promise<WriteResult>;
|
348 | getStreamMetadataRaw(stream: string, userCredentials?: UserCredentials): Promise<RawStreamMetadataResult>;
|
349 | }
|
350 |
|
351 |
|
352 | export 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 |
|
378 | clusterDns?: string,
|
379 | maxDiscoverAttempts?: number,
|
380 | externalGossipPort?: number,
|
381 | gossipTimeout?: number
|
382 | }
|
383 |
|
384 |
|
385 | export function createConnection(settings: ConnectionSettings, endPointOrGossipSeed: string | TcpEndPoint | GossipSeed[], connectionName?: string): EventStoreNodeConnection;
|
386 | export function createJsonEventData(eventId: string, event: any, metadata?: any, type?: string): EventData;
|
387 | export function createEventData(eventId: string, type: string, isJson: boolean, data: Buffer, metadata?: Buffer): EventData;
|