axiodb 3.31.117 → 4.32.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +16 -17
  2. package/lib/Services/CRUD Operation/Create.operation.js +1 -1
  3. package/lib/Services/CRUD Operation/Create.operation.js.map +1 -1
  4. package/lib/Services/CRUD Operation/Delete.operation.js +17 -12
  5. package/lib/Services/CRUD Operation/Delete.operation.js.map +1 -1
  6. package/lib/Services/CRUD Operation/Reader.operation.js +27 -14
  7. package/lib/Services/CRUD Operation/Reader.operation.js.map +1 -1
  8. package/lib/Services/CRUD Operation/Update.operation.d.ts +1 -3
  9. package/lib/Services/CRUD Operation/Update.operation.js +20 -68
  10. package/lib/Services/CRUD Operation/Update.operation.js.map +1 -1
  11. package/lib/Services/Collection/collection.operation.d.ts +23 -3
  12. package/lib/Services/Collection/collection.operation.js +34 -22
  13. package/lib/Services/Collection/collection.operation.js.map +1 -1
  14. package/lib/Services/Database/database.operation.d.ts +27 -3
  15. package/lib/Services/Database/database.operation.js +55 -11
  16. package/lib/Services/Database/database.operation.js.map +1 -1
  17. package/lib/Services/Index/Index.service.d.ts +125 -0
  18. package/lib/Services/Index/Index.service.js +231 -0
  19. package/lib/Services/Index/Index.service.js.map +1 -0
  20. package/lib/Services/Index/InsertIndex.service.d.ts +34 -0
  21. package/lib/Services/Index/InsertIndex.service.js +79 -0
  22. package/lib/Services/Index/InsertIndex.service.js.map +1 -0
  23. package/lib/Services/Index/ReadIndex.service.d.ts +44 -0
  24. package/lib/Services/Index/ReadIndex.service.js +81 -0
  25. package/lib/Services/Index/ReadIndex.service.js.map +1 -0
  26. package/lib/config/DB.d.ts +1 -29
  27. package/lib/config/DB.js +1 -7
  28. package/lib/config/DB.js.map +1 -1
  29. package/lib/config/Interfaces/Operation/database.operation.interface.d.ts +0 -2
  30. package/lib/utility/BufferLoaderWithWorker.utils.js +28 -7
  31. package/lib/utility/BufferLoaderWithWorker.utils.js.map +1 -1
  32. package/lib/utility/Searcher.utils.js +1 -1
  33. package/package.json +1 -1
  34. package/lib/Schema/DataTypes.models.d.ts +0 -26
  35. package/lib/Schema/DataTypes.models.js +0 -36
  36. package/lib/Schema/DataTypes.models.js.map +0 -1
  37. package/lib/Schema/validator.models.d.ts +0 -10
  38. package/lib/Schema/validator.models.js +0 -51
  39. package/lib/Schema/validator.models.js.map +0 -1
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.IndexManager = void 0;
16
+ const Keys_1 = require("../../config/Keys/Keys");
17
+ const FileManager_1 = __importDefault(require("../../engine/Filesystem/FileManager"));
18
+ const FolderManager_1 = __importDefault(require("../../engine/Filesystem/FolderManager"));
19
+ const Converter_helper_1 = __importDefault(require("../../Helper/Converter.helper"));
20
+ const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
21
+ class IndexManager {
22
+ constructor(path) {
23
+ this.path = path;
24
+ this.indexFolderPath = `${this.path}/indexes`;
25
+ this.indexMetaPath = `${this.indexFolderPath}/index.meta.json`;
26
+ this.fileManager = new FileManager_1.default();
27
+ this.folderManager = new FolderManager_1.default();
28
+ this.converter = new Converter_helper_1.default();
29
+ this.ResponseHelper = new response_helper_1.default();
30
+ }
31
+ /**
32
+ * Create one or more index files and register them in the index metadata.
33
+ *
34
+ * For each supplied field name this method:
35
+ * 1. Determines the index file path as `${indexName}.axiodb` inside the configured index folder.
36
+ * 2. Checks whether the index file already exists. If it does not, creates the file with an empty
37
+ * index structure ({ fieldName, indexEntries: [] }).
38
+ * 3. Reads the index metadata file (index.meta.json), parses it, and if an entry for the index
39
+ * field does not already exist, appends a metadata record `{ indexFieldName, fileName, path }`
40
+ * and writes the metadata file back.
41
+ *
42
+ * Side effects:
43
+ * - Writes new index files to disk via `fileManager.WriteFile`.
44
+ * - Reads and updates the index metadata file via `fileManager.ReadFile` / `WriteFile`.
45
+ * - Uses the configured `converter` to serialize/deserialize index and metadata content.
46
+ *
47
+ * Notes:
48
+ * - The operation is not atomic: some indexes may be created while others fail. The method will
49
+ * collect created and failed index names and include them in the returned response.
50
+ * - A failure is recorded for a field when the index file already exists, when the index already
51
+ * exists in the metadata, or when reading/writing the metadata file fails.
52
+ * - The method relies on `indexFolderPath`, `indexMetaPath`, `fileManager`, and `converter`
53
+ * being correctly configured and available on the instance.
54
+ *
55
+ * @param fieldNames - One or more field names for which to create indexes.
56
+ * @returns A promise that resolves to either:
57
+ * - SuccessInterface: indicates which indexes were created and which already existed / failed,
58
+ * typically containing a human-readable message listing affected and existing indexes.
59
+ * - ErrorInterface: returned when underlying file/IO operations fail in a way that prevents
60
+ * producing the expected success response.
61
+ *
62
+ * @example
63
+ * // Create a single index
64
+ * await service.createIndex('email');
65
+ *
66
+ * @example
67
+ * // Create multiple indexes
68
+ * await service.createIndex('email', 'username', 'createdAt');
69
+ */
70
+ createIndex(...fieldNames) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const EffectedIndexes = [];
73
+ const FailedIndexes = [];
74
+ for (const fieldName of fieldNames) {
75
+ const indexName = fieldName;
76
+ const indexFilePath = `${this.indexFolderPath}/${indexName}${Keys_1.General.DBMS_File_EXT}`;
77
+ const DemoIndexHash = {
78
+ fieldName: indexName,
79
+ indexEntries: {},
80
+ };
81
+ const exists = yield this.fileManager.FileExists(indexFilePath);
82
+ if (!exists.status) {
83
+ // create empty index file
84
+ yield this.fileManager.WriteFile(indexFilePath, this.converter.ToString(DemoIndexHash));
85
+ // Update index.meta.json
86
+ const indexMetaContent = yield this.fileManager.ReadFile(this.indexMetaPath);
87
+ if (indexMetaContent.status) {
88
+ const indexMeta = this.converter.ToObject(indexMetaContent.data);
89
+ // check if index already exists in meta
90
+ const indexExists = indexMeta.find((index) => index.indexFieldName === indexName);
91
+ if (!indexExists) {
92
+ indexMeta.push({
93
+ indexFieldName: indexName,
94
+ fileName: `${indexName}${Keys_1.General.DBMS_File_EXT}`,
95
+ path: indexFilePath,
96
+ });
97
+ yield this.fileManager.WriteFile(this.indexMetaPath, this.converter.ToString(indexMeta));
98
+ EffectedIndexes.push(indexName);
99
+ return this.ResponseHelper.Success(`Indexes: ${EffectedIndexes.join(", ")} created Indexes: ${FailedIndexes.join(", ")}`);
100
+ }
101
+ else {
102
+ FailedIndexes.push(indexName);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ });
108
+ }
109
+ /**
110
+ * Deletes an index file and removes its entry from the index metadata.
111
+ *
112
+ * This asynchronous method attempts to delete the index file located at
113
+ * `${this.indexFolderPath}/${indexName}.axiodb`. If the file exists it is removed,
114
+ * and the index metadata file at `this.indexMetaPath` is read and updated by
115
+ * filtering out the metadata entry whose `indexFieldName` matches `indexName`.
116
+ * The metadata update is performed only if the metadata file can be read successfully.
117
+ *
118
+ * @param indexName - The name of the index to delete (without extension).
119
+ * @returns A Promise that resolves to a SuccessInterface when the index was deleted
120
+ * (and metadata updated when possible), or an ErrorInterface when the
121
+ * specified index does not exist.
122
+ *
123
+ * @async
124
+ * @remarks
125
+ * - Side effects: removes a file from the file system and may modify the index metadata file.
126
+ * - Uses injected helpers: `fileManager` for filesystem operations, `converter` for
127
+ * (de)serialization of metadata, and `ResponseHelper` to construct the returned result.
128
+ * - If the metadata file cannot be read, the method still succeeds after deleting the index file.
129
+ *
130
+ * @throws {Error} May propagate errors from underlying file operations if those utilities throw.
131
+ */
132
+ dropIndex(indexName) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const indexFilePath = `${this.indexFolderPath}/${indexName}${Keys_1.General.DBMS_File_EXT}`;
135
+ // check if index file exists
136
+ const exists = yield this.fileManager.FileExists(indexFilePath);
137
+ if (exists.status === true) {
138
+ // delete index file
139
+ yield this.fileManager.DeleteFile(indexFilePath);
140
+ // update index.meta.json
141
+ const indexMetaContent = yield this.fileManager.ReadFile(this.indexMetaPath);
142
+ if (indexMetaContent.status) {
143
+ let indexMeta = this.converter.ToObject(indexMetaContent.data);
144
+ indexMeta = indexMeta.filter((index) => index.indexFieldName !== indexName);
145
+ yield this.fileManager.WriteFile(this.indexMetaPath, this.converter.ToString(indexMeta));
146
+ }
147
+ return this.ResponseHelper.Success(`Index: ${indexName} deleted successfully`);
148
+ }
149
+ else {
150
+ return this.ResponseHelper.Error(`Index: ${indexName} does not exist`);
151
+ }
152
+ });
153
+ }
154
+ /**
155
+ * Ensures the index folder and the index metadata file exist, creating them if necessary.
156
+ *
157
+ * This asynchronous method performs the following steps:
158
+ * 1. Checks whether the index folder at `this.indexFolderPath` exists; if not, creates it.
159
+ * 2. Checks whether the index metadata file at `this.indexMetaPath` exists; if not:
160
+ * a. Constructs a default index metadata entry for a unique "documentId" index:
161
+ * - indexFieldName: "documentId"
162
+ * - fileName: "documentId.axiodb"
163
+ * - path: `${this.indexFolderPath}/documentId.axiodb`
164
+ * - unique: true
165
+ * b. Calls `this.createIndex("documentId")` to create the underlying index file/structure.
166
+ * c. Writes the metadata array to `this.indexMetaPath` using `this.converter.ToString(...)`.
167
+ *
168
+ * The operation is idempotent: if the folder or metadata file already exist, no changes are made.
169
+ *
170
+ * @remarks
171
+ * - This method performs filesystem modifications via `folderManager` and `fileManager`.
172
+ * - Any errors thrown by `folderManager`, `fileManager`, `converter`, or `createIndex` will propagate to the caller.
173
+ * - Callers should `await` this method to ensure the initialization is complete before proceeding.
174
+ *
175
+ * @returns A Promise that resolves when initialization is complete.
176
+ *
177
+ * @throws Will reject if directory creation, file checks/writes, conversion, or index creation fails.
178
+ *
179
+ * @example
180
+ * // Ensure index folder and metadata exist before using the index service
181
+ * await indexService.generateIndexMeta();
182
+ */
183
+ generateIndexMeta() {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ // check is index.meta.json exists or not
186
+ const folderExists = yield this.folderManager.DirectoryExists(this.indexFolderPath);
187
+ if (!folderExists.status) {
188
+ yield this.folderManager.CreateDirectory(this.indexFolderPath);
189
+ }
190
+ const exists = yield this.fileManager.FileExists(this.indexMetaPath);
191
+ if (!exists.status) {
192
+ // create index.meta.json
193
+ const indexMeta = [
194
+ {
195
+ indexFieldName: "documentId",
196
+ path: `${this.indexFolderPath}/documentId${Keys_1.General.DBMS_File_EXT}`,
197
+ fileName: `documentId${Keys_1.General.DBMS_File_EXT}`
198
+ }
199
+ ];
200
+ yield this.createIndex("documentId");
201
+ yield this.fileManager.WriteFile(this.indexMetaPath, this.converter.ToString(indexMeta));
202
+ }
203
+ });
204
+ }
205
+ /**
206
+ * Finds index metadata entries that correspond to properties present on the provided document.
207
+ *
208
+ * Reads the index metadata file at `this.indexMetaPath`, converts its content into an object,
209
+ * and returns the subset of metadata entries whose `indexFieldName` is an own property of `doc`.
210
+ *
211
+ * @param doc - The document to check for matching index fields. The function tests own properties
212
+ * (via `Object.prototype.hasOwnProperty.call`) rather than inherited properties.
213
+ * @returns A Promise that resolves to an array of matching index metadata entries, or `undefined`
214
+ * if the index metadata file could not be successfully read. The array may be empty if
215
+ * no metadata entries match.
216
+ *
217
+ * @throws May propagate errors from `fileManager.ReadFile` or `converter.ToObject` if those
218
+ * operations throw or reject.
219
+ */
220
+ findMatchingIndexMeta(doc) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const indexMetaContent = yield this.fileManager.ReadFile(this.indexMetaPath);
223
+ if (indexMetaContent.status) {
224
+ const indexMeta = this.converter.ToObject(indexMetaContent.data);
225
+ return indexMeta.filter((meta) => Object.prototype.hasOwnProperty.call(doc, meta.indexFieldName));
226
+ }
227
+ });
228
+ }
229
+ }
230
+ exports.IndexManager = IndexManager;
231
+ //# sourceMappingURL=Index.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Index.service.js","sourceRoot":"","sources":["../../../source/Services/Index/Index.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,iDAAiD;AACjD,sFAA8D;AAC9D,0FAAkE;AAClE,qFAAsD;AACtD,mFAA0D;AAE1D,MAAa,YAAY;IAUvB,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,GAAG,IAAI,CAAC,IAAI,UAAU,CAAC;QAC9C,IAAI,CAAC,aAAa,GAAG,GAAG,IAAI,CAAC,eAAe,kBAAkB,CAAC;QAC/D,IAAI,CAAC,WAAW,GAAG,IAAI,qBAAW,EAAE,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,IAAI,uBAAa,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,IAAI,yBAAc,EAAE,CAAC;IAC7C,CAAC;IAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACU,WAAW,CAAC,GAAG,UAAoB;;YAC9C,MAAM,eAAe,GAAa,EAAE,CAAC;YACrC,MAAM,aAAa,GAAa,EAAE,CAAC;YACnC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAG,SAAS,CAAC;gBAC5B,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,eAAe,IAAI,SAAS,GAAG,cAAO,CAAC,aAAa,EAAE,CAAC;gBACrF,MAAM,aAAa,GAAG;oBACpB,SAAS,EAAE,SAAS;oBACpB,YAAY,EAAE,EAAE;iBACjB,CAAA;gBACD,MAAM,MAA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C,CAAC,IAA8B,EAAE,EAAE,CACzD,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,CAC/D,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AA3ND,oCA2NC"}
@@ -0,0 +1,34 @@
1
+ import { IndexManager } from "./Index.service";
2
+ export default class InsertIndex extends IndexManager {
3
+ constructor(path: string);
4
+ /**
5
+ * Inserts a document identifier into one or more index files as defined by the global index meta.
6
+ *
7
+ * The method:
8
+ * 1. Reads the global index meta from `this.indexMetaPath` and converts it to an object using `this.converter`.
9
+ * 2. Calls `this.findMatchingIndexMeta(document)` to determine which index files should be updated for the provided document.
10
+ * 3. For each matched index entry:
11
+ * - Reads the index file at `index.path`,
12
+ * - Converts its contents to an object,
13
+ * - Appends `${document.documentId}${General.DBMS_File_EXT}` to `indexMeta.indexEntries`,
14
+ * - Writes the updated index back to disk.
15
+ *
16
+ * @param document - Object representing the document to index. Must contain a `documentId` property (string | number).
17
+ * @returns A Promise that resolves to:
18
+ * - `true` if the last index file write operation returned a success status,
19
+ * - `false` if the global index meta could not be read, no matching index meta entries were found, or the final write returned a falsy status.
20
+ *
21
+ * @throws Propagates any exceptions thrown by file reads/writes or conversion (e.g., IO or parse/serialize errors).
22
+ *
23
+ * @remarks
24
+ * - The method appends the document entry and does not deduplicate existing entries.
25
+ * - When multiple index files are updated, the returned boolean reflects the status of the final write operation only.
26
+ * - The operation is not atomic across multiple index files; concurrent invocations may produce race conditions.
27
+ *
28
+ * @example
29
+ * // document must include documentId:
30
+ * // { documentId: "abc123", ... }
31
+ * const success = await indexService.InsertToIndex({ documentId: "abc123" });
32
+ */
33
+ InsertToIndex(document: any): Promise<boolean>;
34
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+ const Keys_1 = require("../../config/Keys/Keys");
14
+ const Index_service_1 = require("./Index.service");
15
+ class InsertIndex extends Index_service_1.IndexManager {
16
+ constructor(path) {
17
+ super(path);
18
+ }
19
+ /**
20
+ * Inserts a document identifier into one or more index files as defined by the global index meta.
21
+ *
22
+ * The method:
23
+ * 1. Reads the global index meta from `this.indexMetaPath` and converts it to an object using `this.converter`.
24
+ * 2. Calls `this.findMatchingIndexMeta(document)` to determine which index files should be updated for the provided document.
25
+ * 3. For each matched index entry:
26
+ * - Reads the index file at `index.path`,
27
+ * - Converts its contents to an object,
28
+ * - Appends `${document.documentId}${General.DBMS_File_EXT}` to `indexMeta.indexEntries`,
29
+ * - Writes the updated index back to disk.
30
+ *
31
+ * @param document - Object representing the document to index. Must contain a `documentId` property (string | number).
32
+ * @returns A Promise that resolves to:
33
+ * - `true` if the last index file write operation returned a success status,
34
+ * - `false` if the global index meta could not be read, no matching index meta entries were found, or the final write returned a falsy status.
35
+ *
36
+ * @throws Propagates any exceptions thrown by file reads/writes or conversion (e.g., IO or parse/serialize errors).
37
+ *
38
+ * @remarks
39
+ * - The method appends the document entry and does not deduplicate existing entries.
40
+ * - When multiple index files are updated, the returned boolean reflects the status of the final write operation only.
41
+ * - The operation is not atomic across multiple index files; concurrent invocations may produce race conditions.
42
+ *
43
+ * @example
44
+ * // document must include documentId:
45
+ * // { documentId: "abc123", ... }
46
+ * const success = await indexService.InsertToIndex({ documentId: "abc123" });
47
+ */
48
+ InsertToIndex(document) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const matchedIndex = yield this.findMatchingIndexMeta(document);
51
+ if (matchedIndex) {
52
+ if (matchedIndex.length == 0) {
53
+ return false;
54
+ }
55
+ let status = false;
56
+ for (const indexes of matchedIndex) {
57
+ const path = indexes.path;
58
+ const IndexName = indexes.indexFieldName;
59
+ const indexContent = yield this.fileManager.ReadFile(path);
60
+ const indexMeta = this.converter.ToObject(indexContent.data);
61
+ const alreadyhave = Object.keys(indexMeta.indexEntries).some(keys => keys == document[IndexName]);
62
+ if (alreadyhave) {
63
+ indexMeta.indexEntries[document[IndexName]].push(`${document.documentId}${Keys_1.General.DBMS_File_EXT}`);
64
+ }
65
+ else {
66
+ indexMeta.indexEntries[document[IndexName]] = [`${document.documentId}${Keys_1.General.DBMS_File_EXT}`];
67
+ }
68
+ // Write it back
69
+ const staus = yield this.fileManager.WriteFile(path, this.converter.ToString(indexMeta));
70
+ status = staus.status;
71
+ }
72
+ return status;
73
+ }
74
+ return false;
75
+ });
76
+ }
77
+ }
78
+ exports.default = InsertIndex;
79
+ //# sourceMappingURL=InsertIndex.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InsertIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/InsertIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD,iDAAiD;AACjD,mDAA+C;AAE/C,MAAqB,WAAY,SAAQ,4BAAY;IAEnD,YAAa,IAAY;QACvB,KAAK,CAAC,IAAI,CAAC,CAAA;IACb,CAAC;IAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BC;IACY,aAAa,CAAC,QAAa;;YACpC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAA;YAE/D,IAAI,YAAY,EAAC,CAAC;gBAElB,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;oBAC7B,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,IA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service";
2
+ export declare class ReadIndex extends IndexManager {
3
+ constructor(path: string);
4
+ /**
5
+ * Retrieve file path(s) from an index that match the provided query.
6
+ *
7
+ * @param query - An object containing the value to look up. The concrete lookup key is determined
8
+ * by the matched index metadata's `fieldName` (i.e. the method will use
9
+ * query[metaContent.fieldName] to find entries).
10
+ *
11
+ * @returns A Promise that resolves to an array of string file paths associated with the query value.
12
+ * If no matching index metadata is found, the promise resolves to an empty array.
13
+ * If a matching index is found but no entries exist for the queried value, the returned
14
+ * value may be undefined at runtime (callers should guard against a missing entry).
15
+ *
16
+ * @remarks
17
+ * - This method calls `findMatchingIndexMeta(query)` to locate the appropriate index metadata.
18
+ * - When a match is found, it reads the index file via `fileManager.ReadFile(...)` and converts the
19
+ * file content to an object using `converter.ToObject(...)`.
20
+ * - The resolved object is expected to have `indexEntries` and `fieldName` properties. The method
21
+ * uses `indexEntries[query[fieldName]]` to obtain the associated file list.
22
+ * - The index object is logged to the console for debugging purposes.
23
+ *
24
+ * @throws The returned promise will reject if reading or parsing the index file fails (for example,
25
+ * due to I/O errors or converter failures).
26
+ */
27
+ getFileFromIndex(query: any): Promise<string[]>;
28
+ /**
29
+ * Finds index metadata entries that correspond to properties present on the provided document.
30
+ *
31
+ * Reads the index metadata file at `this.indexMetaPath`, converts its content into an object,
32
+ * and returns the subset of metadata entries whose `indexFieldName` is an own property of `doc`.
33
+ *
34
+ * @param doc - The document to check for matching index fields. The function tests own properties
35
+ * (via `Object.prototype.hasOwnProperty.call`) rather than inherited properties.
36
+ * @returns A Promise that resolves to an array of matching index metadata entries, or `undefined`
37
+ * if the index metadata file could not be successfully read. The array may be empty if
38
+ * no metadata entries match.
39
+ *
40
+ * @throws May propagate errors from `fileManager.ReadFile` or `converter.ToObject` if those
41
+ * operations throw or reject.
42
+ */
43
+ protected findMatchingIndexMeta(document: any): Promise<any | undefined>;
44
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ReadIndex = void 0;
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ const Index_service_1 = require("./Index.service");
15
+ class ReadIndex extends Index_service_1.IndexManager {
16
+ constructor(path) {
17
+ super(path);
18
+ }
19
+ /**
20
+ * Retrieve file path(s) from an index that match the provided query.
21
+ *
22
+ * @param query - An object containing the value to look up. The concrete lookup key is determined
23
+ * by the matched index metadata's `fieldName` (i.e. the method will use
24
+ * query[metaContent.fieldName] to find entries).
25
+ *
26
+ * @returns A Promise that resolves to an array of string file paths associated with the query value.
27
+ * If no matching index metadata is found, the promise resolves to an empty array.
28
+ * If a matching index is found but no entries exist for the queried value, the returned
29
+ * value may be undefined at runtime (callers should guard against a missing entry).
30
+ *
31
+ * @remarks
32
+ * - This method calls `findMatchingIndexMeta(query)` to locate the appropriate index metadata.
33
+ * - When a match is found, it reads the index file via `fileManager.ReadFile(...)` and converts the
34
+ * file content to an object using `converter.ToObject(...)`.
35
+ * - The resolved object is expected to have `indexEntries` and `fieldName` properties. The method
36
+ * uses `indexEntries[query[fieldName]]` to obtain the associated file list.
37
+ * - The index object is logged to the console for debugging purposes.
38
+ *
39
+ * @throws The returned promise will reject if reading or parsing the index file fails (for example,
40
+ * due to I/O errors or converter failures).
41
+ */
42
+ getFileFromIndex(query) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const matchedIndexFile = yield this.findMatchingIndexMeta(query);
45
+ if (matchedIndexFile !== undefined) {
46
+ const metaContent = this.converter.ToObject((yield this.fileManager.ReadFile(matchedIndexFile.path)).data);
47
+ const finalValueFiles = metaContent.indexEntries[query[metaContent.fieldName]];
48
+ return finalValueFiles;
49
+ }
50
+ else {
51
+ return [];
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Finds index metadata entries that correspond to properties present on the provided document.
57
+ *
58
+ * Reads the index metadata file at `this.indexMetaPath`, converts its content into an object,
59
+ * and returns the subset of metadata entries whose `indexFieldName` is an own property of `doc`.
60
+ *
61
+ * @param doc - The document to check for matching index fields. The function tests own properties
62
+ * (via `Object.prototype.hasOwnProperty.call`) rather than inherited properties.
63
+ * @returns A Promise that resolves to an array of matching index metadata entries, or `undefined`
64
+ * if the index metadata file could not be successfully read. The array may be empty if
65
+ * no metadata entries match.
66
+ *
67
+ * @throws May propagate errors from `fileManager.ReadFile` or `converter.ToObject` if those
68
+ * operations throw or reject.
69
+ */
70
+ findMatchingIndexMeta(document) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const indexMetaContent = yield this.fileManager.ReadFile(this.indexMetaPath);
73
+ if (indexMetaContent.status) {
74
+ const indexMeta = this.converter.ToObject(indexMetaContent.data);
75
+ return indexMeta.find((meta) => Object.prototype.hasOwnProperty.call(document, meta.indexFieldName));
76
+ }
77
+ });
78
+ }
79
+ }
80
+ exports.ReadIndex = ReadIndex;
81
+ //# sourceMappingURL=ReadIndex.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/ReadIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAuD;AACvD,mDAA+C;AAE/C,MAAa,SAAU,SAAQ,4BAAY;IAEzC,YAAa,IAAY;QACvB,KAAK,CAAC,IAAI,CAAC,CAAA;IACb,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,gBAAgB,CAAE,KAAU;;YACvC,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;YAChE,IAAG,gBAAgB,KAAK,SAAS,EAAE,CAAC;gBAClC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC3G,MAAM,eAAe,GAAG,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAA;gBAC9E,OAAO,eAAe,CAAC;YACzB,CAAC;iBACI,CAAC;gBACJ,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;;;;;;;KAcC;IACe,qBAAqB,CAAC,QAAa;;YACjD,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC7E,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC;gBAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACjE,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,IAA8B,EAAE,EAAE,CACvD,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CACpE,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AAjED,8BAiEC"}
@@ -2,8 +2,6 @@ import { InMemoryCache } from "../Memory/memory.operation";
2
2
  import Converter from "../Helper/Converter.helper";
3
3
  import { CryptoHelper } from "../Helper/Crypto.helper";
4
4
  import ResponseHelper from "../Helper/response.helper";
5
- import { SchemaTypes } from "../Schema/DataTypes.models";
6
- import schemaValidate from "../Schema/validator.models";
7
5
  import Aggregation from "../Services/Aggregation/Aggregation.Operation";
8
6
  import Collection from "../Services/Collection/collection.operation";
9
7
  import Database from "../Services/Database/database.operation";
@@ -21,34 +19,8 @@ declare const InstanceTypes: {
21
19
  ResponseHelper: typeof ResponseHelper;
22
20
  InMemoryCache: typeof InMemoryCache;
23
21
  };
24
- export { SchemaTypes, schemaValidate, AxioDB, InstanceTypes };
22
+ export { AxioDB, InstanceTypes };
25
23
  declare const _default: {
26
- SchemaTypes: {
27
- string: <TSchema = string>() => import("joi").StringSchema<TSchema>;
28
- number: <TSchema = number>() => import("joi").NumberSchema<TSchema>;
29
- boolean: <TSchema = boolean>() => import("joi").BooleanSchema<TSchema>;
30
- object: <TSchema = any, isStrict = false, T = TSchema>(schema?: import("joi").SchemaMap<T, isStrict>) => import("joi").ObjectSchema<TSchema>;
31
- array: <TSchema = any[]>() => import("joi").ArraySchema<TSchema>;
32
- date: <TSchema = Date>() => import("joi").DateSchema<TSchema>;
33
- binary: <TSchema = Buffer<ArrayBufferLike>>() => import("joi").BinarySchema<TSchema>;
34
- func: <TSchema = Function>() => import("joi").FunctionSchema<TSchema>;
35
- ref: (key: string, options?: import("joi").ReferenceOptions) => import("joi").Reference;
36
- any: <TSchema = any>() => import("joi").AnySchema<TSchema>;
37
- alphanum: () => import("joi").StringSchema<string>;
38
- email: (options?: import("joi").EmailOptions) => import("joi").StringSchema<string>;
39
- guid: (options?: import("joi").GuidOptions) => import("joi").StringSchema<string>;
40
- ip: (options?: import("joi").IpOptions) => import("joi").StringSchema<string>;
41
- uri: (options?: import("joi").UriOptions) => import("joi").StringSchema<string>;
42
- max: (limit: number | import("joi").Reference) => import("joi").NumberSchema<number>;
43
- min: (limit: number | import("joi").Reference) => import("joi").NumberSchema<number>;
44
- length: (limit: number | import("joi").Reference) => import("joi").StringSchema<string>;
45
- pattern: (regex: RegExp) => import("joi").StringSchema<string>;
46
- required: () => import("joi").Schema<any>;
47
- optional: () => import("joi").Schema<any>;
48
- allow: (values: any[]) => import("joi").Schema<any>;
49
- valid: (values: any[]) => import("joi").Schema<any>;
50
- };
51
- schemaValidate: typeof schemaValidate;
52
24
  AxioDB: typeof AxioDB;
53
25
  InstanceTypes: {
54
26
  Collection: typeof Collection;
package/lib/config/DB.js CHANGED
@@ -3,16 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InstanceTypes = exports.AxioDB = exports.schemaValidate = exports.SchemaTypes = void 0;
6
+ exports.InstanceTypes = exports.AxioDB = void 0;
7
7
  // Import All Required Sub Modules
8
8
  const memory_operation_1 = require("../Memory/memory.operation");
9
9
  const Converter_helper_1 = __importDefault(require("../Helper/Converter.helper"));
10
10
  const Crypto_helper_1 = require("../Helper/Crypto.helper");
11
11
  const response_helper_1 = __importDefault(require("../Helper/response.helper"));
12
- const DataTypes_models_1 = require("../Schema/DataTypes.models");
13
- Object.defineProperty(exports, "SchemaTypes", { enumerable: true, get: function () { return DataTypes_models_1.SchemaTypes; } });
14
- const validator_models_1 = __importDefault(require("../Schema/validator.models"));
15
- exports.schemaValidate = validator_models_1.default;
16
12
  const Aggregation_Operation_1 = __importDefault(require("../Services/Aggregation/Aggregation.Operation"));
17
13
  const collection_operation_1 = __importDefault(require("../Services/Collection/collection.operation"));
18
14
  const database_operation_1 = __importDefault(require("../Services/Database/database.operation"));
@@ -35,8 +31,6 @@ const InstanceTypes = {
35
31
  exports.InstanceTypes = InstanceTypes;
36
32
  // Export With All Sub Modules
37
33
  exports.default = {
38
- SchemaTypes: DataTypes_models_1.SchemaTypes,
39
- schemaValidate: validator_models_1.default,
40
34
  AxioDB: Indexation_operation_1.AxioDB,
41
35
  InstanceTypes,
42
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DB.js","sourceRoot":"","sources":["../../source/config/DB.ts"],"names":[],"mappings":";;;;;;AAAA,kCAAkC;AAClC,iEAA2D;AAC3D,kFAAmD;AACnD,2DAAuD;AACvD,gFAAuD;AACvD,iEAAyD;AA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a;CACd,CAAC"}
@@ -2,8 +2,6 @@ export interface CollectionMap {
2
2
  isCryptoEnabled: boolean;
3
3
  cryptoKey?: string;
4
4
  path: string;
5
- schema?: any;
6
- isSchema: boolean;
7
5
  }
8
6
  export interface DatabaseMap {
9
7
  DatabaseName: string;
@@ -29,18 +29,14 @@ const os_1 = __importDefault(require("os"));
29
29
  */
30
30
  function ReaderWithWorker(DataFilesList_1, encryptionKey_1, path_2, isEncrypted_1) {
31
31
  return __awaiter(this, arguments, void 0, function* (DataFilesList, encryptionKey, path, isEncrypted, storeFileName = false) {
32
- const numWorkers = Math.min(os_1.default.cpus().length, DataFilesList.length); // Use all CPU cores or file count, whichever is smaller
33
- const chunkSize = Math.ceil(DataFilesList.length / numWorkers);
34
32
  const workerPath = path_1.default.resolve(__dirname, "../engine/node", "WorkerForDataLoad.engine.js");
35
33
  const tasks = [];
36
- for (let i = 0; i < numWorkers; i++) {
37
- const start = i * chunkSize;
38
- const end = Math.min(start + chunkSize, DataFilesList.length);
39
- const dataChunk = DataFilesList.slice(start, end);
34
+ // Only spawn one worker if fewer than 5000 files
35
+ if (DataFilesList.length < 5000) {
40
36
  tasks.push(new Promise((resolve, reject) => {
41
37
  const worker = new worker_threads_1.Worker(workerPath, {
42
38
  workerData: {
43
- chunk: dataChunk,
39
+ chunk: DataFilesList,
44
40
  encryptionKey: encryptionKey,
45
41
  path: path,
46
42
  isEncrypted: isEncrypted,
@@ -55,6 +51,31 @@ function ReaderWithWorker(DataFilesList_1, encryptionKey_1, path_2, isEncrypted_
55
51
  });
56
52
  }));
57
53
  }
54
+ else {
55
+ // For 5000+ files, divide work among multiple workers
56
+ for (let i = 0; i < Math.min(os_1.default.cpus().length, DataFilesList.length); i++) {
57
+ const start = i * Math.ceil(DataFilesList.length / Math.min(os_1.default.cpus().length, DataFilesList.length));
58
+ const end = Math.min(start + Math.ceil(DataFilesList.length / Math.min(os_1.default.cpus().length, DataFilesList.length)), DataFilesList.length);
59
+ const dataChunk = DataFilesList.slice(start, end);
60
+ tasks.push(new Promise((resolve, reject) => {
61
+ const worker = new worker_threads_1.Worker(workerPath, {
62
+ workerData: {
63
+ chunk: dataChunk,
64
+ encryptionKey: encryptionKey,
65
+ path: path,
66
+ isEncrypted: isEncrypted,
67
+ storeFileName: storeFileName,
68
+ },
69
+ });
70
+ worker.on("message", resolve);
71
+ worker.on("error", reject);
72
+ worker.on("exit", (code) => {
73
+ if (code !== 0)
74
+ reject(new Error(`Worker stopped with code ${code}`));
75
+ });
76
+ }));
77
+ }
78
+ }
58
79
  const results = yield Promise.all(tasks);
59
80
  return results.flat();
60
81
  });