/** * OPFS (Origin Private File System) Storage Adapter * Provides persistent storage for the vector database using the Origin Private File System API */ import { GraphVerb, HNSWNoun, HNSWVerb, StatisticsData } from '../../coreTypes.js'; import { BaseStorage } from '../baseStorage.js'; import '../../types/fileSystemTypes.js'; type HNSWNode = HNSWNoun; /** * Type alias for HNSWVerb to make the code more readable */ type Edge = HNSWVerb; type HNSWNoun_internal = HNSWNoun; /** * OPFS storage adapter for browser environments * Uses the Origin Private File System API to store data persistently */ export declare class OPFSStorage extends BaseStorage { private rootDir; private nounsDir; private verbsDir; private metadataDir; private nounMetadataDir; private verbMetadataDir; private indexDir; private isAvailable; private isPersistentRequested; private isPersistentGranted; private statistics; private activeLocks; private lockPrefix; constructor(); /** * Initialize the storage adapter */ init(): Promise; /** * Check if OPFS is available in the current environment */ isOPFSAvailable(): boolean; /** * Request persistent storage permission from the user * @returns Promise that resolves to true if permission was granted, false otherwise */ requestPersistentStorage(): Promise; /** * Check if persistent storage is granted * @returns Promise that resolves to true if persistent storage is granted, false otherwise */ isPersistent(): Promise; /** * Save a noun to storage */ protected saveNoun_internal(noun: HNSWNoun_internal): Promise; /** * Get a noun from storage */ protected getNoun_internal(id: string): Promise; /** * Get nouns by noun type (internal implementation) * @param nounType The noun type to filter by * @returns Promise that resolves to an array of nouns of the specified noun type */ protected getNounsByNounType_internal(nounType: string): Promise; /** * Get nodes by noun type * @param nounType The noun type to filter by * @returns Promise that resolves to an array of nodes of the specified noun type */ protected getNodesByNounType(nounType: string): Promise; /** * Delete a noun from storage (internal implementation) */ protected deleteNoun_internal(id: string): Promise; /** * Delete a node from storage */ protected deleteNode(id: string): Promise; /** * Save a verb to storage (internal implementation) */ protected saveVerb_internal(verb: HNSWVerb): Promise; /** * Save an edge to storage */ protected saveEdge(edge: Edge): Promise; /** * Get a verb from storage (internal implementation) */ protected getVerb_internal(id: string): Promise; /** * Get an edge from storage */ protected getEdge(id: string): Promise; /** * Get all edges from storage */ protected getAllEdges(): Promise; /** * Get verbs by source (internal implementation) */ protected getVerbsBySource_internal(sourceId: string): Promise; /** * Get edges by source */ protected getEdgesBySource(sourceId: string): Promise; /** * Get verbs by target (internal implementation) */ protected getVerbsByTarget_internal(targetId: string): Promise; /** * Get edges by target */ protected getEdgesByTarget(targetId: string): Promise; /** * Get verbs by type (internal implementation) */ protected getVerbsByType_internal(type: string): Promise; /** * Get edges by type */ protected getEdgesByType(type: string): Promise; /** * Delete a verb from storage (internal implementation) */ protected deleteVerb_internal(id: string): Promise; /** * Delete an edge from storage */ protected deleteEdge(id: string): Promise; /** * Save metadata to storage */ saveMetadata(id: string, metadata: any): Promise; /** * Get metadata from storage */ getMetadata(id: string): Promise; /** * Get multiple metadata objects in batches (CRITICAL: Prevents socket exhaustion) * OPFS implementation uses controlled concurrency for file operations */ getMetadataBatch(ids: string[]): Promise>; /** * Save verb metadata to storage */ saveVerbMetadata(id: string, metadata: any): Promise; /** * Get verb metadata from storage */ getVerbMetadata(id: string): Promise; /** * Save noun metadata to storage */ saveNounMetadata(id: string, metadata: any): Promise; /** * Get noun metadata from storage */ getNounMetadata(id: string): Promise; /** * Clear all data from storage */ clear(): Promise; /** * Get information about storage usage and capacity */ getStorageStatus(): Promise<{ type: string; used: number; quota: number | null; details?: Record; }>; /** * Get the statistics key for a specific date * @param date The date to get the key for * @returns The statistics key for the specified date */ private getStatisticsKeyForDate; /** * Get the current statistics key * @returns The current statistics key */ private getCurrentStatisticsKey; /** * Get the legacy statistics key (for backward compatibility) * @returns The legacy statistics key */ private getLegacyStatisticsKey; /** * Acquire a browser-based lock for coordinating operations across multiple tabs * @param lockKey The key to lock on * @param ttl Time to live for the lock in milliseconds (default: 30 seconds) * @returns Promise that resolves to true if lock was acquired, false otherwise */ private acquireLock; /** * Release a browser-based lock * @param lockKey The key to unlock * @param lockValue The value used when acquiring the lock (for verification) * @returns Promise that resolves when lock is released */ private releaseLock; /** * Clean up expired locks from localStorage */ private cleanupExpiredLocks; /** * Save statistics data to storage with browser-based locking * @param statistics The statistics data to save */ protected saveStatisticsData(statistics: StatisticsData): Promise; /** * Get statistics data from storage * @returns Promise that resolves to the statistics data or null if not found */ protected getStatisticsData(): Promise; /** * Get nouns with pagination support * @param options Pagination and filter options * @returns Promise that resolves to a paginated result of nouns */ getNounsWithPagination(options?: { limit?: number; cursor?: string; filter?: { nounType?: string | string[]; service?: string | string[]; metadata?: Record; }; }): Promise<{ items: HNSWNoun[]; totalCount?: number; hasMore: boolean; nextCursor?: string; }>; /** * Get verbs with pagination support * @param options Pagination and filter options * @returns Promise that resolves to a paginated result of verbs */ getVerbsWithPagination(options?: { limit?: number; cursor?: string; filter?: { verbType?: string | string[]; sourceId?: string | string[]; targetId?: string | string[]; service?: string | string[]; metadata?: Record; }; }): Promise<{ items: GraphVerb[]; totalCount?: number; hasMore: boolean; nextCursor?: string; }>; } export {};