axiodb 1.3.6 → 1.3.8
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 +72 -2
- package/lib/Operation/CRUD Operation/Delete.operation.d.ts +84 -0
- package/lib/Operation/CRUD Operation/Delete.operation.js +321 -0
- package/lib/Operation/CRUD Operation/Delete.operation.js.map +1 -0
- package/lib/Operation/CRUD Operation/Reader.operation.d.ts +8 -0
- package/lib/Operation/CRUD Operation/Reader.operation.js +25 -2
- package/lib/Operation/CRUD Operation/Reader.operation.js.map +1 -1
- package/lib/Operation/CRUD Operation/Update.operation.d.ts +3 -0
- package/lib/Operation/CRUD Operation/Update.operation.js +9 -0
- package/lib/Operation/CRUD Operation/Update.operation.js.map +1 -0
- package/lib/Operation/Collection/collection.operation.d.ts +15 -0
- package/lib/Operation/Collection/collection.operation.js +23 -0
- package/lib/Operation/Collection/collection.operation.js.map +1 -1
- package/lib/utils/HashMapSearch.utils.d.ts +12 -10
- package/lib/utils/HashMapSearch.utils.js +45 -32
- package/lib/utils/HashMapSearch.utils.js.map +1 -1
- package/lib/utils/SortData.utils.d.ts +1 -1
- package/lib/utils/SortData.utils.js +19 -8
- package/lib/utils/SortData.utils.js.map +1 -1
- package/package.json +2 -5
- package/lib/server/Fastify.d.ts +0 -14
- package/lib/server/Fastify.js +0 -42
- package/lib/server/Fastify.js.map +0 -1
- package/lib/server/Router/Router.d.ts +0 -0
- package/lib/server/Router/Router.js +0 -2
- package/lib/server/Router/Router.js.map +0 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install axiodb@latest --save
|
|
|
25
25
|
### CommonJS
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
const { AxioDB,
|
|
28
|
+
const { AxioDB, SchemaTypes } = require("axiodb");
|
|
29
29
|
|
|
30
30
|
// Initialize AxioDB
|
|
31
31
|
const db = new AxioDB();
|
|
@@ -90,6 +90,72 @@ db.createDB("myDatabase").then(async (database) => {
|
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
### Additional Features
|
|
94
|
+
|
|
95
|
+
#### Creating Multiple Databases and Collections & Deletations of Database
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
const { AxioDB, SchemaTypes } = require("axiodb");
|
|
99
|
+
|
|
100
|
+
const db = new AxioDB();
|
|
101
|
+
|
|
102
|
+
const insertCode = async () => {
|
|
103
|
+
const schema = {
|
|
104
|
+
name: SchemaTypes.string().required().max(15),
|
|
105
|
+
age: SchemaTypes.number().required().min(18),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const DB1 = await db.createDB("DB1");
|
|
109
|
+
const DB2 = await db.createDB("DB2");
|
|
110
|
+
const collection = await DB1.createCollection(
|
|
111
|
+
"collection1",
|
|
112
|
+
schema,
|
|
113
|
+
true,
|
|
114
|
+
"Ankan",
|
|
115
|
+
);
|
|
116
|
+
const collection2 = await DB1.createCollection("collection2", schema, false);
|
|
117
|
+
|
|
118
|
+
// Insert data
|
|
119
|
+
for (let i = 0; i < 300; i++) {
|
|
120
|
+
await collection
|
|
121
|
+
.insert({
|
|
122
|
+
name: `Ankan${i}`,
|
|
123
|
+
age: i + 18,
|
|
124
|
+
})
|
|
125
|
+
.then((data) => {
|
|
126
|
+
console.log(data);
|
|
127
|
+
collection
|
|
128
|
+
.insert({
|
|
129
|
+
name: `Saha${i}`,
|
|
130
|
+
age: i + 18,
|
|
131
|
+
})
|
|
132
|
+
.then(console.log);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Query data
|
|
137
|
+
collection
|
|
138
|
+
.query({})
|
|
139
|
+
.Sort({ age: -1 })
|
|
140
|
+
.Skip(2)
|
|
141
|
+
.Limit(10)
|
|
142
|
+
.exec()
|
|
143
|
+
.then(console.log);
|
|
144
|
+
|
|
145
|
+
// Delete collection
|
|
146
|
+
DB1.deleteCollection("collection1").then(console.log);
|
|
147
|
+
|
|
148
|
+
// Get collection info
|
|
149
|
+
DB1.getCollectionInfo().then(console.log);
|
|
150
|
+
|
|
151
|
+
// Delete databases
|
|
152
|
+
db.deleteDatabase("DB2").then(console.log);
|
|
153
|
+
db.deleteDatabase("DB1").then(console.log);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
insertCode();
|
|
157
|
+
```
|
|
158
|
+
|
|
93
159
|
## Encryption
|
|
94
160
|
|
|
95
161
|
AxioDB supports optional encryption to protect sensitive data stored in your JSON files. You can enable encryption when creating a collection by passing the `crypto` flag and an encryption key.
|
|
@@ -97,7 +163,7 @@ AxioDB supports optional encryption to protect sensitive data stored in your JSO
|
|
|
97
163
|
### Example with Encryption
|
|
98
164
|
|
|
99
165
|
```js
|
|
100
|
-
import { AxioDB,
|
|
166
|
+
import { AxioDB, SchemaTypes } from "axiodb";
|
|
101
167
|
|
|
102
168
|
// Initialize AxioDB
|
|
103
169
|
const db = new AxioDB();
|
|
@@ -153,8 +219,12 @@ These pain points motivated me to develop AxioDB, a DBMS Npm Package that addres
|
|
|
153
219
|
### AxioDB
|
|
154
220
|
|
|
155
221
|
- **createDB(dbName: string): Promise<Database>**
|
|
222
|
+
|
|
156
223
|
- Creates a new database with the specified name.
|
|
157
224
|
|
|
225
|
+
- **deleteDatabase(dbName: string): Promise<SuccessInterface | ErrorInterface>**
|
|
226
|
+
- Deletes the specified database.
|
|
227
|
+
|
|
158
228
|
### Database
|
|
159
229
|
|
|
160
230
|
- **createCollection(collectionName: string, schema: object, crypto?: boolean, key?: string): Promise<Collection>**
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
|
|
2
|
+
/**
|
|
3
|
+
* The DeleteOperation class is used to delete a document from a collection.
|
|
4
|
+
* This class provides methods to delete a single document that matches the base query.
|
|
5
|
+
*/
|
|
6
|
+
export default class DeleteOperation {
|
|
7
|
+
protected readonly collectionName: string;
|
|
8
|
+
private readonly baseQuery;
|
|
9
|
+
private readonly path;
|
|
10
|
+
private readonly isEncrypted;
|
|
11
|
+
private readonly encryptionKey;
|
|
12
|
+
private readonly ResponseHelper;
|
|
13
|
+
private readonly cryptoInstance?;
|
|
14
|
+
private readonly Converter;
|
|
15
|
+
private allDataWithFileName;
|
|
16
|
+
private sort;
|
|
17
|
+
constructor(collectionName: string, path: string, baseQuery: object | any, isEncrypted?: boolean, encryptionKey?: string);
|
|
18
|
+
/**
|
|
19
|
+
* Deletes a single document that matches the base query.
|
|
20
|
+
*
|
|
21
|
+
* This method:
|
|
22
|
+
* 1. Loads all raw data from buffers
|
|
23
|
+
* 2. Searches for documents matching the base query
|
|
24
|
+
* 3. Selects the first matching document (applying sort if provided)
|
|
25
|
+
* 4. Deletes the file associated with the selected document
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<object>} A response object containing either:
|
|
28
|
+
* - Success: { message: "Data deleted successfully", deleteData: object }
|
|
29
|
+
* - Error: An error message if no data found or deletion fails
|
|
30
|
+
*
|
|
31
|
+
* @throws Will propagate any errors from underlying operations
|
|
32
|
+
*/
|
|
33
|
+
deleteOne(): Promise<SuccessInterface | ErrorInterface>;
|
|
34
|
+
/**
|
|
35
|
+
* Deletes multiple documents that match the base query.
|
|
36
|
+
*
|
|
37
|
+
* This method:
|
|
38
|
+
* 1. Searches for documents matching the base query
|
|
39
|
+
* 2. Deletes each matching file
|
|
40
|
+
* 3. Returns success with the deleted data or an error
|
|
41
|
+
*
|
|
42
|
+
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to either:
|
|
43
|
+
* - Success with a success message and the deleted data
|
|
44
|
+
* - Error if:
|
|
45
|
+
* - No matching data is found
|
|
46
|
+
* - Any file deletion operation fails
|
|
47
|
+
* - The initial buffer data loading fails
|
|
48
|
+
*/
|
|
49
|
+
deleteMany(): Promise<SuccessInterface | ErrorInterface>;
|
|
50
|
+
/**
|
|
51
|
+
* Loads all buffer raw data from the specified directory.
|
|
52
|
+
*
|
|
53
|
+
* This method performs the following steps:
|
|
54
|
+
* 1. Checks if the directory is locked.
|
|
55
|
+
* 2. If the directory is not locked, it lists all files in the directory.
|
|
56
|
+
* 3. Reads each file and decrypts the data if encryption is enabled.
|
|
57
|
+
* 4. Stores the decrypted data in the `AllData` array.
|
|
58
|
+
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
61
|
+
*
|
|
62
|
+
* @throws {Error} Throws an error if any operation fails.
|
|
63
|
+
*/
|
|
64
|
+
private LoadAllBufferRawData;
|
|
65
|
+
/**
|
|
66
|
+
* Deletes a file from the specified path.
|
|
67
|
+
*
|
|
68
|
+
* This method checks if the directory is locked before attempting to delete the file.
|
|
69
|
+
* If the directory is locked, it tries to unlock it, delete the file, and then lock it again.
|
|
70
|
+
*
|
|
71
|
+
* @param fileName - The name of the file to be deleted
|
|
72
|
+
* @returns A response object indicating success or failure
|
|
73
|
+
* Success response: { status: true, message: "File deleted successfully" }
|
|
74
|
+
* Error response: { status: false, message: <error message> }
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private deleteFile;
|
|
78
|
+
/**
|
|
79
|
+
* to be sorted to the query
|
|
80
|
+
* @param {object} sort - The sort to be set.
|
|
81
|
+
* @returns {DeleteOperation} - An instance of the DeleteOperation class.
|
|
82
|
+
*/
|
|
83
|
+
Sort(sort: object | any): DeleteOperation;
|
|
84
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const Converter_helper_1 = __importDefault(require("../../Helper/Converter.helper"));
|
|
17
|
+
const Crypto_helper_1 = require("../../Helper/Crypto.helper");
|
|
18
|
+
const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
|
|
19
|
+
const FileManager_1 = __importDefault(require("../../Storage/FileManager"));
|
|
20
|
+
const FolderManager_1 = __importDefault(require("../../Storage/FolderManager"));
|
|
21
|
+
// Import All Utility
|
|
22
|
+
const HashMapSearch_utils_1 = __importDefault(require("../../utils/HashMapSearch.utils"));
|
|
23
|
+
const SortData_utils_1 = __importDefault(require("../../utils/SortData.utils"));
|
|
24
|
+
/**
|
|
25
|
+
* The DeleteOperation class is used to delete a document from a collection.
|
|
26
|
+
* This class provides methods to delete a single document that matches the base query.
|
|
27
|
+
*/
|
|
28
|
+
class DeleteOperation {
|
|
29
|
+
constructor(collectionName, path, baseQuery, isEncrypted = false, encryptionKey) {
|
|
30
|
+
this.allDataWithFileName = [];
|
|
31
|
+
this.collectionName = collectionName;
|
|
32
|
+
this.path = path;
|
|
33
|
+
this.baseQuery = baseQuery;
|
|
34
|
+
this.isEncrypted = isEncrypted;
|
|
35
|
+
this.encryptionKey = encryptionKey;
|
|
36
|
+
this.sort = {};
|
|
37
|
+
this.ResponseHelper = new response_helper_1.default();
|
|
38
|
+
this.Converter = new Converter_helper_1.default();
|
|
39
|
+
if (this.isEncrypted && this.encryptionKey) {
|
|
40
|
+
this.cryptoInstance = new Crypto_helper_1.CryptoHelper(this.encryptionKey);
|
|
41
|
+
}
|
|
42
|
+
this.allDataWithFileName = []; // To store all data with file name
|
|
43
|
+
}
|
|
44
|
+
// Methods
|
|
45
|
+
/**
|
|
46
|
+
* Deletes a single document that matches the base query.
|
|
47
|
+
*
|
|
48
|
+
* This method:
|
|
49
|
+
* 1. Loads all raw data from buffers
|
|
50
|
+
* 2. Searches for documents matching the base query
|
|
51
|
+
* 3. Selects the first matching document (applying sort if provided)
|
|
52
|
+
* 4. Deletes the file associated with the selected document
|
|
53
|
+
*
|
|
54
|
+
* @returns {Promise<object>} A response object containing either:
|
|
55
|
+
* - Success: { message: "Data deleted successfully", deleteData: object }
|
|
56
|
+
* - Error: An error message if no data found or deletion fails
|
|
57
|
+
*
|
|
58
|
+
* @throws Will propagate any errors from underlying operations
|
|
59
|
+
*/
|
|
60
|
+
deleteOne() {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const response = yield this.LoadAllBufferRawData();
|
|
63
|
+
if ("data" in response) {
|
|
64
|
+
const SearchedData = yield new HashMapSearch_utils_1.default(response.data).find(this.baseQuery, "data");
|
|
65
|
+
if (SearchedData.length === 0) {
|
|
66
|
+
return this.ResponseHelper.Error("No data found with the specified query");
|
|
67
|
+
}
|
|
68
|
+
let selectedFirstData = SearchedData[0]; // Select the first data
|
|
69
|
+
let fileName = selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.fileName; // Get the file name
|
|
70
|
+
// Sort the data if sort is provided then select the first data for deletion
|
|
71
|
+
if (Object.keys(this.sort).length === 0) {
|
|
72
|
+
selectedFirstData = SearchedData[0]; // Select the first data
|
|
73
|
+
fileName = selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.fileName; // Get the file name
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const Sorter = new SortData_utils_1.default(SearchedData, this.sort);
|
|
77
|
+
const SortedData = yield Sorter.sort("data"); // Sort the data
|
|
78
|
+
selectedFirstData = SortedData[0]; // Select the first data
|
|
79
|
+
fileName = selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.fileName; // Get the file name
|
|
80
|
+
}
|
|
81
|
+
// Delete the file
|
|
82
|
+
const deleteResponse = yield this.deleteFile(fileName);
|
|
83
|
+
if ("data" in deleteResponse) {
|
|
84
|
+
return this.ResponseHelper.Success({
|
|
85
|
+
message: "Data deleted successfully",
|
|
86
|
+
deleteData: selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.data,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return this.ResponseHelper.Error("Failed to delete data");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return this.ResponseHelper.Error(response);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Deletes multiple documents that match the base query.
|
|
100
|
+
*
|
|
101
|
+
* This method:
|
|
102
|
+
* 1. Searches for documents matching the base query
|
|
103
|
+
* 2. Deletes each matching file
|
|
104
|
+
* 3. Returns success with the deleted data or an error
|
|
105
|
+
*
|
|
106
|
+
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to either:
|
|
107
|
+
* - Success with a success message and the deleted data
|
|
108
|
+
* - Error if:
|
|
109
|
+
* - No matching data is found
|
|
110
|
+
* - Any file deletion operation fails
|
|
111
|
+
* - The initial buffer data loading fails
|
|
112
|
+
*/
|
|
113
|
+
deleteMany() {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const response = yield this.LoadAllBufferRawData();
|
|
116
|
+
if ("data" in response) {
|
|
117
|
+
const SearchedData = yield new HashMapSearch_utils_1.default(response.data).find(this.baseQuery, "data");
|
|
118
|
+
if (SearchedData.length === 0) {
|
|
119
|
+
return this.ResponseHelper.Error("No data found with the specified query");
|
|
120
|
+
}
|
|
121
|
+
// Delete all files
|
|
122
|
+
for (let i = 0; i < SearchedData.length; i++) {
|
|
123
|
+
const deleteResponse = yield this.deleteFile(SearchedData[i].fileName);
|
|
124
|
+
if ("data" in deleteResponse) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return this.ResponseHelper.Error("Failed to delete data");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return this.ResponseHelper.Success({
|
|
132
|
+
message: "Data deleted successfully",
|
|
133
|
+
deleteData: SearchedData.map((data) => data.data),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return this.ResponseHelper.Error(response);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Loads all buffer raw data from the specified directory.
|
|
143
|
+
*
|
|
144
|
+
* This method performs the following steps:
|
|
145
|
+
* 1. Checks if the directory is locked.
|
|
146
|
+
* 2. If the directory is not locked, it lists all files in the directory.
|
|
147
|
+
* 3. Reads each file and decrypts the data if encryption is enabled.
|
|
148
|
+
* 4. Stores the decrypted data in the `AllData` array.
|
|
149
|
+
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
150
|
+
*
|
|
151
|
+
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
152
|
+
*
|
|
153
|
+
* @throws {Error} Throws an error if any operation fails.
|
|
154
|
+
*/
|
|
155
|
+
LoadAllBufferRawData() {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
try {
|
|
158
|
+
// Check if Directory Locked or not
|
|
159
|
+
const isLocked = yield new FolderManager_1.default().IsDirectoryLocked(this.path);
|
|
160
|
+
if ("data" in isLocked) {
|
|
161
|
+
// If Directory is not locked
|
|
162
|
+
if (isLocked.data === false) {
|
|
163
|
+
// Read List the data from the file
|
|
164
|
+
const ReadResponse = yield new FolderManager_1.default().ListDirectory(this.path);
|
|
165
|
+
if ("data" in ReadResponse) {
|
|
166
|
+
// Store all files in DataFilesList
|
|
167
|
+
const DataFilesList = ReadResponse.data;
|
|
168
|
+
// Read all files from the directory
|
|
169
|
+
for (let i = 0; i < DataFilesList.length; i++) {
|
|
170
|
+
const ReadFileResponse = yield new FileManager_1.default().ReadFile(`${this.path}/${DataFilesList[i]}`);
|
|
171
|
+
// Check if the file is read successfully or not
|
|
172
|
+
if ("data" in ReadFileResponse) {
|
|
173
|
+
if (this.isEncrypted === true && this.cryptoInstance) {
|
|
174
|
+
// Decrypt the data if crypto is enabled
|
|
175
|
+
const ContentResponse = yield this.cryptoInstance.decrypt(this.Converter.ToObject(ReadFileResponse.data));
|
|
176
|
+
// Store all Decrypted Data in AllData
|
|
177
|
+
this.allDataWithFileName.push({
|
|
178
|
+
fileName: DataFilesList[i],
|
|
179
|
+
data: this.Converter.ToObject(ContentResponse),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.allDataWithFileName.push({
|
|
184
|
+
fileName: DataFilesList[i],
|
|
185
|
+
data: this.Converter.ToObject(ReadFileResponse.data),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return this.ResponseHelper.Error(`Failed to read file: ${DataFilesList[i]}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return this.ResponseHelper.Success(this.allDataWithFileName);
|
|
194
|
+
}
|
|
195
|
+
return this.ResponseHelper.Error("Failed to read directory");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// if Directory is locked then unlock it
|
|
199
|
+
const unlockResponse = yield new FolderManager_1.default().UnlockDirectory(this.path);
|
|
200
|
+
if ("data" in unlockResponse) {
|
|
201
|
+
// Read List the data from the file
|
|
202
|
+
const ReadResponse = yield new FolderManager_1.default().ListDirectory(this.path);
|
|
203
|
+
if ("data" in ReadResponse) {
|
|
204
|
+
// Store all files in DataFilesList
|
|
205
|
+
const DataFilesList = ReadResponse.data;
|
|
206
|
+
// Read all files from the directory
|
|
207
|
+
for (let i = 0; i < DataFilesList.length; i++) {
|
|
208
|
+
const ReadFileResponse = yield new FileManager_1.default().ReadFile(`${this.path}/${DataFilesList[i]}`);
|
|
209
|
+
// Check if the file is read successfully or not
|
|
210
|
+
if ("data" in ReadFileResponse) {
|
|
211
|
+
if (this.isEncrypted === true && this.cryptoInstance) {
|
|
212
|
+
// Decrypt the data if crypto is enabled
|
|
213
|
+
const ContaentResponse = yield this.cryptoInstance.decrypt(this.Converter.ToObject(ReadFileResponse.data));
|
|
214
|
+
// Store all Decrypted Data in AllData
|
|
215
|
+
this.allDataWithFileName.push({
|
|
216
|
+
fileName: DataFilesList[i],
|
|
217
|
+
data: this.Converter.ToObject(ContaentResponse),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.allDataWithFileName.push({
|
|
222
|
+
fileName: DataFilesList[i],
|
|
223
|
+
data: this.Converter.ToObject(ReadFileResponse.data),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
return this.ResponseHelper.Error(`Failed to read file: ${DataFilesList[i]}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Lock the directory after reading all files
|
|
232
|
+
const lockResponse = yield new FolderManager_1.default().LockDirectory(this.path);
|
|
233
|
+
if ("data" in lockResponse) {
|
|
234
|
+
return this.ResponseHelper.Success(this.allDataWithFileName);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return this.ResponseHelper.Error(`Failed to lock directory: ${this.path}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return this.ResponseHelper.Error(`Failed to read directory: ${this.path}`);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
return this.ResponseHelper.Error(`Failed to unlock directory: ${this.path}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
return this.ResponseHelper.Error(isLocked);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
return this.ResponseHelper.Error(error);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Deletes a file from the specified path.
|
|
258
|
+
*
|
|
259
|
+
* This method checks if the directory is locked before attempting to delete the file.
|
|
260
|
+
* If the directory is locked, it tries to unlock it, delete the file, and then lock it again.
|
|
261
|
+
*
|
|
262
|
+
* @param fileName - The name of the file to be deleted
|
|
263
|
+
* @returns A response object indicating success or failure
|
|
264
|
+
* Success response: { status: true, message: "File deleted successfully" }
|
|
265
|
+
* Error response: { status: false, message: <error message> }
|
|
266
|
+
* @private
|
|
267
|
+
*/
|
|
268
|
+
deleteFile(fileName) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
// Check if Directory Locked or not
|
|
271
|
+
const isLocked = yield new FolderManager_1.default().IsDirectoryLocked(this.path);
|
|
272
|
+
if ("data" in isLocked) {
|
|
273
|
+
// If Directory is not locked
|
|
274
|
+
if (isLocked.data === false) {
|
|
275
|
+
const deleteResponse = yield new FileManager_1.default().DeleteFile(`${this.path}/${fileName}`);
|
|
276
|
+
if ("data" in deleteResponse) {
|
|
277
|
+
return this.ResponseHelper.Success("File deleted successfully");
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return this.ResponseHelper.Error("Failed to delete file");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const unlockResponse = yield new FolderManager_1.default().UnlockDirectory(this.path);
|
|
285
|
+
if ("data" in unlockResponse) {
|
|
286
|
+
const deleteResponse = yield new FileManager_1.default().DeleteFile(`${this.path}/${fileName}`);
|
|
287
|
+
if ("data" in deleteResponse) {
|
|
288
|
+
const lockResponse = yield new FolderManager_1.default().LockDirectory(this.path);
|
|
289
|
+
if ("data" in lockResponse) {
|
|
290
|
+
return this.ResponseHelper.Success("File deleted successfully");
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return this.ResponseHelper.Error("Failed to lock directory");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
return this.ResponseHelper.Error("Failed to delete file");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
return this.ResponseHelper.Error("Failed to unlock directory");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return this.ResponseHelper.Error("Failed to delete file");
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* to be sorted to the query
|
|
312
|
+
* @param {object} sort - The sort to be set.
|
|
313
|
+
* @returns {DeleteOperation} - An instance of the DeleteOperation class.
|
|
314
|
+
*/
|
|
315
|
+
Sort(sort) {
|
|
316
|
+
this.sort = sort;
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.default = DeleteOperation;
|
|
321
|
+
//# sourceMappingURL=Delete.operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Delete.operation.js","sourceRoot":"","sources":["../../../source/Operation/CRUD Operation/Delete.operation.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;;;AAMvD,qFAAsD;AACtD,8DAA0D;AAC1D,mFAA0D;AAC1D,4EAAoD;AACpD,gFAAwD;AAExD,qBAAqB;AACrB,0FAA4D;AAC5D,gFAAiD;AAEjD;;;GAGG;AACH,MAAqB,eAAe;IAalC,YACE,cAAsB,EACtB,IAAY,EACZ,SAAuB,EACvB,cAAuB,KAAK,EAC5B,aAAsB;QARhB,wBAAmB,GAAU,EAAE,CAAC;QAUtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B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AAY,GAAG,MAAM,IAAI,uBAAa,EAAE,CAAC,aAAa,CAC1D,IAAI,CAAC,IAAI,CACV,CAAC;4BACF,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;gCAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;4BAClE,CAAC;iCAAM,CAAC;gCACN,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;4BAC/D,CAAC;wBACH,CAAC;6BAAM,CAAC;4BACN,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;wBAC5D,CAAC;oBACH,CAAC;yBAAM,CAAC;wBACN,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;oBACjE,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;KAAA;IAED;;;;OAIG;IACI,IAAI,CAAC,IAAkB;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlVD,kCAkVC"}
|
|
@@ -13,6 +13,7 @@ export default class Reader {
|
|
|
13
13
|
private isEncrypted;
|
|
14
14
|
private encryptionKey;
|
|
15
15
|
private cryptoInstance?;
|
|
16
|
+
private totalCount;
|
|
16
17
|
private readonly ResponseHelper;
|
|
17
18
|
private AllData;
|
|
18
19
|
/**
|
|
@@ -47,6 +48,13 @@ export default class Reader {
|
|
|
47
48
|
* @returns {Reader} - An instance of the Reader class.
|
|
48
49
|
*/
|
|
49
50
|
Sort(sort: object | any): Reader;
|
|
51
|
+
/**
|
|
52
|
+
* Sets whether to include the total count of matching documents in the result.
|
|
53
|
+
*
|
|
54
|
+
* @param count - Boolean flag indicating whether to include the total count
|
|
55
|
+
* @returns The Reader instance for method chaining
|
|
56
|
+
*/
|
|
57
|
+
setCount(count: boolean): Reader;
|
|
50
58
|
/**
|
|
51
59
|
* Loads all buffer raw data from the specified directory.
|
|
52
60
|
*
|
|
@@ -46,6 +46,7 @@ class Reader {
|
|
|
46
46
|
this.Converter = new Converter_helper_1.default();
|
|
47
47
|
this.encryptionKey = encryptionKey;
|
|
48
48
|
this.ResponseHelper = new response_helper_1.default();
|
|
49
|
+
this.totalCount = false;
|
|
49
50
|
this.AllData = [];
|
|
50
51
|
if (this.isEncrypted === true) {
|
|
51
52
|
this.cryptoInstance = new Crypto_helper_1.CryptoHelper(this.encryptionKey);
|
|
@@ -115,6 +116,16 @@ class Reader {
|
|
|
115
116
|
this.sort = sort;
|
|
116
117
|
return this;
|
|
117
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Sets whether to include the total count of matching documents in the result.
|
|
121
|
+
*
|
|
122
|
+
* @param count - Boolean flag indicating whether to include the total count
|
|
123
|
+
* @returns The Reader instance for method chaining
|
|
124
|
+
*/
|
|
125
|
+
setCount(count) {
|
|
126
|
+
this.totalCount = count;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
118
129
|
/**
|
|
119
130
|
* Loads all buffer raw data from the specified directory.
|
|
120
131
|
*
|
|
@@ -235,9 +246,21 @@ class Reader {
|
|
|
235
246
|
if (this.limit !== undefined && this.skip !== undefined) {
|
|
236
247
|
// Apply Skip and Limit
|
|
237
248
|
const limitedAndSkippedData = FinalData.slice(this.skip, this.skip + this.limit);
|
|
238
|
-
|
|
249
|
+
if (this.totalCount) {
|
|
250
|
+
return this.ResponseHelper.Success({
|
|
251
|
+
documents: limitedAndSkippedData,
|
|
252
|
+
totalDocuments: limitedAndSkippedData.length,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return this.ResponseHelper.Success({
|
|
257
|
+
documents: limitedAndSkippedData,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
239
260
|
}
|
|
240
|
-
return this.ResponseHelper.Success(
|
|
261
|
+
return this.ResponseHelper.Success({
|
|
262
|
+
documents: FinalData,
|
|
263
|
+
});
|
|
241
264
|
});
|
|
242
265
|
}
|
|
243
266
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reader.operation.js","sourceRoot":"","sources":["../../../source/Operation/CRUD Operation/Reader.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,uDAAuD;AACvD,gFAAwD;AAMxD,qBAAqB;AACrB,mFAA0D;AAC1D,qFAAsD;AACtD,4EAAoD;AACpD,8DAA0D;AAE1D,qBAAqB;AACrB,0FAA4D;AAC5D,gFAAiD;AAEjD;;GAEG;AACH,MAAqB,MAAM;
|
|
1
|
+
{"version":3,"file":"Reader.operation.js","sourceRoot":"","sources":["../../../source/Operation/CRUD Operation/Reader.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,uDAAuD;AACvD,gFAAwD;AAMxD,qBAAqB;AACrB,mFAA0D;AAC1D,qFAAsD;AACtD,4EAAoD;AACpD,8DAA0D;AAE1D,qBAAqB;AACrB,0FAA4D;AAC5D,gFAAiD;AAEjD;;GAEG;AACH,MAAqB,MAAM;IAezB;;;;;;;OAOG;IACH,YACE,cAAsB,EACtB,IAAY,EACZ,SAAuB,EACvB,cAAuB,KAAK,EAC5B,aAAsB;QAEtB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;QACjC,IAAI,CAAC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,QAAQ,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;;;;OAUG;IACW,iBAAiB,CAC7B,SAAgB;;YAEhB,kCAAkC;YAClC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBACxD,uBAAuB;gBACvB,MAAM,qBAAqB,GAAU,SAAS,CAAC,KAAK,CAClD,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CACvB,CAAC;gBACF,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;oBACpB,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;wBACjC,SAAS,EAAE,qBAAqB;wBAChC,cAAc,EAAE,qBAAqB,CAAC,MAAM;qBAC7C,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;wBACjC,SAAS,EAAE,qBAAqB;qBACjC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBACjC,SAAS,EAAE,SAAS;aACrB,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AArSD,yBAqSC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Update.operation.js","sourceRoot":"","sources":["../../../source/Operation/CRUD Operation/Update.operation.ts"],"names":[],"mappings":";;AAAA,MAAqB,eAAe;IAClC;QACE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACjC,CAAC;CACF;AAJD,kCAIC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
|
|
2
2
|
import Reader from "../CRUD Operation/Reader.operation";
|
|
3
|
+
import DeleteOperation from "../CRUD Operation/Delete.operation";
|
|
3
4
|
import { CryptoHelper } from "../../Helper/Crypto.helper";
|
|
4
5
|
/**
|
|
5
6
|
* Represents a collection inside a database.
|
|
@@ -28,4 +29,18 @@ export default class Collection {
|
|
|
28
29
|
* @returns {Reader} - An instance of the Reader class.
|
|
29
30
|
*/
|
|
30
31
|
query(query: object | any): Reader;
|
|
32
|
+
/**
|
|
33
|
+
* Initiates a delete operation on the collection with the provided query.
|
|
34
|
+
*
|
|
35
|
+
* @param query - The query object that specifies which documents to delete.
|
|
36
|
+
* @returns A DeleteOperation instance that can be executed to perform the deletion.
|
|
37
|
+
* @throws {Error} Throws an error if the query is empty.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Delete all documents where age is greater than 30
|
|
42
|
+
* collection.delete({ age: { $gt: 30 } });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
delete(query: object | any): DeleteOperation;
|
|
31
46
|
}
|
|
@@ -12,8 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
// Operations
|
|
15
16
|
const Create_operation_1 = __importDefault(require("../CRUD Operation/Create.operation"));
|
|
16
17
|
const Reader_operation_1 = __importDefault(require("../CRUD Operation/Reader.operation"));
|
|
18
|
+
const Delete_operation_1 = __importDefault(require("../CRUD Operation/Delete.operation"));
|
|
17
19
|
const outers_1 = require("outers");
|
|
18
20
|
// Validator
|
|
19
21
|
const validator_models_1 = __importDefault(require("../../Models/validator.models"));
|
|
@@ -84,6 +86,27 @@ class Collection {
|
|
|
84
86
|
// Read the data
|
|
85
87
|
return new Reader_operation_1.default(this.name, this.path, query, this.isEncrypted, this.encryptionKey);
|
|
86
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Initiates a delete operation on the collection with the provided query.
|
|
91
|
+
*
|
|
92
|
+
* @param query - The query object that specifies which documents to delete.
|
|
93
|
+
* @returns A DeleteOperation instance that can be executed to perform the deletion.
|
|
94
|
+
* @throws {Error} Throws an error if the query is empty.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Delete all documents where age is greater than 30
|
|
99
|
+
* collection.delete({ age: { $gt: 30 } });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
delete(query) {
|
|
103
|
+
// Check if documentId is empty or not
|
|
104
|
+
if (!query) {
|
|
105
|
+
throw new Error("Query cannot be empty");
|
|
106
|
+
}
|
|
107
|
+
// Delete the data
|
|
108
|
+
return new Delete_operation_1.default(this.name, this.path, query, this.isEncrypted, this.encryptionKey);
|
|
109
|
+
}
|
|
87
110
|
}
|
|
88
111
|
exports.default = Collection;
|
|
89
112
|
//# sourceMappingURL=collection.operation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.operation.js","sourceRoot":"","sources":["../../../source/Operation/Collection/collection.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,0FAA2D;AAC3D,0FAAwD;AACxD,mCAAiC;AACjC,YAAY;AACZ,qFAA4D;AAG5D,YAAY;AACZ,qFAAsD;AACtD,oEAA4D;AAE5D;;GAEG;AACH,MAAqB,UAAU;IAY7B,YACE,IAAY,EACZ,IAAY,EACZ,KAAmB,EACnB,WAAW,GAAG,KAAK,EACnB,cAA6B,EAC7B,aAAsB;QAEtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACr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AC;YAED,wCAAwC;YACxC,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC5C,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,CAAC;YAED,gBAAgB;YAChB,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;KAAA;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAmB;QAC9B,sCAAsC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,gBAAgB;QAChB,OAAO,IAAI,0BAAM,CACf,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,EACT,KAAK,EACL,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"collection.operation.js","sourceRoot":"","sources":["../../../source/Operation/Collection/collection.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,aAAa;AACb,0FAA2D;AAC3D,0FAAwD;AACxD,0FAAiE;AAEjE,mCAAiC;AACjC,YAAY;AACZ,qFAA4D;AAG5D,YAAY;AACZ,qFAAsD;AACtD,oEAA4D;AAE5D;;GAEG;AACH,MAAqB,UAAU;IAY7B,YACE,IAAY,EACZ,IAAY,EACZ,KAAmB,EACnB,WAAW,GAAG,KAAK,EACnB,cAA6B,EAC7B,aAAsB;QAEtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAA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ACT,CAAC;YAED,wCAAwC;YACxC,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC5C,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC1E,CAAC;YAED,gBAAgB;YAChB,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;KAAA;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAmB;QAC9B,sCAAsC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,gBAAgB;QAChB,OAAO,IAAI,0BAAM,CACf,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,EACT,KAAK,EACL,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,KAAmB;QAC/B,sCAAsC;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,kBAAkB;QAClB,OAAO,IAAI,0BAAe,CACxB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,EACT,KAAK,EACL,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;CACF;AA1HD,6BA0HC"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
export default class HashmapSearch {
|
|
2
|
-
private indexMap;
|
|
3
2
|
private data;
|
|
4
3
|
constructor(arr: any[]);
|
|
5
4
|
/**
|
|
6
5
|
* Finds and returns an array of items that match the given query.
|
|
6
|
+
* Supports MongoDB-like operators such as $regex, $gt, $lt, and $in.
|
|
7
7
|
*
|
|
8
|
-
* @param query - An object where the keys are the fields to search by and the values
|
|
8
|
+
* @param query - An object where the keys are the fields to search by, and the values can be exact values or operators.
|
|
9
9
|
* @returns A promise that resolves to an array of items that match the query.
|
|
10
|
-
*
|
|
11
|
-
* The function works by creating a set of result indexes that match the query.
|
|
12
|
-
* It iterates over each key in the query, constructs a map key, and retrieves the indexes from the indexMap.
|
|
13
|
-
* If resultIndexes is null, it initializes it with the current indexes.
|
|
14
|
-
* Otherwise, it performs an intersection to refine the results.
|
|
15
|
-
* Finally, it maps the result indexes to the corresponding items in the data array and returns them.
|
|
16
10
|
*/
|
|
17
11
|
find(query: {
|
|
18
|
-
[
|
|
19
|
-
}): Promise<any[]>;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}, aditionalFiled?: string | number | undefined): Promise<any[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if an object matches the given query.
|
|
16
|
+
*
|
|
17
|
+
* @param item - The object to check.
|
|
18
|
+
* @param query - The query object containing search criteria.
|
|
19
|
+
* @returns A boolean indicating if the object matches the query.
|
|
20
|
+
*/
|
|
21
|
+
private matchesQuery;
|
|
20
22
|
}
|
|
@@ -12,49 +12,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
13
|
class HashmapSearch {
|
|
14
14
|
constructor(arr) {
|
|
15
|
-
this.indexMap = new Map();
|
|
16
15
|
this.data = arr;
|
|
17
|
-
// Build index for each field in objects
|
|
18
|
-
arr.forEach((obj, idx) => {
|
|
19
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
20
|
-
const mapKey = `${key}:${value}`;
|
|
21
|
-
if (!this.indexMap.has(mapKey)) {
|
|
22
|
-
this.indexMap.set(mapKey, []);
|
|
23
|
-
}
|
|
24
|
-
this.indexMap.get(mapKey).push(idx);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
16
|
}
|
|
28
17
|
/**
|
|
29
18
|
* Finds and returns an array of items that match the given query.
|
|
19
|
+
* Supports MongoDB-like operators such as $regex, $gt, $lt, and $in.
|
|
30
20
|
*
|
|
31
|
-
* @param query - An object where the keys are the fields to search by and the values
|
|
21
|
+
* @param query - An object where the keys are the fields to search by, and the values can be exact values or operators.
|
|
32
22
|
* @returns A promise that resolves to an array of items that match the query.
|
|
33
|
-
*
|
|
34
|
-
* The function works by creating a set of result indexes that match the query.
|
|
35
|
-
* It iterates over each key in the query, constructs a map key, and retrieves the indexes from the indexMap.
|
|
36
|
-
* If resultIndexes is null, it initializes it with the current indexes.
|
|
37
|
-
* Otherwise, it performs an intersection to refine the results.
|
|
38
|
-
* Finally, it maps the result indexes to the corresponding items in the data array and returns them.
|
|
39
23
|
*/
|
|
40
|
-
find(query) {
|
|
24
|
+
find(query, aditionalFiled) {
|
|
41
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
if (aditionalFiled) {
|
|
27
|
+
return this.data.filter((item) => this.matchesQuery(item[aditionalFiled], query));
|
|
28
|
+
}
|
|
29
|
+
return this.data.filter((item) => this.matchesQuery(item, query));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Checks if an object matches the given query.
|
|
34
|
+
*
|
|
35
|
+
* @param item - The object to check.
|
|
36
|
+
* @param query - The query object containing search criteria.
|
|
37
|
+
* @returns A boolean indicating if the object matches the query.
|
|
38
|
+
*/
|
|
39
|
+
matchesQuery(item, query) {
|
|
40
|
+
return Object.keys(query).every((key) => {
|
|
41
|
+
const queryValue = query[key];
|
|
42
|
+
const itemValue = item[key];
|
|
43
|
+
if (typeof queryValue === "object" && queryValue !== null) {
|
|
44
|
+
// Handle MongoDB-like operators
|
|
45
|
+
if ("$regex" in queryValue &&
|
|
46
|
+
typeof queryValue["$regex"] === "string") {
|
|
47
|
+
const regex = new RegExp(queryValue["$regex"], queryValue["$options"] || "i");
|
|
48
|
+
return regex.test(itemValue);
|
|
49
|
+
}
|
|
50
|
+
if ("$gt" in queryValue && typeof itemValue === "number") {
|
|
51
|
+
return itemValue > queryValue["$gt"];
|
|
52
|
+
}
|
|
53
|
+
if ("$lt" in queryValue && typeof itemValue === "number") {
|
|
54
|
+
return itemValue < queryValue["$lt"];
|
|
55
|
+
}
|
|
56
|
+
if ("$gte" in queryValue && typeof itemValue === "number") {
|
|
57
|
+
return itemValue >= queryValue["$gte"];
|
|
58
|
+
}
|
|
59
|
+
if ("$lte" in queryValue && typeof itemValue === "number") {
|
|
60
|
+
return itemValue <= queryValue["$lte"];
|
|
61
|
+
}
|
|
62
|
+
if ("$in" in queryValue && Array.isArray(queryValue["$in"])) {
|
|
63
|
+
return queryValue["$in"].includes(itemValue);
|
|
51
64
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
resultIndexes = new Set([...resultIndexes].filter((i) => indexes.includes(i)));
|
|
65
|
+
if ("$eq" in queryValue) {
|
|
66
|
+
return itemValue === queryValue["$eq"];
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
|
-
|
|
69
|
+
// Direct equality check for simple queries
|
|
70
|
+
return itemValue === queryValue;
|
|
58
71
|
});
|
|
59
72
|
}
|
|
60
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashMapSearch.utils.js","sourceRoot":"","sources":["../../source/utils/HashMapSearch.utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD,MAAqB,aAAa;
|
|
1
|
+
{"version":3,"file":"HashMapSearch.utils.js","sourceRoot":"","sources":["../../source/utils/HashMapSearch.utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD,MAAqB,aAAa;IAGhC,YAAY,GAAU;QACpB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACU,IAAI,CAC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BACzD,OAAO,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBACvC,CAAC;gBAED,IAAI,MAAM,IAAI,UAAU,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAC1D,OAAO,SAAS,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;gBACzC,CAAC;gBAED,IAAI,MAAM,IAAI,UAAU,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAC1D,OAAO,SAAS,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;gBACzC,CAAC;gBAED,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC5D,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;gBAC/C,CAAC;gBAED,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;oBACxB,OAAO,SAAS,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC;gBACzC,CAAC;YACH,CAAC;YAED,2CAA2C;YAC3C,OAAO,SAAS,KAAK,UAAU,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhFD,gCAgFC"}
|
|
@@ -29,16 +29,27 @@ class Sorting {
|
|
|
29
29
|
* @param query - The query object containing the sorting key and order.
|
|
30
30
|
* @returns A promise that resolves to the sorted array.
|
|
31
31
|
*/
|
|
32
|
-
sort() {
|
|
32
|
+
sort(aditionalField) {
|
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
const [key, order] = Object.entries(this.query)[0]; // Extract the field and order (1 for ascending, -1 for descending)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
if (aditionalField) {
|
|
36
|
+
return [...this.arr].sort((a, b) => {
|
|
37
|
+
if (a[aditionalField][key] < b[aditionalField][key])
|
|
38
|
+
return -order; // Swap order
|
|
39
|
+
if (a[aditionalField][key] > b[aditionalField][key])
|
|
40
|
+
return order; // Swap order
|
|
41
|
+
return 0;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return [...this.arr].sort((a, b) => {
|
|
46
|
+
if (a[key] < b[key])
|
|
47
|
+
return -order; // Swap order
|
|
48
|
+
if (a[key] > b[key])
|
|
49
|
+
return order; // Swap order
|
|
50
|
+
return 0;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
42
53
|
});
|
|
43
54
|
}
|
|
44
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortData.utils.js","sourceRoot":"","sources":["../../source/utils/SortData.utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD;;GAEG;AACH,MAAqB,OAAO;IAK1B;;;;OAIG;IACH,YACE,GAAU,EACV,KAAoD;QAEpD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACU,IAAI;;
|
|
1
|
+
{"version":3,"file":"SortData.utils.js","sourceRoot":"","sources":["../../source/utils/SortData.utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uDAAuD;AACvD;;GAEG;AACH,MAAqB,OAAO;IAK1B;;;;OAIG;IACH,YACE,GAAU,EACV,KAAoD;QAEpD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACU,IAAI,CAAC,cAAuB;;YACvC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAqB,CAAC,CAAC,mEAAmE;YAC3I,IAAI,cAAc,EAAE,CAAC;gBACnB,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACjC,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC;wBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,aAAa;oBACjF,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC;wBAAE,OAAO,KAAK,CAAC,CAAC,aAAa;oBAChF,OAAO,CAAC,CAAC;gBACX,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACjC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;wBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,aAAa;oBACjD,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;wBAAE,OAAO,KAAK,CAAC,CAAC,aAAa;oBAChD,OAAO,CAAC,CAAC;gBACX,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KAAA;CACF;AAxCD,0BAwCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axiodb",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "A fast, lightweight, and scalable open-source DBMS for modern apps. Supports JSON-based data storage, simple APIs, and secure data management. Ideal for projects needing efficient and flexible database solutions.",
|
|
5
5
|
"main": "./lib/config/DB.js",
|
|
6
6
|
"types": "./lib/config/DB.d.ts",
|
|
@@ -8,10 +8,7 @@
|
|
|
8
8
|
"test": "node ./test/test.js",
|
|
9
9
|
"build": "tsc",
|
|
10
10
|
"prepare": "npm run build",
|
|
11
|
-
"
|
|
12
|
-
"build:react": "vite build",
|
|
13
|
-
"lint": "eslint .",
|
|
14
|
-
"preview": "vite preview"
|
|
11
|
+
"lint": "eslint ."
|
|
15
12
|
},
|
|
16
13
|
"repository": {
|
|
17
14
|
"type": "git",
|
package/lib/server/Fastify.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Starts the web server using Fastify.
|
|
3
|
-
*
|
|
4
|
-
* This function initializes a Fastify server instance with logging disabled.
|
|
5
|
-
* It registers a static file plugin to serve files from the "public" directory
|
|
6
|
-
* with a URL prefix of "/public/".
|
|
7
|
-
*
|
|
8
|
-
* The server listens on the port specified in the configuration (`ConfigWebServer.ServerPORT`).
|
|
9
|
-
* If an error occurs while starting the server, it logs the error and exits the process.
|
|
10
|
-
* On successful start, it logs the address the server is listening on.
|
|
11
|
-
*
|
|
12
|
-
* @module Fastify
|
|
13
|
-
*/
|
|
14
|
-
export default function startWebServer(): void;
|
package/lib/server/Fastify.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = startWebServer;
|
|
7
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
-
const outers_1 = require("outers");
|
|
9
|
-
const Keys_1 = require("../config/Keys/Keys");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const static_1 = __importDefault(require("@fastify/static"));
|
|
12
|
-
/**
|
|
13
|
-
* Starts the web server using Fastify.
|
|
14
|
-
*
|
|
15
|
-
* This function initializes a Fastify server instance with logging disabled.
|
|
16
|
-
* It registers a static file plugin to serve files from the "public" directory
|
|
17
|
-
* with a URL prefix of "/public/".
|
|
18
|
-
*
|
|
19
|
-
* The server listens on the port specified in the configuration (`ConfigWebServer.ServerPORT`).
|
|
20
|
-
* If an error occurs while starting the server, it logs the error and exits the process.
|
|
21
|
-
* On successful start, it logs the address the server is listening on.
|
|
22
|
-
*
|
|
23
|
-
* @module Fastify
|
|
24
|
-
*/
|
|
25
|
-
function startWebServer() {
|
|
26
|
-
const Server = (0, fastify_1.default)({ logger: false });
|
|
27
|
-
// Register static file plugin to serve files
|
|
28
|
-
Server.register(static_1.default, {
|
|
29
|
-
root: path_1.default.resolve(process.cwd(), "public"), // Directory for static files
|
|
30
|
-
prefix: "/public/", // URL prefix for static files
|
|
31
|
-
});
|
|
32
|
-
// Listen to the server
|
|
33
|
-
Server.listen({ port: Keys_1.WebServer.ServerPORT }, (err, address) => {
|
|
34
|
-
if (err) {
|
|
35
|
-
Server.log.error(err);
|
|
36
|
-
outers_1.Console.red("Failed to start the server", err);
|
|
37
|
-
}
|
|
38
|
-
Server.log.info(`AxioDB Web Interface is listening on ${address}`);
|
|
39
|
-
outers_1.Console.green("Web Interface Server is running on", address);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=Fastify.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Fastify.js","sourceRoot":"","sources":["../../source/server/Fastify.ts"],"names":[],"mappings":";;;;;AAmBA,iCAkBC;AArCD,sDAA8B;AAC9B,mCAAiC;AACjC,8CAAmE;AACnE,gDAAwB;AACxB,6DAA4C;AAE5C;;;;;;;;;;;;GAYG;AACH,SAAwB,cAAc;IACpC,MAAM,MAAM,GAAG,IAAA,iBAAO,EAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAE1C,6CAA6C;IAC7C,MAAM,CAAC,QAAQ,CAAC,gBAAa,EAAE;QAC7B,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,EAAE,6BAA6B;QAC1E,MAAM,EAAE,UAAU,EAAE,8BAA8B;KACnD,CAAC,CAAC;IAEH,uBAAuB;IACvB,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,gBAAe,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACnE,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACtB,gBAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,yCAAyC,OAAO,EAAE,CAAC,CAAC;QACpE,gBAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../source/server/Router/Router.ts"],"names":[],"mappings":""}
|