import { Types } from ".."; import { GenericEvent } from "./managers"; export type ThreadCallbackPayload = { [Types.ThreadEventType.THREAD_CREATE]: Types.Thread; [Types.ThreadEventType.THREAD_UPDATE]: Types.Thread; [Types.ThreadEventType.THREAD_DELETE]: { threadId: string; }; [Types.ThreadEventType.THREAD_STATS]: { lastMsgDate: number; messagesCount: number; threadId: string; }; [Types.ThreadEventType.MESSAGE_CREATE]: Types.Message; [Types.ThreadEventType.MESSAGE_UPDATE]: Types.Message; [Types.ThreadEventType.MESSAGE_DELETE]: { threadId: string; messageId: string; }; [Types.ThreadEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData; }; export type StoreCallbackPayload = { [Types.StoreEventType.STORE_CREATE]: Types.Store; [Types.StoreEventType.STORE_UPDATE]: Types.Store; [Types.StoreEventType.STORE_DELETE]: { storeId: string; }; [Types.StoreEventType.STORE_STATS]: { contextId: string; storeId: string; lastFileDate: number; filesCount: number; }; [Types.StoreEventType.FILE_CREATE]: Types.File; [Types.StoreEventType.FILE_UPDATE]: Types.File; [Types.StoreEventType.FILE_DELETE]: { contextId: string; storeId: string; fileId: string; }; [Types.StoreEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData; }; export type InboxCallbackPayload = { [Types.InboxEventType.INBOX_CREATE]: Types.Inbox; [Types.InboxEventType.INBOX_UPDATE]: Types.Inbox; [Types.InboxEventType.INBOX_DELETE]: { inboxId: string; }; [Types.InboxEventType.ENTRY_CREATE]: Types.InboxEntry; [Types.InboxEventType.ENTRY_DELETE]: { contextId: string; inboxId: string; entryId: string; }; [Types.InboxEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData; }; export type KvdbCallbackPayload = { [Types.KvdbEventType.KVDB_STATS]: { lastEntryDate: number; entryCount: number; kvdbId: string; }; [Types.KvdbEventType.KVDB_CREATE]: Types.Kvdb; [Types.KvdbEventType.KVDB_UPDATE]: Types.Kvdb; [Types.KvdbEventType.KVDB_DELETE]: { kvdbId: string; }; [Types.KvdbEventType.ENTRY_UPDATE]: Types.KvdbEntry; [Types.KvdbEventType.ENTRY_CREATE]: Types.KvdbEntry; [Types.KvdbEventType.ENTRY_DELETE]: { contextId: string; kvdbId: string; entryId: string; }; [Types.KvdbEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData; }; export type UserEventCallbackPayload = { [Types.ConnectionEventType.USER_ADD]: Types.ContextUserEventData; [Types.ConnectionEventType.USER_REMOVE]: Types.ContextUserEventData; [Types.ConnectionEventType.USER_STATUS]: Types.ContextUsersStatusChangedEventData; }; export type EventsCallbackPayload = Types.ContextCustomEventData; export type EventCallback = { callback: (e: Types.Event | GenericEvent) => void; symbol: Symbol; }; export interface Subscription { type: T; selector: S; id: string; callbacks: EventCallback[]; } export declare function createThreadSubscription(s: { type: T; selector: S; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): { callbacks: EventCallback[]; type: T; selector: S; id: string; }; export declare function createStoreSubscription(s: { type: T; selector: S; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): { callbacks: EventCallback[]; type: T; selector: S; id: string; }; export declare function createKvdbSubscription(s: { type: T; selector: S; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): { callbacks: EventCallback[]; type: T; selector: S; id: string; }; export declare function createInboxSubscription(s: { type: T; selector: S; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): { callbacks: EventCallback[]; type: T; selector: S; id: string; }; export declare function createEventSubscription(s: { channel: string; selector: Types.EventsEventSelectorType; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): Subscription & { channel: string; }; export declare enum ConnectionStatusEventType { LIB_DISCONNECTED = 0, LIB_PLATFORM_DISCONNECTED = 1, LIB_CONNECTED = 2 } export type ConnectionSubscription = { type: ConnectionStatusEventType; callbacks: EventCallback[]; }; export declare function createConnectionSubscription(s: { type: ConnectionStatusEventType; callbacks: ((arg: GenericEvent) => void)[]; }): ConnectionSubscription; export declare function createUserEventSubscription(s: { type: T; selector: S; id: string; callbacks: ((arg: GenericEvent) => void)[]; }): Subscription; export interface EventSubscriber { /** * Subscribe for events on the given subscription queries. * @param {string[]} subscriptionQueries list of queries */ subscribeFor(subscriptionQueries: string[]): Promise; /** * Unsubscribe from events for the given subscriptionIds. */ unsubscribeFrom(subscriptionIds: string[]): Promise; /** * Generate subscription query string for the requested event scope. * @param {E} eventType type of event which you listen for * @param {S} selectorType scope on which you listen for events * @param {string} selectorId ID of the selector */ buildSubscriptionQuery(eventType: E, selectorType: S, selectorId: string): Promise; } export type SubscriberForThreadsEvents = EventSubscriber; export type SubscriberForStoreEvents = EventSubscriber; export type SubscriberForInboxEvents = EventSubscriber; export type SubscriberForKvdbEvents = EventSubscriber; export type SubscriberForUserEvents = EventSubscriber; export type SubscriberForEvents = EventSubscriber;