UNPKG

docudb

Version:

Document-based NoSQL database for NodeJS

134 lines 4.52 kB
/** * Indexing Module * Handles the creation and use of indexes to optimize searches */ import { IndexManagerOptions, IndexOptions, Document, Indices } from '../types/index.js'; declare class IndexManager { indices: Indices; dataDir: string; /** * @param {Object} options - Configuration options * @param {string} options.dataDir - Directory to store data */ constructor(options?: IndexManagerOptions); /** * Initializes the index manager * @param {string} collectionName - Collection name */ initialize(collectionName: string): Promise<void>; /** * Creates an index for a specific field * @param {string} collectionName - Collection name * @param {string} field - Field to index * @param {IndexOptions} options - Index options * @returns {Promise<void>} */ createIndex(collectionName: string, field: string | string[], options?: IndexOptions): Promise<boolean>; /** * Removes an index * @param {string} collectionName - Collection name * @param {string} field - Indexed field * @returns {Promise<void>} */ dropIndex(collectionName: string, field: string): Promise<void>; /** * Updates an index with a document * @param {string} collectionName - Collection name * @param {string} docId - Document ID * @param {Object} doc - Document to index * @returns {Promise<void>} */ updateIndex(collectionName: string, docId: string, doc: Document): Promise<void>; /** * Removes a document from all indices * @param {string} collectionName - Collection name * @param {string} docId - Document ID * @returns {Promise<void>} */ removeFromIndices(collectionName: string, docId: string): Promise<void>; /** * Finds documents using an index * @param {string} collectionName - Collection name * @param {string} field - Indexed field * @param {*} value - Value to search for * @returns {string[]} - Matching document IDs */ findByIndex(collectionName: string, field: string, value: any): string[] | null; /** * Checks if an index exists for a field * @param {string} collectionName - Collection name * @param {string} field - Field to check * @returns {boolean} - true if an index exists for the field */ hasIndex(collectionName: string, field: string): boolean; /** * Gets the index directory path * @param {string} collectionName - Collection name * @returns {string} - Directory path * @private */ private _getIndexDir; /** * Gets the path for an index file * @param {string} collectionName - Collection name * @param {string} field - Indexed field * @returns {string} - File path * @private */ private _getIndexPath; /** * Loads all indices for a collection * @param {string} collectionName - Collection name * @returns {Promise<void>} * @private */ private _loadIndices; /** * Saves an index to disk * @param {string} collectionName - Collection name * @param {string} field - Indexed field * @returns {Promise<void>} * @private */ private _saveIndex; /** * Saves all indices for a collection * @param {string} collectionName - Collection name * @returns {Promise<void>} * @private */ private _saveAllIndices; /** * Removes a document from an index * @param {Object} index - Index to modify * @param {string} docId - Document ID * @returns {boolean} - true if any entry was removed * @private */ private _removeDocFromIndex; /** * Finds a document ID by value in an index * @param {Object} index - Index to search * @param {*} value - Value to search for * @returns {string|null} - Document ID or null if not found * @private */ private _findDocIdByValue; /** * Converts a value to a string key for the index * @param {*} value - Value to convert * @returns {string} - Key for the index * @private */ private _getValueKey; /** * Gets a nested value from an object using dot notation * @param {Object} obj - Object to get value from * @param {string} path - Path to value using dot notation * @returns {*} - Found value or undefined * @private */ private _getNestedValue; } export default IndexManager; //# sourceMappingURL=indexManager.d.ts.map