generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 96
/
subscriptions.ts
34 lines (29 loc) · 1.12 KB
/
subscriptions.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
import type { GenericMessageReply } from '../types/message-types.js';
import type { KeyValues } from './query-types.js';
import type { RecordsWriteMessage } from './records-types.js';
import type { GenericMessage, MessageSubscription } from './message-types.js';
export type EventListener = (tenant: string, event: MessageEvent, indexes: KeyValues) => void;
/**
* MessageEvent contains the message being emitted and an optional initial write message.
*/
export type MessageEvent = {
message: GenericMessage;
/** the initial write of the RecordsWrite or RecordsDelete message */
initialWrite?: RecordsWriteMessage
};
/**
* The EventStream interface implements a pub/sub system based on Message filters.
*/
export interface EventStream {
subscribe(tenant: string, id: string, listener: EventListener): Promise<EventSubscription>;
emit(tenant: string, event: MessageEvent, indexes: KeyValues): void;
open(): Promise<void>;
close(): Promise<void>;
}
export interface EventSubscription {
id: string;
close: () => Promise<void>;
}
export type SubscriptionReply = GenericMessageReply & {
subscription?: MessageSubscription;
};