hamok
Version:
Lightweight Distributed Object Storage on RAFT consensus algorithm
76 lines • 3.25 kB
TypeScript
import { EventEmitter } from 'events';
import { HamokConnection } from './HamokConnection';
import { RemoteMap } from './RemoteMap';
import { HamokRemoteMapSnapshot } from '../HamokSnapshot';
export type HamokRemoteMapEventMap<K, V> = {
'insert': [key: K, value: V];
'update': [key: K, oldValue: V, newValue: V];
'remove': [key: K, value: V];
'clear': [];
'close': [];
};
export declare interface HamokRemoteMap<K, V> {
on<U extends keyof HamokRemoteMapEventMap<K, V>>(event: U, listener: (...args: HamokRemoteMapEventMap<K, V>[U]) => void): this;
off<U extends keyof HamokRemoteMapEventMap<K, V>>(event: U, listener: (...args: HamokRemoteMapEventMap<K, V>[U]) => void): this;
once<U extends keyof HamokRemoteMapEventMap<K, V>>(event: U, listener: (...args: HamokRemoteMapEventMap<K, V>[U]) => void): this;
emit<U extends keyof HamokRemoteMapEventMap<K, V>>(event: U, ...args: HamokRemoteMapEventMap<K, V>[U]): boolean;
}
/**
* A remote map is a map that is stored on a remote endpoint and magaged by Hamok instances
*/
export declare class HamokRemoteMap<K, V> extends EventEmitter {
readonly connection: HamokConnection<K, V>;
readonly remoteMap: RemoteMap<K, V>;
private _closed;
equalValues: (a: V, b: V) => boolean;
private readonly _executor;
/**
* Flag indicate if the storage emit events and notify other storage to emit events (if this is the leader)
*/
emitEvents: boolean;
private _initializing?;
/**
* The last commit index that was applied to the map
*/
private _appliedCommitIndex;
/**
* Whether this endpoint is the leader
*/
private _leader;
/**
*
* @param supplier the supplied action has to be executed if this endpoint is the leader
* @param commitIndex the commit index that the action is associated with
* @param onCompleted callback if this endpoint is the leader and the action is executed
* @returns
*/
private _executeIfLeader;
constructor(connection: HamokConnection<K, V>, remoteMap: RemoteMap<K, V>, equalValues?: (a: V, b: V) => boolean);
get id(): string;
get ready(): Promise<this>;
get closed(): boolean;
close(): void;
size(): Promise<number>;
isEmpty(): Promise<boolean>;
keys(): Promise<IterableIterator<K>>;
clear(): Promise<void>;
get(key: K): Promise<V | undefined>;
getAll(keys: IterableIterator<K> | K[]): Promise<ReadonlyMap<K, V>>;
set(key: K, value: V): Promise<V | undefined>;
setAll(entries: ReadonlyMap<K, V>): Promise<ReadonlyMap<K, V>>;
insert(key: K, value: V): Promise<V | undefined>;
insertAll(entries: ReadonlyMap<K, V> | [K, V][]): Promise<ReadonlyMap<K, V>>;
delete(key: K): Promise<boolean>;
deleteAll(keys: ReadonlySet<K> | K[]): Promise<ReadonlySet<K>>;
remove(key: K): Promise<boolean>;
removeAll(keys: ReadonlySet<K> | K[]): Promise<ReadonlyMap<K, V>>;
updateIf(key: K, value: V, oldValue: V): Promise<boolean>;
iterator(): AsyncIterableIterator<[K, V]>;
/**
* Exports the storage data
*/
export(): HamokRemoteMapSnapshot;
import(data: HamokRemoteMapSnapshot): void;
private _import;
}
//# sourceMappingURL=HamokRemoteMap.d.ts.map