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
91 lines • 4.4 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const FolderManager_1 = __importDefault(require("../engine/Filesystem/FolderManager"));
const BufferLoaderWithWorker_utils_1 = __importDefault(require("../utility/BufferLoaderWithWorker.utils"));
const response_helper_1 = __importDefault(require("./response.helper"));
/**
* 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
*/
class DocumentLoader {
/**
* 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_1, encryptionKey_1) {
return __awaiter(this, arguments, void 0, function* (collectionPath, encryptionKey, isEncrypted = false, documentFiles, includeFileName = false) {
try {
const dataFilesList = [];
if (documentFiles !== undefined) {
// Use provided file list
dataFilesList.push(...documentFiles);
}
else {
// Scan directory for .axiodb files
const readResponse = yield new FolderManager_1.default().ListDirectory(collectionPath);
if ("data" in readResponse) {
// Filter for .axiodb files only
const axiodbFiles = readResponse.data.filter((file) => file.endsWith(".axiodb"));
dataFilesList.push(...axiodbFiles);
}
else {
return this.ResponseHelper.Error("Failed to read directory");
}
}
// Load all files using worker threads (parallel processing)
const resultData = yield (0, BufferLoaderWithWorker_utils_1.default)(dataFilesList, encryptionKey, collectionPath, isEncrypted, includeFileName);
return this.ResponseHelper.Success(resultData);
}
catch (error) {
return this.ResponseHelper.Error(error);
}
});
}
}
DocumentLoader.ResponseHelper = new response_helper_1.default();
exports.default = DocumentLoader;
//# sourceMappingURL=DocumentLoader.helper.js.map