import type { DB, DBTransaction, LevelPath } from '@matrixai/db'; import type { NotificationId, Notification, NotificationData } from './types.js'; import type ACL from '../acl/ACL.js'; import type KeyRing from '../keys/KeyRing.js'; import type NodeManager from '../nodes/NodeManager.js'; import type { NodeId, TaskHandlerId } from '../ids/types.js'; import type { TaskHandler, TaskInfo } from '../tasks/types.js'; import type { TaskManager } from '../tasks/index.js'; import type { AgentClientManifest } from '../nodes/agent/callers/index.js'; import Logger from '@matrixai/logger'; import { createDestroyStartStop } from '@matrixai/async-init'; /** * Manage Node Notifications between Gestalts */ interface NotificationsManager extends createDestroyStartStop.CreateDestroyStartStop { } declare class NotificationsManager { static createNotificationsManager({ acl, db, nodeManager, taskManager, keyRing, sendNotificationRetries, sendNotificationRetryIntervalTimeMin, sendNotificationRetryIntervalTimeMax, messageCap, logger, fresh, }: { acl: ACL; db: DB; nodeManager: NodeManager; taskManager: TaskManager; keyRing: KeyRing; messageCap?: number; sendNotificationRetries?: number; sendNotificationRetryIntervalTimeMin?: number; sendNotificationRetryIntervalTimeMax?: number; logger?: Logger; fresh?: boolean; }): Promise; protected logger: Logger; protected acl: ACL; protected db: DB; protected keyRing: KeyRing; protected nodeManager: NodeManager; protected taskManager: TaskManager; protected messageCap: number; protected sendNotificationRetries: number; protected sendNotificationRetryIntervalTimeMin: number; protected sendNotificationRetryIntervalTimeMax: number; protected notificationsManagerDbPath: LevelPath; /** * Inbox Notifications * `NotificationsManager/inbox/{NotificationId} -> {NotificationDB}` */ protected notificationsManagerInboxDbPath: LevelPath; /** * Outbox Notifications * `NotificationsManager/outbox/{NotificationId} -> {NotificationDB}` */ protected notificationsManagerOutboxDbPath: LevelPath; protected inboxNotificationIdGenerator: () => NotificationId; protected outboxNotificationIdGenerator: () => NotificationId; protected sendNotificationHandler: TaskHandler; readonly sendNotificationHandlerId: TaskHandlerId; constructor({ acl, db, nodeManager, taskManager, keyRing, messageCap, sendNotificationRetries, sendNotificationRetryIntervalTimeMin, sendNotificationRetryIntervalTimeMax, logger, }: { acl: ACL; db: DB; nodeManager: NodeManager; taskManager: TaskManager; keyRing: KeyRing; messageCap: number; sendNotificationRetries: number; sendNotificationRetryIntervalTimeMin: number; sendNotificationRetryIntervalTimeMax: number; logger: Logger; }); start({ fresh, }?: { fresh?: boolean; }): Promise; stop(): Promise; destroy(): Promise; /** * Send a notification to another node * The `data` parameter must match one of the NotificationData types outlined in ./types */ sendNotification({ nodeId, data, retries, retryIntervalTimeMin, retryIntervalTimeMax, }: { nodeId: NodeId; data: NotificationData; retries?: number; retryIntervalTimeMin?: number; retryIntervalTimeMax?: number; }, tran?: DBTransaction): Promise<{ /** * The ID of the notification that was sent. */ notificationId: NotificationId; /** * A promise that resolves when the notification is successfully sent, * and rejects when the peer responds with an error or if the notification was never successfully sent */ sendP: Promise; }>; protected getOutboxNotificationIds({ seek, seekEnd, order, limit, tran, }: { seek?: NotificationId | number | Date; seekEnd?: NotificationId | number | Date; order?: 'asc' | 'desc'; limit?: number; tran: DBTransaction; }): AsyncGenerator; protected readOutboxNotificationById(notificationId: NotificationId, tran: DBTransaction): Promise; /** * Read pending notifications in the outbox. */ readOutboxNotifications({ seek, seekEnd, limit, order, tran, }?: { seek?: NotificationId | number | Date; seekEnd?: NotificationId | number | Date; order?: 'asc' | 'desc'; limit?: number; tran?: DBTransaction; }): AsyncGenerator; getOutboxNotificationTaskInfoById(notificationId: NotificationId, tran?: DBTransaction): Promise; /** * Clears the pending outbox notifications */ clearOutboxNotifications(tran?: DBTransaction): Promise; removeOutboxNotification(notificationId: NotificationId, tran?: DBTransaction): Promise; /** * Receive a notification */ receiveNotification(notification: Notification, tran?: DBTransaction): Promise; /** * Read a notification */ readInboxNotifications({ seek, seekEnd, unread, order, limit, tran, }?: { seek?: NotificationId | number | Date; seekEnd?: NotificationId | number | Date; unread?: boolean; order?: 'asc' | 'desc'; limit?: number; tran?: DBTransaction; }): AsyncGenerator; /** * Linearly searches for a GestaltInvite notification from the supplied NodeId. * Returns the notification if found. */ findGestaltInvite(fromNode: NodeId, tran?: DBTransaction): Promise; /** * Removes all notifications */ clearInboxNotifications(tran?: DBTransaction): Promise; protected readInboxNotificationById(notificationId: NotificationId, tran: DBTransaction): Promise; protected getInboxNotificationIds({ seek, seekEnd, unread, order, limit, tran, }: { seek?: NotificationId | number | Date; seekEnd?: NotificationId | number | Date; unread?: boolean; order?: 'asc' | 'desc'; limit?: number; tran: DBTransaction; }): AsyncGenerator; protected getInboxNotifications(type: 'unread' | 'all', tran: DBTransaction): Promise>; removeInboxNotification(messageId: NotificationId, tran?: DBTransaction): Promise; } export default NotificationsManager;