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