axiodb
Version:
The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor
46 lines (45 loc) • 1.93 kB
TypeScript
import { SuccessInterface, ErrorInterface } from '../config/Interfaces/Helper/response.helper.interface';
/**
* DocumentLoader - Shared utility for loading documents from collection directories
*
* Provides a centralized method for loading document files using worker threads,
* replacing duplicated code in Reader, Update, Delete, and Aggregation operations.
*
* @class DocumentLoader
*/
export default class DocumentLoader {
private static readonly ResponseHelper;
/**
* Loads all documents from a collection directory using worker threads
*
* This method consolidates the LoadAllBufferRawData logic that was previously
* duplicated across multiple CRUD operations. It handles both direct file
* specification and directory scanning with .axiodb file filtering.
*
* @param collectionPath - Full path to collection directory
* @param encryptionKey - Optional encryption key for encrypted documents
* @param isEncrypted - Whether documents are encrypted (default: false)
* @param documentFiles - Optional specific file names to load
* @param includeFileName - Whether to include fileName in result (default: false)
* @returns Success with document array or Error
*
* @example
* // Load all documents from a collection
* const result = await DocumentLoader.loadDocuments(
* '/path/to/collection',
* undefined,
* false
* );
*
* @example
* // Load specific documents with filenames included
* const result = await DocumentLoader.loadDocuments(
* '/path/to/collection',
* 'encryption-key',
* true,
* ['doc1.axiodb', 'doc2.axiodb'],
* true
* );
*/
static loadDocuments(collectionPath: string, encryptionKey?: string, isEncrypted?: boolean, documentFiles?: string[], includeFileName?: boolean): Promise<SuccessInterface | ErrorInterface>;
}