import { Member, PlatformID, SecureString } from '@digitaldefiance/ecies-lib'; import { IMemberChanges, IMemberIndexEntry, IMemberQueryCriteria, IMemberReference, IMemberStore, INewMemberData } from '../interfaces/member/memberData'; import { IPrivateMemberProfileHydratedData, IPublicMemberProfileHydratedData } from '../interfaces/member/profileStorage'; import { IBlockStore } from '../interfaces/storage/blockStore'; import { IMemberStoreDb } from '../interfaces/storage/documentTypes'; /** * Service for storing and retrieving member data */ export declare class MemberStore implements IMemberStore { private readonly blockStore; private readonly memberIndex; private readonly regionIndex; private readonly nameIndex; private readonly emailIndex; /** Optional DB reference for scalable, DB-backed queryIndex lookups. */ private _db; /** * Safely convert a TID to its raw Uint8Array bytes. * * GuidV4Provider.toBytes() expects a GuidV4Uint8Array with branded getters. * If the caller passes a plain Uint8Array (e.g. via an `as Uint8Array` cast), * toBytes() returns undefined because the branded getter is missing. * This helper detects that case and falls back to fromBytes() → toBytes() * to re-wrap the raw bytes into the correct branded type first. */ private idToBytes; constructor(blockStore: IBlockStore, db?: IMemberStoreDb); /** * Pick the smallest supported block size that can hold `dataLength` bytes. * * Delegates to `BlockService.getBlockSizeForData` with the block store's * supported sizes so that only sizes the store actually accepts are * considered. * * @throws MemberError if no supported block size is large enough. */ private blockSizeForData; /** * Attach (or replace) the DB reference after construction. * Called by the plugin after connect() so MemberStore can query * the persisted member_index and users collections directly. */ setDb(db: IMemberStoreDb): void; /** * Extract and parse JSON data from a CBL block. * Handles XOR tuple reconstruction and null byte trimming. * * @param cbl - The ConstituentBlockListBlock to extract data from * @returns The parsed JSON data as a storage data object * @throws MemberError if extraction or parsing fails * @requirements 1.1, 1.2 */ private extractProfileDataFromCBL; /** * Create a new member */ createMember(data: INewMemberData): Promise<{ reference: IMemberReference; mnemonic: SecureString; }>; /** * Get a member by ID * Reconstructs the member from stored CBL blocks. * * @param id - The member ID * @returns The reconstructed Member object * @throws MemberError if member not found or reconstruction fails * @requirements 2.1, 2.2 */ getMember(id: TID): Promise>; /** * Returns the hex-encoded public key for a member. * * Fast path: when a DB reference is set, queries the `users` collection * directly for `publicKey` (stored as hex by buildUserDocument). This * avoids loading CBL blocks, which are not written for seeded users. * * Fallback: calls getMember() for members created via createMember() that * do have real CBL blocks in the block store. */ getMemberPublicKeyHex(id: TID): Promise; /** * Get member profile document by ID * Deserializes CBL data to retrieve public and private profile data. * * @param id - The member ID * @returns Object containing public and private profile data (null if not available) * @throws MemberError if member not found or deserialization fails * @requirements 1.1, 1.2, 1.3, 1.4 */ getMemberProfile(id: TID): Promise<{ publicProfile: IPublicMemberProfileHydratedData | null; privateProfile: IPrivateMemberProfileHydratedData | null; }>; /** * Update a member * * Persists profile changes to CBL blocks and updates the member index. * Implements rollback mechanism for failed updates. * * @param id - The member ID * @param changes - The changes to apply * @throws MemberError if member not found or update fails * @requirements 3.1, 3.2, 3.3, 3.4 */ updateMember(id: TID, changes: IMemberChanges): Promise; /** * Delete a member */ deleteMember(id: TID): Promise; /** * Update the member index. * * Updates the in-memory indexes AND persists the entry to the * `member_index` BrightDb collection (when `_db` is available) so that * the data survives server restarts. Without this DB write, members * created via `createMember()` / `register()` only existed in memory * and were lost on restart. */ updateIndex(entry: IMemberIndexEntry): Promise; /** * Query the member index. * * When a `name` or `email` criterion is provided and the in-memory index is * empty (e.g. after a server restart), falls back to querying the persisted * `users` and `member_index` collections via the optional `_db` reference. * This avoids loading the entire member list into memory for large databases. */ queryIndex(criteria: IMemberQueryCriteria): Promise[]>; /** * DB-backed queryIndex for name/email lookups. * * Queries `users` for the member ID, then `member_index` for CBL checksums. * Returns at most `criteria.limit` results (default 1 for name/email lookups). * Does NOT load the full member list — O(1) DB lookups. */ private _queryIndexFromDb; /** * Sync shard with other nodes */ syncShard(_region: string): Promise; /** * Propagate changes to other nodes */ propagateChanges(_changes: IMemberChanges[]): Promise; } //# sourceMappingURL=memberStore.d.ts.map