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.
- package/README.md +16 -17
- package/lib/Services/CRUD Operation/Create.operation.js +1 -1
- package/lib/Services/CRUD Operation/Create.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Delete.operation.js +17 -12
- package/lib/Services/CRUD Operation/Delete.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Reader.operation.js +27 -14
- package/lib/Services/CRUD Operation/Reader.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Update.operation.d.ts +1 -3
- package/lib/Services/CRUD Operation/Update.operation.js +20 -68
- package/lib/Services/CRUD Operation/Update.operation.js.map +1 -1
- package/lib/Services/Collection/collection.operation.d.ts +23 -3
- package/lib/Services/Collection/collection.operation.js +34 -22
- package/lib/Services/Collection/collection.operation.js.map +1 -1
- package/lib/Services/Database/database.operation.d.ts +27 -3
- package/lib/Services/Database/database.operation.js +55 -11
- package/lib/Services/Database/database.operation.js.map +1 -1
- package/lib/Services/Index/Index.service.d.ts +125 -0
- package/lib/Services/Index/Index.service.js +231 -0
- package/lib/Services/Index/Index.service.js.map +1 -0
- package/lib/Services/Index/InsertIndex.service.d.ts +34 -0
- package/lib/Services/Index/InsertIndex.service.js +79 -0
- package/lib/Services/Index/InsertIndex.service.js.map +1 -0
- package/lib/Services/Index/ReadIndex.service.d.ts +44 -0
- package/lib/Services/Index/ReadIndex.service.js +81 -0
- package/lib/Services/Index/ReadIndex.service.js.map +1 -0
- package/lib/config/DB.d.ts +1 -29
- package/lib/config/DB.js +1 -7
- package/lib/config/DB.js.map +1 -1
- package/lib/config/Interfaces/Operation/database.operation.interface.d.ts +0 -2
- package/lib/utility/BufferLoaderWithWorker.utils.js +28 -7
- package/lib/utility/BufferLoaderWithWorker.utils.js.map +1 -1
- package/lib/utility/Searcher.utils.js +1 -1
- package/package.json +1 -1
- package/lib/Schema/DataTypes.models.d.ts +0 -26
- package/lib/Schema/DataTypes.models.js +0 -36
- package/lib/Schema/DataTypes.models.js.map +0 -1
- package/lib/Schema/validator.models.d.ts +0 -10
- package/lib/Schema/validator.models.js +0 -51
- package/lib/Schema/validator.models.js.map +0 -1
|
@@ -20,26 +20,17 @@ const Delete_operation_1 = __importDefault(require("../CRUD Operation/Delete.ope
|
|
|
20
20
|
const Update_operation_1 = __importDefault(require("../CRUD Operation/Update.operation"));
|
|
21
21
|
const Aggregation_Operation_1 = __importDefault(require("../Aggregation/Aggregation.Operation"));
|
|
22
22
|
const outers_1 = require("outers");
|
|
23
|
-
// Validator
|
|
24
|
-
const validator_models_1 = __importDefault(require("../../Schema/validator.models"));
|
|
25
23
|
// Converter
|
|
26
24
|
const Converter_helper_1 = __importDefault(require("../../Helper/Converter.helper"));
|
|
27
|
-
const DataTypes_models_1 = require("../../Schema/DataTypes.models");
|
|
28
25
|
const FolderManager_1 = __importDefault(require("../../engine/Filesystem/FolderManager"));
|
|
26
|
+
const InsertIndex_service_1 = __importDefault(require("../Index/InsertIndex.service"));
|
|
29
27
|
/**
|
|
30
28
|
* Represents a collection inside a database.
|
|
31
29
|
*/
|
|
32
30
|
class Collection {
|
|
33
|
-
constructor(name, path,
|
|
31
|
+
constructor(name, path, isEncrypted = false, cryptoInstance, encryptionKey) {
|
|
34
32
|
this.name = name;
|
|
35
33
|
this.path = path;
|
|
36
|
-
if (isSchemaNeeded == true && !schema) {
|
|
37
|
-
throw new Error("Schema is required when isSchemaNeeded is true");
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.isSchemaNeeded = isSchemaNeeded;
|
|
41
|
-
this.schema = schema;
|
|
42
|
-
}
|
|
43
34
|
this.isEncrypted = isEncrypted;
|
|
44
35
|
this.cryptoInstance = cryptoInstance;
|
|
45
36
|
this.Converter = new Converter_helper_1.default();
|
|
@@ -47,6 +38,7 @@ class Collection {
|
|
|
47
38
|
this.encryptionKey = encryptionKey;
|
|
48
39
|
// Initialize the Insertion class
|
|
49
40
|
this.Insertion = new Create_operation_1.default(this.name, this.path);
|
|
41
|
+
this.IndexManager = new InsertIndex_service_1.default(this.path);
|
|
50
42
|
}
|
|
51
43
|
/**
|
|
52
44
|
* Get Numbers of Documents in the Collection
|
|
@@ -107,6 +99,35 @@ class Collection {
|
|
|
107
99
|
}
|
|
108
100
|
});
|
|
109
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new index on the specified fields by delegating to the IndexManager.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This method accepts one or more field names and forwards them to IndexManager.createIndex.
|
|
107
|
+
* Index creation behavior (such as uniqueness, ordering, or persistence) is determined by the IndexManager implementation.
|
|
108
|
+
*
|
|
109
|
+
* @param fieldNames - One or more field names that should be included in the new index.
|
|
110
|
+
* @returns A promise that resolves with the result returned by IndexManager.createIndex.
|
|
111
|
+
* @throws Any errors thrown by IndexManager.createIndex (for example, validation or persistence errors) are propagated.
|
|
112
|
+
*/
|
|
113
|
+
newIndex(...fieldNames) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
return yield this.IndexManager.createIndex(...fieldNames);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Drops an index by name from the collection.
|
|
120
|
+
*
|
|
121
|
+
* @param indexName - The name of the index to drop.
|
|
122
|
+
* @returns A promise that resolves with the result returned by IndexManager.dropIndex.
|
|
123
|
+
* @throws Will throw an error if the drop operation fails (for example, if the index does not exist
|
|
124
|
+
* or if the caller lacks necessary permissions).
|
|
125
|
+
*/
|
|
126
|
+
dropIndex(indexName) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return yield this.IndexManager.dropIndex(indexName);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
110
131
|
/**
|
|
111
132
|
* Inserts a document into the collection.
|
|
112
133
|
* @param {object} data - The data to be inserted.
|
|
@@ -125,18 +146,9 @@ class Collection {
|
|
|
125
146
|
// Add the documentId to the data
|
|
126
147
|
const documentId = yield this.Insertion.generateUniqueDocumentId();
|
|
127
148
|
data.documentId = documentId;
|
|
149
|
+
yield this.IndexManager.InsertToIndex(data);
|
|
128
150
|
// Insert the updatedAt field in schema & data
|
|
129
151
|
data.updatedAt = this.updatedAt;
|
|
130
|
-
if (this.isSchemaNeeded == true) {
|
|
131
|
-
this.schema.updatedAt = DataTypes_models_1.SchemaTypes.date().required();
|
|
132
|
-
this.schema.documentId = DataTypes_models_1.SchemaTypes.string().required();
|
|
133
|
-
// Validate the data
|
|
134
|
-
const validator = yield (0, validator_models_1.default)(this.schema, data, false);
|
|
135
|
-
if (validator === null || validator === void 0 ? void 0 : validator.details) {
|
|
136
|
-
outers_1.Console.red("Validation Error", validator.details);
|
|
137
|
-
return new response_helper_1.default().Error(validator.details);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
152
|
// Encrypt the data if crypto is enabled
|
|
141
153
|
if (this.cryptoInstance && this.isEncrypted) {
|
|
142
154
|
data = yield this.cryptoInstance.encrypt(this.Converter.ToString(data));
|
|
@@ -235,7 +247,7 @@ class Collection {
|
|
|
235
247
|
if (!query) {
|
|
236
248
|
throw new Error("Query cannot be empty");
|
|
237
249
|
}
|
|
238
|
-
return new Update_operation_1.default(this.name, this.path, query, this.
|
|
250
|
+
return new Update_operation_1.default(this.name, this.path, query, this.isEncrypted, this.encryptionKey);
|
|
239
251
|
}
|
|
240
252
|
}
|
|
241
253
|
exports.default = Collection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.operation.js","sourceRoot":"","sources":["../../../source/Services/Collection/collection.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,mFAA0D;AAC1D,aAAa;AACb,0FAA2D;AAC3D,0FAAwD;AACxD,0FAAiE;AACjE,0FAAiE;AACjE,iGAA+D;AAE/D,
|
|
1
|
+
{"version":3,"file":"collection.operation.js","sourceRoot":"","sources":["../../../source/Services/Collection/collection.operation.ts"],"names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EACT,KAAK,EACL,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;CACF;AA/QD,6BA+QC"}
|
|
@@ -16,11 +16,9 @@ export default class Database {
|
|
|
16
16
|
* @param {string} collectionName - Name of the collection.
|
|
17
17
|
* @param {boolean} crypto - Enable crypto for the collection.
|
|
18
18
|
* @param {string} key - Key for crypto.
|
|
19
|
-
* @param {boolean} isSchemaNeeded - Whether the collection requires a schema.
|
|
20
|
-
* @param {object} schema - Schema of the collection.
|
|
21
19
|
* @returns {Promise<AxioDB>} - Returns the instance of AxioDB.
|
|
22
20
|
*/
|
|
23
|
-
createCollection(collectionName: string, crypto?: boolean, key?: string | undefined
|
|
21
|
+
createCollection(collectionName: string, crypto?: boolean, key?: string | undefined): Promise<Collection>;
|
|
24
22
|
/**
|
|
25
23
|
* Checks if a collection exists in the database.
|
|
26
24
|
* @param {string} collectionName - Name of the collection to check.
|
|
@@ -40,6 +38,32 @@ export default class Database {
|
|
|
40
38
|
* @throws {Error} - Throws an error if the database does not exist.
|
|
41
39
|
*/
|
|
42
40
|
getCollectionInfo(): Promise<SuccessInterface | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Removes the metadata entry for a collection from the collection metadata file.
|
|
43
|
+
*
|
|
44
|
+
* Reads the JSON file located at `${this.path}/collection.meta`, validates that the
|
|
45
|
+
* file exists and contains an array of collection metadata objects, removes any entry
|
|
46
|
+
* whose `name` matches the provided `collectionName`, and writes the updated array
|
|
47
|
+
* back to the same file.
|
|
48
|
+
*
|
|
49
|
+
* The method returns a SuccessInterface on successful removal (even if no matching
|
|
50
|
+
* collection was found) or an ErrorInterface describing the failure.
|
|
51
|
+
*
|
|
52
|
+
* @param collectionName - The name of the collection whose metadata should be removed.
|
|
53
|
+
* @returns A promise that resolves to SuccessInterface on success or ErrorInterface on failure.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* - If the metadata file does not exist, an ErrorInterface is returned.
|
|
57
|
+
* - If the metadata file cannot be parsed as a JSON array, an ErrorInterface is returned.
|
|
58
|
+
* - This method performs I/O using a FileManager instance and uses this.ResponseHelper
|
|
59
|
+
* to construct success/error responses. It does not throw; failures are reported via
|
|
60
|
+
* the returned ErrorInterface.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Remove the "users" collection metadata
|
|
64
|
+
* await db.dropCollectionMetadata("users");
|
|
65
|
+
*/
|
|
66
|
+
dropCollectionMetadata(collectionName: string): Promise<SuccessInterface | ErrorInterface>;
|
|
43
67
|
/**
|
|
44
68
|
* Adds metadata for a collection to the collection metadata file.
|
|
45
69
|
*
|
|
@@ -21,6 +21,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
21
|
const Crypto_helper_1 = require("../../Helper/Crypto.helper");
|
|
22
22
|
const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
|
|
23
23
|
const outers_1 = require("outers");
|
|
24
|
+
const Index_service_1 = require("../Index/Index.service");
|
|
24
25
|
/**
|
|
25
26
|
* Represents a database instance.
|
|
26
27
|
* This class provides methods to create, delete, and manage collections within a database.
|
|
@@ -38,19 +39,15 @@ class Database {
|
|
|
38
39
|
* @param {string} collectionName - Name of the collection.
|
|
39
40
|
* @param {boolean} crypto - Enable crypto for the collection.
|
|
40
41
|
* @param {string} key - Key for crypto.
|
|
41
|
-
* @param {boolean} isSchemaNeeded - Whether the collection requires a schema.
|
|
42
|
-
* @param {object} schema - Schema of the collection.
|
|
43
42
|
* @returns {Promise<AxioDB>} - Returns the instance of AxioDB.
|
|
44
43
|
*/
|
|
45
44
|
createCollection(collectionName_1) {
|
|
46
|
-
return __awaiter(this, arguments, void 0, function* (collectionName, crypto = false, key
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* (collectionName, crypto = false, key) {
|
|
47
46
|
// Check if the collection already exists
|
|
48
47
|
const collectionExists = yield this.folderManager.DirectoryExists(path_1.default.join(this.path, collectionName));
|
|
49
48
|
const collectionPath = path_1.default.join(this.path, collectionName);
|
|
50
49
|
const CollectionMeta = yield this.getCollectionMetaDetails(collectionName);
|
|
51
50
|
if (CollectionMeta) {
|
|
52
|
-
isSchemaNeeded = CollectionMeta.isSchemaNeeded;
|
|
53
|
-
schema = CollectionMeta.schema;
|
|
54
51
|
crypto = CollectionMeta.isEncrypted
|
|
55
52
|
? Boolean(CollectionMeta.isEncrypted)
|
|
56
53
|
: false;
|
|
@@ -61,29 +58,28 @@ class Database {
|
|
|
61
58
|
yield this.folderManager.CreateDirectory(collectionPath);
|
|
62
59
|
console.log(`Collection Created: ${collectionPath}`);
|
|
63
60
|
}
|
|
61
|
+
// Create AutoIndex meta for the collection
|
|
62
|
+
const Index = new Index_service_1.IndexManager(collectionPath);
|
|
63
|
+
yield Index.generateIndexMeta();
|
|
64
64
|
// if crypto is enabled, hash the collection name
|
|
65
65
|
if (crypto === true) {
|
|
66
66
|
const newCryptoInstance = new Crypto_helper_1.CryptoHelper(key);
|
|
67
|
-
const collection = new collection_operation_1.default(collectionName, collectionPath,
|
|
67
|
+
const collection = new collection_operation_1.default(collectionName, collectionPath, crypto, newCryptoInstance, key);
|
|
68
68
|
// Store collection metadata in the collectionMap
|
|
69
69
|
yield this.AddCollectionMetadata({
|
|
70
70
|
name: collectionName,
|
|
71
71
|
path: collectionPath,
|
|
72
|
-
isSchemaNeeded: isSchemaNeeded === undefined ? false : isSchemaNeeded,
|
|
73
|
-
schema: schema === undefined ? {} : schema,
|
|
74
72
|
encryptionKey: key === undefined ? "" : key,
|
|
75
73
|
isEncrypted: crypto === undefined ? false : crypto,
|
|
76
74
|
});
|
|
77
75
|
return collection;
|
|
78
76
|
}
|
|
79
77
|
else {
|
|
80
|
-
const collection = new collection_operation_1.default(collectionName, collectionPath
|
|
78
|
+
const collection = new collection_operation_1.default(collectionName, collectionPath);
|
|
81
79
|
// Store collection metadata in the collectionMap
|
|
82
80
|
yield this.AddCollectionMetadata({
|
|
83
81
|
name: collectionName,
|
|
84
82
|
path: collectionPath,
|
|
85
|
-
isSchemaNeeded: isSchemaNeeded === undefined ? false : isSchemaNeeded,
|
|
86
|
-
schema: schema === undefined ? {} : schema,
|
|
87
83
|
encryptionKey: key === undefined ? "" : key,
|
|
88
84
|
isEncrypted: crypto === undefined ? false : crypto,
|
|
89
85
|
});
|
|
@@ -114,6 +110,11 @@ class Database {
|
|
|
114
110
|
const collectionPath = path_1.default.join(this.path, collectionName);
|
|
115
111
|
const exists = yield this.folderManager.DirectoryExists(collectionPath);
|
|
116
112
|
if (exists.statusCode === outers_1.StatusCodes.OK) {
|
|
113
|
+
// Remove collection metadata
|
|
114
|
+
const status = yield this.dropCollectionMetadata(collectionName);
|
|
115
|
+
if (status && "statusCode" in status && status.statusCode !== 200) {
|
|
116
|
+
return status;
|
|
117
|
+
}
|
|
117
118
|
yield this.folderManager.DeleteDirectory(collectionPath);
|
|
118
119
|
return this.ResponseHelper.Success(`Collection: ${collectionName} deleted successfully`);
|
|
119
120
|
}
|
|
@@ -150,6 +151,49 @@ class Database {
|
|
|
150
151
|
}
|
|
151
152
|
});
|
|
152
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Removes the metadata entry for a collection from the collection metadata file.
|
|
156
|
+
*
|
|
157
|
+
* Reads the JSON file located at `${this.path}/collection.meta`, validates that the
|
|
158
|
+
* file exists and contains an array of collection metadata objects, removes any entry
|
|
159
|
+
* whose `name` matches the provided `collectionName`, and writes the updated array
|
|
160
|
+
* back to the same file.
|
|
161
|
+
*
|
|
162
|
+
* The method returns a SuccessInterface on successful removal (even if no matching
|
|
163
|
+
* collection was found) or an ErrorInterface describing the failure.
|
|
164
|
+
*
|
|
165
|
+
* @param collectionName - The name of the collection whose metadata should be removed.
|
|
166
|
+
* @returns A promise that resolves to SuccessInterface on success or ErrorInterface on failure.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* - If the metadata file does not exist, an ErrorInterface is returned.
|
|
170
|
+
* - If the metadata file cannot be parsed as a JSON array, an ErrorInterface is returned.
|
|
171
|
+
* - This method performs I/O using a FileManager instance and uses this.ResponseHelper
|
|
172
|
+
* to construct success/error responses. It does not throw; failures are reported via
|
|
173
|
+
* the returned ErrorInterface.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // Remove the "users" collection metadata
|
|
177
|
+
* await db.dropCollectionMetadata("users");
|
|
178
|
+
*/
|
|
179
|
+
dropCollectionMetadata(collectionName) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const FileManagement = new FileManager_1.default();
|
|
182
|
+
const isFileExist = yield FileManagement.FileExists(`${this.path}/collection.meta`);
|
|
183
|
+
if (isFileExist.status == false) {
|
|
184
|
+
return this.ResponseHelper.Error("Collection metadata file does not exist");
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const FullData = JSON.parse((yield FileManagement.ReadFile(`${this.path}/collection.meta`)).data);
|
|
188
|
+
if (!Array.isArray(FullData)) {
|
|
189
|
+
return this.ResponseHelper.Error("Invalid collection metadata format");
|
|
190
|
+
}
|
|
191
|
+
const UpdatedData = FullData.filter((data) => data.name !== collectionName);
|
|
192
|
+
yield FileManagement.WriteFile(`${this.path}/collection.meta`, JSON.stringify(UpdatedData));
|
|
193
|
+
return this.ResponseHelper.Success(`Collection metadata for ${collectionName} dropped successfully`);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
153
197
|
/**
|
|
154
198
|
* Adds metadata for a collection to the collection metadata file.
|
|
155
199
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.operation.js","sourceRoot":"","sources":["../../../source/Services/Database/database.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,8FAA4D;AAC5D,sFAA8D;AAC9D,0FAAkE;AAClE,gDAAwB;AAExB,qBAAqB;AACrB,8DAA0D;AAC1D,mFAA0D;AAC1D,mCAAqC;
|
|
1
|
+
{"version":3,"file":"database.operation.js","sourceRoot":"","sources":["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AM,IAAI,KAAK,EAAE,CAAC;gBAChC,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,CAAC,MAAM,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,IAAI,CACrE,CAAC;YACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAClC,CAAC,IAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAC3D,CAAC;YACF,OAAO,cAAc,CAAC;QACxB,CAAC;KAAA;CACF;AAxSD,2BAwSC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
|
|
2
|
+
import FileManager from "../../engine/Filesystem/FileManager";
|
|
3
|
+
import FolderManager from "../../engine/Filesystem/FolderManager";
|
|
4
|
+
import Converter from "../../Helper/Converter.helper";
|
|
5
|
+
import ResponseHelper from "../../Helper/response.helper";
|
|
6
|
+
export declare class IndexManager {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly indexFolderPath: string;
|
|
9
|
+
readonly indexMetaPath: string;
|
|
10
|
+
readonly fileManager: FileManager;
|
|
11
|
+
readonly folderManager: FolderManager;
|
|
12
|
+
readonly converter: Converter;
|
|
13
|
+
readonly ResponseHelper: ResponseHelper;
|
|
14
|
+
constructor(path: string);
|
|
15
|
+
/**
|
|
16
|
+
* Create one or more index files and register them in the index metadata.
|
|
17
|
+
*
|
|
18
|
+
* For each supplied field name this method:
|
|
19
|
+
* 1. Determines the index file path as `${indexName}.axiodb` inside the configured index folder.
|
|
20
|
+
* 2. Checks whether the index file already exists. If it does not, creates the file with an empty
|
|
21
|
+
* index structure ({ fieldName, indexEntries: [] }).
|
|
22
|
+
* 3. Reads the index metadata file (index.meta.json), parses it, and if an entry for the index
|
|
23
|
+
* field does not already exist, appends a metadata record `{ indexFieldName, fileName, path }`
|
|
24
|
+
* and writes the metadata file back.
|
|
25
|
+
*
|
|
26
|
+
* Side effects:
|
|
27
|
+
* - Writes new index files to disk via `fileManager.WriteFile`.
|
|
28
|
+
* - Reads and updates the index metadata file via `fileManager.ReadFile` / `WriteFile`.
|
|
29
|
+
* - Uses the configured `converter` to serialize/deserialize index and metadata content.
|
|
30
|
+
*
|
|
31
|
+
* Notes:
|
|
32
|
+
* - The operation is not atomic: some indexes may be created while others fail. The method will
|
|
33
|
+
* collect created and failed index names and include them in the returned response.
|
|
34
|
+
* - A failure is recorded for a field when the index file already exists, when the index already
|
|
35
|
+
* exists in the metadata, or when reading/writing the metadata file fails.
|
|
36
|
+
* - The method relies on `indexFolderPath`, `indexMetaPath`, `fileManager`, and `converter`
|
|
37
|
+
* being correctly configured and available on the instance.
|
|
38
|
+
*
|
|
39
|
+
* @param fieldNames - One or more field names for which to create indexes.
|
|
40
|
+
* @returns A promise that resolves to either:
|
|
41
|
+
* - SuccessInterface: indicates which indexes were created and which already existed / failed,
|
|
42
|
+
* typically containing a human-readable message listing affected and existing indexes.
|
|
43
|
+
* - ErrorInterface: returned when underlying file/IO operations fail in a way that prevents
|
|
44
|
+
* producing the expected success response.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Create a single index
|
|
48
|
+
* await service.createIndex('email');
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Create multiple indexes
|
|
52
|
+
* await service.createIndex('email', 'username', 'createdAt');
|
|
53
|
+
*/
|
|
54
|
+
createIndex(...fieldNames: string[]): Promise<SuccessInterface | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes an index file and removes its entry from the index metadata.
|
|
57
|
+
*
|
|
58
|
+
* This asynchronous method attempts to delete the index file located at
|
|
59
|
+
* `${this.indexFolderPath}/${indexName}.axiodb`. If the file exists it is removed,
|
|
60
|
+
* and the index metadata file at `this.indexMetaPath` is read and updated by
|
|
61
|
+
* filtering out the metadata entry whose `indexFieldName` matches `indexName`.
|
|
62
|
+
* The metadata update is performed only if the metadata file can be read successfully.
|
|
63
|
+
*
|
|
64
|
+
* @param indexName - The name of the index to delete (without extension).
|
|
65
|
+
* @returns A Promise that resolves to a SuccessInterface when the index was deleted
|
|
66
|
+
* (and metadata updated when possible), or an ErrorInterface when the
|
|
67
|
+
* specified index does not exist.
|
|
68
|
+
*
|
|
69
|
+
* @async
|
|
70
|
+
* @remarks
|
|
71
|
+
* - Side effects: removes a file from the file system and may modify the index metadata file.
|
|
72
|
+
* - Uses injected helpers: `fileManager` for filesystem operations, `converter` for
|
|
73
|
+
* (de)serialization of metadata, and `ResponseHelper` to construct the returned result.
|
|
74
|
+
* - If the metadata file cannot be read, the method still succeeds after deleting the index file.
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} May propagate errors from underlying file operations if those utilities throw.
|
|
77
|
+
*/
|
|
78
|
+
dropIndex(indexName: string): Promise<SuccessInterface | ErrorInterface>;
|
|
79
|
+
/**
|
|
80
|
+
* Ensures the index folder and the index metadata file exist, creating them if necessary.
|
|
81
|
+
*
|
|
82
|
+
* This asynchronous method performs the following steps:
|
|
83
|
+
* 1. Checks whether the index folder at `this.indexFolderPath` exists; if not, creates it.
|
|
84
|
+
* 2. Checks whether the index metadata file at `this.indexMetaPath` exists; if not:
|
|
85
|
+
* a. Constructs a default index metadata entry for a unique "documentId" index:
|
|
86
|
+
* - indexFieldName: "documentId"
|
|
87
|
+
* - fileName: "documentId.axiodb"
|
|
88
|
+
* - path: `${this.indexFolderPath}/documentId.axiodb`
|
|
89
|
+
* - unique: true
|
|
90
|
+
* b. Calls `this.createIndex("documentId")` to create the underlying index file/structure.
|
|
91
|
+
* c. Writes the metadata array to `this.indexMetaPath` using `this.converter.ToString(...)`.
|
|
92
|
+
*
|
|
93
|
+
* The operation is idempotent: if the folder or metadata file already exist, no changes are made.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* - This method performs filesystem modifications via `folderManager` and `fileManager`.
|
|
97
|
+
* - Any errors thrown by `folderManager`, `fileManager`, `converter`, or `createIndex` will propagate to the caller.
|
|
98
|
+
* - Callers should `await` this method to ensure the initialization is complete before proceeding.
|
|
99
|
+
*
|
|
100
|
+
* @returns A Promise that resolves when initialization is complete.
|
|
101
|
+
*
|
|
102
|
+
* @throws Will reject if directory creation, file checks/writes, conversion, or index creation fails.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Ensure index folder and metadata exist before using the index service
|
|
106
|
+
* await indexService.generateIndexMeta();
|
|
107
|
+
*/
|
|
108
|
+
generateIndexMeta(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Finds index metadata entries that correspond to properties present on the provided document.
|
|
111
|
+
*
|
|
112
|
+
* Reads the index metadata file at `this.indexMetaPath`, converts its content into an object,
|
|
113
|
+
* and returns the subset of metadata entries whose `indexFieldName` is an own property of `doc`.
|
|
114
|
+
*
|
|
115
|
+
* @param doc - The document to check for matching index fields. The function tests own properties
|
|
116
|
+
* (via `Object.prototype.hasOwnProperty.call`) rather than inherited properties.
|
|
117
|
+
* @returns A Promise that resolves to an array of matching index metadata entries, or `undefined`
|
|
118
|
+
* if the index metadata file could not be successfully read. The array may be empty if
|
|
119
|
+
* no metadata entries match.
|
|
120
|
+
*
|
|
121
|
+
* @throws May propagate errors from `fileManager.ReadFile` or `converter.ToObject` if those
|
|
122
|
+
* operations throw or reject.
|
|
123
|
+
*/
|
|
124
|
+
protected findMatchingIndexMeta(doc: any): Promise<any[] | undefined>;
|
|
125
|
+
}
|