import { ISigned, IUser } from './user'; import { IDataChange } from './data-change'; import { Event } from './events'; export declare const events: { dataSaved: Event; dataDeleted: Event; }; export interface IData extends ISigned { id: string; group: string; type: 'Group' | 'Deleted' | 'User' | 'any' | string; modified: number; subject?: string; ttl?: number; [key: string]: any; } export interface IGroupMember { userId: string; read?: boolean; write?: boolean; admin?: boolean; expireMS?: number; } export interface IGroup extends IData { type: 'Group'; name: string; owner: string; members: IGroupMember[]; blockedUserIds: string[]; allowPublicViewers?: boolean; allowViewerComments?: boolean; apps?: string[]; inactive?: boolean; } export declare function isGroup(data: IData): data is IGroup; export interface IFile { type: 'File'; id: string; name: string; fileType: string; size: number; blob: Blob; isPublic: boolean; shareUsers: string[]; shareGroups: string[]; } export interface IKVIndex extends IData { type: 'Index'; dataKey: string; dataType?: string; } export declare const usersGroup: IGroup; export declare function getPersonalGroup(myId: string): IGroup; export type Indexes = 'group' | 'type' | 'modified' | 'group-type' | 'group-modified' | 'type-modified' | 'group-type-modified' | 'subject' | 'group-subject' | 'type-subject' | 'group-type-subject' | IKVIndex; export interface ICursor { value: T; next: () => Promise; } export type DBCursorDirection = "next" | "nextunique" | "prev" | "prevunique"; export type DBKeyValue = string | number | Date; export type DBKeyArray = DBKeyValue[]; export interface DBKeyRange { lower?: DBKeyValue | DBKeyArray; upper?: DBKeyValue | DBKeyArray; lowerOpen?: boolean; upperOpen?: boolean; } export type DBQuery = DBKeyValue | DBKeyArray | DBKeyRange; export interface IDB { save: (data: IData | IData[], skipValidation?: boolean) => Promise; get: (id: string) => Promise; delete: (id: string) => Promise; find: (query?: DBQuery, index?: Indexes) => Promise; openCursor: (query?: DBQuery, index?: Indexes, direction?: DBCursorDirection) => Promise>; files: { save: (file: IFile) => Promise; get: (id: string) => Promise; delete: (id: string) => Promise; }; local: { save: (data: any) => Promise; get: (id: string) => Promise; delete: (id: string) => Promise; }; changes: { save: (data: IDataChange | IDataChange[]) => Promise; get: (id: string) => Promise; delete: (id: string) => Promise; openCursor: (group: string, modified?: number, direction?: IDBCursorDirection) => Promise>; getSubjectChanges: (subject: string, modified?: number) => Promise; }; } export interface PeerstackDBOpts { dbName?: string; dbVersion?: number; onUpgrade?: ((evt: any) => Promise); persistenceLayer?: IPersistenceLayer; [key: string]: any; } export interface IPersistenceLayer { init: (opts: PeerstackDBOpts) => Promise; } export declare function init(opts?: PeerstackDBOpts): Promise; export declare function getDB(): Promise; export declare const checkPermission: typeof hasPermission; export declare const groups: { [groupId: string]: IGroup; }; export declare const users: { [userId: string]: IUser; }; export declare function getGroup(groupId: string, forceRefresh?: boolean): Promise; export declare function getUser(userId: string, forceRefresh?: boolean): Promise; export declare function hasPermission(userId: string, group: string | IGroup, accessLevel: 'read' | 'write' | 'admin', db?: IDB): Promise; export declare function validateData(db: IDB, datas: IData[]): Promise; export declare const BLOCK_SIZE: number; export declare function getBlockId(modified: number): string; export declare function getGroupUsers(groupId: string): Promise; export declare function getBlockIds(group: string, level0BlockId: string): Promise<{ id: string; modified: number; }[]>; export declare const L5BlockHashes: { [groupId: string]: { [blockId: string]: string; }; }; export declare const blockHashes: { [groupId: string]: { [detailLevel: string]: { [blockId: string]: string; }; }; }; export declare function clearHashCache(groupId: string): void; export declare function getBlockHashes(groupId: string, detailLevel?: number): Promise<{}>; export declare function getBlockIdHashes(groupId: string, blockId: string): Promise<{ [blockId: string]: string; }>; export declare function getDetailHashes(groupId: string): Promise<{}>; export declare function getGroupUsersHash(groupId: string): Promise<{ users: IUser[]; hash: string; }>;