import { NormalizedFilter } from "koncorde"; import { JSONObject } from "kuzzle-sdk"; import { RoomList } from "../types"; import Long from "long"; import "../types/Global"; export type SerializedRoomSubscriptions = { nodeId: string; messageId: Long; subscribers: number; }; export type SerializedRoomState = { collection: string; filters: string; index: string; nodes: SerializedRoomSubscriptions[]; roomId: string; }; /** * Class maintaining the complete cluster state */ export default class State { /** * State of realtime rooms. * * Each room state contains the node IDs subscribing to the room. * * Map */ private realtime; /** * State of authentication strategies * * Map */ private strategies; /** * Adds a new realtime room to the state * * @param roomId * @param index * @param collection * @param filters Precomputed Koncorde filters * @param node */ addRealtimeRoom(roomId: string, index: string, collection: string, filters: JSONObject, node: SerializedRoomSubscriptions): void; /** * Retrieves a room in the same format than Koncorde.normalize * * @param roomId */ getNormalizedFilters(roomId: string): NormalizedFilter | null; /** * Removes a room in the full state, for a given node. * * @param roomId * @param nodeId */ removeRealtimeRoom(roomId: string, nodeId: string): void; countRealtimeSubscriptions(roomId: string): number; listRealtimeRooms(): RoomList; addRealtimeSubscription(roomId: string, nodeId: string, messageId: Long): void; removeRealtimeSubscription(roomId: string, nodeId: string, messageId: Long): void; /** * Removes a node from the full state * * @param nodeId */ removeNode(nodeId: string): void; /** * Adds a new dynamic strategy to the full state * */ addAuthStrategy(strategyObject: JSONObject): void; removeAuthStrategy(strategyName: string): void; serialize(): { authStrategies: JSONObject[]; rooms: SerializedRoomState[]; }; /** * Initializes itself from a full state description * * /!\ Modifies Kuzzle's RAM cache: loading a full cache also load data into * Koncorde. This is necessary to allow to detect changes to filters that * could otherwise not be known to this node (e.g. if only 1 subscription * exists and made on another node) * * @param serialized POJO object of a full realtime state */ loadFullState(serialized: SerializedState): void; } export type SerializedState = { authStrategies: JSONObject[]; rooms: SerializedRoomState[]; };