@signalapp/mock-server
Version:
Mock Signal Server for writing tests
68 lines (67 loc) • 3.21 kB
TypeScript
/// <reference types="node" />
import { signalservice as Proto } from '../../protos/compiled';
import { ServiceIdKind } from '../types';
import { Group } from './group';
import { PrimaryDevice } from './primary-device';
export type StorageStateRecord = Readonly<{
type: Proto.ManifestRecord.Identifier.Type;
key: Buffer;
record: Proto.IStorageRecord;
}>;
export type StorageStateNewRecord = Readonly<{
type: Proto.ManifestRecord.Identifier.Type;
key?: Buffer;
record: Proto.IStorageRecord;
}>;
export type DiffResult = Readonly<{
added: ReadonlyArray<Proto.IStorageRecord>;
removed: ReadonlyArray<Proto.IStorageRecord>;
}>;
export type ToStorageItemOptions = Readonly<{
storageKey: Buffer;
recordIkm: Buffer | undefined;
}>;
export type CreateWriteOperationOptions = Readonly<{
storageKey: Buffer;
recordIkm: Buffer | undefined;
previous?: StorageState;
}>;
export declare class StorageState {
readonly version: number;
private readonly items;
constructor(version: number, items: ReadonlyArray<StorageStateRecord>);
static getEmpty(): StorageState;
getAccountRecord(): Proto.IAccountRecord | undefined;
updateAccount(diff: Proto.IAccountRecord): StorageState;
getGroup(group: Group): Proto.IGroupV2Record | undefined;
addGroup(group: Group, diff?: Proto.IGroupV2Record): StorageState;
updateGroup(group: Group, diff: Proto.IGroupV2Record): StorageState;
pinGroup(group: Group): StorageState;
unpinGroup(group: Group): StorageState;
isGroupPinned(group: Group): boolean;
addContact({ device }: PrimaryDevice, diff?: Proto.IContactRecord, serviceIdKind?: ServiceIdKind): StorageState;
updateContact({ device }: PrimaryDevice, diff: Proto.IContactRecord, serviceIdKind?: ServiceIdKind): StorageState;
getContact({ device }: PrimaryDevice, serviceIdKind?: ServiceIdKind): Proto.IContactRecord | undefined;
removeContact({ device }: PrimaryDevice, serviceIdKind?: ServiceIdKind): StorageState;
mergeContact(primary: PrimaryDevice, diff: Proto.IContactRecord): StorageState;
pin(primary: PrimaryDevice, serviceIdKind?: ServiceIdKind): StorageState;
unpin(primary: PrimaryDevice, serviceIdKind?: ServiceIdKind): StorageState;
isPinned({ device }: PrimaryDevice): boolean;
addRecord(newRecord: StorageStateNewRecord): StorageState;
findRecord(find: (record: StorageStateRecord) => boolean): StorageStateRecord | undefined;
hasRecord(find: (record: StorageStateRecord) => boolean): boolean;
updateRecord(find: (item: StorageStateRecord) => boolean, map: (record: Proto.IStorageRecord) => Proto.IStorageRecord): StorageState;
removeRecord(find: (item: StorageStateRecord) => boolean): StorageState;
getAllGroupRecords(): ReadonlyArray<StorageStateRecord>;
hasKey(storageKey: Buffer): boolean;
createWriteOperation({ storageKey, recordIkm, previous, }: CreateWriteOperationOptions): Proto.IWriteOperation;
inspect(): string;
diff(oldState: StorageState): DiffResult;
private addItem;
private updateItem;
private replaceItem;
private removeItem;
private changePin;
private changeGroupPin;
private static createStorageID;
}