axiodb 13.0.1 → 13.1.1
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/lib/Services/CRUD Operation/Delete.operation.d.ts +24 -45
- package/lib/Services/CRUD Operation/Delete.operation.js +91 -195
- package/lib/Services/CRUD Operation/Delete.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Update.operation.d.ts +24 -38
- package/lib/Services/CRUD Operation/Update.operation.js +83 -248
- package/lib/Services/CRUD Operation/Update.operation.js.map +1 -1
- package/lib/Services/Collection/collection.operation.js +2 -2
- package/lib/Services/Collection/collection.operation.js.map +1 -1
- package/lib/Services/Transaction/Transaction.service.js +27 -2
- package/lib/Services/Transaction/Transaction.service.js.map +1 -1
- package/lib/Services/Transaction/TransactionIndexManager.service.js +10 -1
- package/lib/Services/Transaction/TransactionIndexManager.service.js.map +1 -1
- package/package.json +1 -1
- package/lib/Services/Index/DeleteIndex.service.d.ts +0 -41
- package/lib/Services/Index/DeleteIndex.service.js +0 -121
- package/lib/Services/Index/DeleteIndex.service.js.map +0 -1
- package/lib/Services/Index/InsertIndex.service.d.ts +0 -35
- package/lib/Services/Index/InsertIndex.service.js +0 -109
- package/lib/Services/Index/InsertIndex.service.js.map +0 -1
|
@@ -8,76 +8,55 @@ export default class DeleteOperation {
|
|
|
8
8
|
private readonly baseQuery;
|
|
9
9
|
private readonly path;
|
|
10
10
|
private readonly ResponseHelper;
|
|
11
|
-
private readonly fileManager;
|
|
12
11
|
private allDataWithFileName;
|
|
13
12
|
private sort;
|
|
14
13
|
constructor(collectionName: string, path: string, baseQuery: object | any);
|
|
15
14
|
/**
|
|
16
15
|
* Deletes a single document that matches the base query.
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* 5. Deletes the file associated with the selected document
|
|
24
|
-
* 6. Releases lock
|
|
17
|
+
* Routed through a single-operation Transaction, so the delete is WAL-backed:
|
|
18
|
+
* locking, the fresh re-read under lock, and index sync are all handled by
|
|
19
|
+
* Transaction/TransactionIndexManager. This method's own job is just picking
|
|
20
|
+
* *which* document to target (honoring .Sort()), since Transaction.delete()
|
|
21
|
+
* removes every document a query matches.
|
|
25
22
|
*
|
|
26
23
|
* @returns {Promise<object>} A response object containing either:
|
|
27
24
|
* - Success: { message: "Data deleted successfully", deleteData: object }
|
|
28
25
|
* - Error: An error message if no data found or deletion fails
|
|
29
|
-
*
|
|
30
|
-
* @throws Will propagate any errors from underlying operations
|
|
31
26
|
*/
|
|
32
27
|
deleteOne(): Promise<SuccessInterface | ErrorInterface>;
|
|
33
28
|
/**
|
|
34
29
|
* Deletes multiple documents that match the base query.
|
|
35
30
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* 4. Releases all locks
|
|
41
|
-
* 5. Returns success with the deleted data or an error
|
|
31
|
+
* Routed through a single Transaction covering the whole query, so the batch
|
|
32
|
+
* is WAL-backed: locking, fresh re-reads, and index sync (one rewrite per
|
|
33
|
+
* affected index field, not one per document) are all handled by
|
|
34
|
+
* Transaction/TransactionIndexManager.
|
|
42
35
|
*
|
|
43
36
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to either:
|
|
44
37
|
* - Success with a success message and the deleted data
|
|
45
|
-
* - Error if
|
|
46
|
-
* - No matching data is found
|
|
47
|
-
* - Lock acquisition fails
|
|
48
|
-
* - Any file deletion operation fails
|
|
49
|
-
* - The initial buffer data loading fails
|
|
38
|
+
* - Error if no matching data is found or the transaction failed
|
|
50
39
|
*/
|
|
51
40
|
deleteMany(): Promise<SuccessInterface | ErrorInterface>;
|
|
52
41
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* 1. Checks if the directory is locked.
|
|
57
|
-
* 2. If the directory is not locked, it lists all files in the directory.
|
|
58
|
-
* 3. Reads each file.
|
|
59
|
-
* 4. Stores the data in the `AllData` array.
|
|
60
|
-
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
61
|
-
*
|
|
62
|
-
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
63
|
-
*
|
|
64
|
-
* @throws {Error} Throws an error if any operation fails.
|
|
42
|
+
* to be sorted to the query
|
|
43
|
+
* @param {object} sort - The sort to be set.
|
|
44
|
+
* @returns {DeleteOperation} - An instance of the DeleteOperation class.
|
|
65
45
|
*/
|
|
66
|
-
|
|
46
|
+
Sort(sort: object | any): DeleteOperation;
|
|
67
47
|
/**
|
|
68
|
-
*
|
|
48
|
+
* Resolves the single document deleteOne should target: runs the same
|
|
49
|
+
* index-or-full-scan search deleteMany's Transaction path uses internally,
|
|
50
|
+
* then applies .Sort() (if set) and picks the first match - matching the
|
|
51
|
+
* "one specific document" semantics deleteOne has always had.
|
|
69
52
|
*
|
|
70
|
-
* @
|
|
71
|
-
* @returns A response object indicating success or failure
|
|
72
|
-
* Success response: { status: true, message: "File deleted successfully" }
|
|
73
|
-
* Error response: { status: false, message: <error message> }
|
|
74
|
-
* @private
|
|
53
|
+
* @returns The target document's ID, or null if nothing matched.
|
|
75
54
|
*/
|
|
76
|
-
private
|
|
55
|
+
private resolveTargetDocumentId;
|
|
77
56
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @returns {
|
|
57
|
+
* Loads all buffer raw data from the specified directory.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
81
60
|
*/
|
|
82
|
-
|
|
61
|
+
private LoadAllBufferRawData;
|
|
83
62
|
}
|
|
@@ -15,16 +15,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
|
|
17
17
|
const DocumentLoader_helper_1 = __importDefault(require("../../Helper/DocumentLoader.helper"));
|
|
18
|
-
const FileManager_1 = __importDefault(require("../../engine/Filesystem/FileManager"));
|
|
19
|
-
const crypto_1 = require("crypto");
|
|
20
18
|
// Import All Utility
|
|
21
19
|
const Searcher_utils_1 = __importDefault(require("../../utility/Searcher.utils"));
|
|
22
20
|
const SortData_utils_1 = __importDefault(require("../../utility/SortData.utils"));
|
|
23
|
-
const memory_operation_1 = __importDefault(require("../../Memory/memory.operation"));
|
|
24
21
|
const Keys_1 = require("../../config/Keys/Keys");
|
|
25
22
|
const ReadIndex_service_1 = require("../Index/ReadIndex.service");
|
|
26
|
-
const
|
|
27
|
-
const LockManager_service_1 = __importDefault(require("../Transaction/LockManager.service"));
|
|
23
|
+
const Transaction_service_1 = __importDefault(require("../Transaction/Transaction.service"));
|
|
28
24
|
/**
|
|
29
25
|
* The DeleteOperation class is used to delete a document from a collection.
|
|
30
26
|
* This class provides methods to delete a single document that matches the base query.
|
|
@@ -37,220 +33,143 @@ class DeleteOperation {
|
|
|
37
33
|
this.baseQuery = baseQuery;
|
|
38
34
|
this.sort = {};
|
|
39
35
|
this.ResponseHelper = new response_helper_1.default();
|
|
40
|
-
this.fileManager = new FileManager_1.default();
|
|
41
36
|
this.allDataWithFileName = []; // To store all data with file name
|
|
42
37
|
}
|
|
43
38
|
// Methods
|
|
44
39
|
/**
|
|
45
40
|
* Deletes a single document that matches the base query.
|
|
46
41
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* 5. Deletes the file associated with the selected document
|
|
53
|
-
* 6. Releases lock
|
|
42
|
+
* Routed through a single-operation Transaction, so the delete is WAL-backed:
|
|
43
|
+
* locking, the fresh re-read under lock, and index sync are all handled by
|
|
44
|
+
* Transaction/TransactionIndexManager. This method's own job is just picking
|
|
45
|
+
* *which* document to target (honoring .Sort()), since Transaction.delete()
|
|
46
|
+
* removes every document a query matches.
|
|
54
47
|
*
|
|
55
48
|
* @returns {Promise<object>} A response object containing either:
|
|
56
49
|
* - Success: { message: "Data deleted successfully", deleteData: object }
|
|
57
50
|
* - Error: An error message if no data found or deletion fails
|
|
58
|
-
*
|
|
59
|
-
* @throws Will propagate any errors from underlying operations
|
|
60
51
|
*/
|
|
61
52
|
deleteOne() {
|
|
62
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
54
|
var _a;
|
|
64
|
-
const lockManager = LockManager_service_1.default.getInstance(this.path);
|
|
65
|
-
const operationId = (0, crypto_1.randomUUID)();
|
|
66
|
-
const timestamp = Date.now();
|
|
67
|
-
let documentId = null;
|
|
68
55
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.documentId) !== undefined) {
|
|
72
|
-
const FilePath = [
|
|
73
|
-
`${this.baseQuery.documentId}${Keys_1.General.DBMS_File_EXT}`,
|
|
74
|
-
];
|
|
75
|
-
ReadResponse = yield this.LoadAllBufferRawData(FilePath);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
const fileNames = yield new ReadIndex_service_1.ReadIndex(this.path).getFileFromIndex(this.baseQuery);
|
|
79
|
-
if (fileNames.length > 0) {
|
|
80
|
-
// Load File Names from Index
|
|
81
|
-
ReadResponse = yield this.LoadAllBufferRawData(fileNames);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
ReadResponse = yield this.LoadAllBufferRawData();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!("data" in ReadResponse)) {
|
|
88
|
-
return this.ResponseHelper.Error(ReadResponse);
|
|
89
|
-
}
|
|
90
|
-
const SearchedData = yield new Searcher_utils_1.default(ReadResponse.data, true).find(this.baseQuery, "data");
|
|
91
|
-
if (SearchedData.length === 0) {
|
|
56
|
+
const documentId = yield this.resolveTargetDocumentId();
|
|
57
|
+
if (!documentId) {
|
|
92
58
|
return this.ResponseHelper.Error("No data found with the specified query");
|
|
93
59
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
const SortedData = yield Sorter.sort("data"); // Sort the data
|
|
100
|
-
selectedFirstData = SortedData[0]; // Select the first data
|
|
101
|
-
fileName = selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.fileName; // Get the file name
|
|
102
|
-
}
|
|
103
|
-
documentId = fileName.split('.')[0];
|
|
104
|
-
// STEP 2: Acquire lock on the document (ACID: Isolation)
|
|
105
|
-
const lockResult = yield lockManager.acquireLock(documentId, operationId, timestamp);
|
|
106
|
-
if (!("data" in lockResult)) {
|
|
107
|
-
return this.ResponseHelper.Error("Lock acquisition failed");
|
|
60
|
+
const txn = new Transaction_service_1.default(this.path);
|
|
61
|
+
txn.delete({ documentId });
|
|
62
|
+
const commitResult = yield txn.commit();
|
|
63
|
+
if (!("data" in commitResult)) {
|
|
64
|
+
return commitResult;
|
|
108
65
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// the file is unaffected by that, but cleaning up the index with stale field
|
|
112
|
-
// values would remove the wrong index entry and leave a dangling one behind.
|
|
113
|
-
const freshRead = yield DocumentLoader_helper_1.default.loadDocuments(this.path, [fileName], true);
|
|
114
|
-
if (!("data" in freshRead) || freshRead.data.length === 0) {
|
|
66
|
+
const deleteOp = ((_a = commitResult.data.resolvedOperations) !== null && _a !== void 0 ? _a : []).find((op) => op.type === "DELETE" && op.documentId === documentId);
|
|
67
|
+
if (!deleteOp) {
|
|
115
68
|
return this.ResponseHelper.Error("Document no longer exists");
|
|
116
69
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return this.ResponseHelper.Error("Failed to delete data");
|
|
122
|
-
}
|
|
123
|
-
// Fire-and-forget: Remove from indexes and invalidate cache asynchronously for faster response
|
|
124
|
-
const isDeleted = yield new DeleteIndex_service_1.default(this.path).RemoveFromIndex(documentId, currentData).catch(() => { });
|
|
125
|
-
if (isDeleted) {
|
|
126
|
-
yield memory_operation_1.default.invalidateByDocument(this.path, documentId).catch(() => { });
|
|
127
|
-
return this.ResponseHelper.Success({
|
|
128
|
-
message: "Data deleted successfully",
|
|
129
|
-
deleteData: currentData,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
return this.ResponseHelper.Error("Failed to remove from index & invalidate cache");
|
|
134
|
-
}
|
|
70
|
+
return this.ResponseHelper.Success({
|
|
71
|
+
message: "Data deleted successfully",
|
|
72
|
+
deleteData: deleteOp.oldData,
|
|
73
|
+
});
|
|
135
74
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (documentId) {
|
|
139
|
-
yield lockManager.releaseLock(documentId).catch(() => { });
|
|
140
|
-
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return this.ResponseHelper.Error("Failed to delete data");
|
|
141
77
|
}
|
|
142
78
|
});
|
|
143
79
|
}
|
|
144
80
|
/**
|
|
145
81
|
* Deletes multiple documents that match the base query.
|
|
146
82
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* 4. Releases all locks
|
|
152
|
-
* 5. Returns success with the deleted data or an error
|
|
83
|
+
* Routed through a single Transaction covering the whole query, so the batch
|
|
84
|
+
* is WAL-backed: locking, fresh re-reads, and index sync (one rewrite per
|
|
85
|
+
* affected index field, not one per document) are all handled by
|
|
86
|
+
* Transaction/TransactionIndexManager.
|
|
153
87
|
*
|
|
154
88
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to either:
|
|
155
89
|
* - Success with a success message and the deleted data
|
|
156
|
-
* - Error if
|
|
157
|
-
* - No matching data is found
|
|
158
|
-
* - Lock acquisition fails
|
|
159
|
-
* - Any file deletion operation fails
|
|
160
|
-
* - The initial buffer data loading fails
|
|
90
|
+
* - Error if no matching data is found or the transaction failed
|
|
161
91
|
*/
|
|
162
92
|
deleteMany() {
|
|
163
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
|
|
165
|
-
const operationId = (0, crypto_1.randomUUID)();
|
|
166
|
-
const timestamp = Date.now();
|
|
167
|
-
const acquiredLocks = [];
|
|
94
|
+
var _a;
|
|
168
95
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
response = yield this.LoadAllBufferRawData();
|
|
178
|
-
}
|
|
179
|
-
if (!("data" in response)) {
|
|
180
|
-
return this.ResponseHelper.Error(response);
|
|
181
|
-
}
|
|
182
|
-
const SearchedData = yield new Searcher_utils_1.default(response.data, true).find(this.baseQuery, "data");
|
|
183
|
-
if (SearchedData.length === 0) {
|
|
96
|
+
const txn = new Transaction_service_1.default(this.path);
|
|
97
|
+
txn.delete(this.baseQuery);
|
|
98
|
+
const commitResult = yield txn.commit();
|
|
99
|
+
if (!("data" in commitResult)) {
|
|
100
|
+
return commitResult;
|
|
101
|
+
}
|
|
102
|
+
const deleteOps = ((_a = commitResult.data.resolvedOperations) !== null && _a !== void 0 ? _a : []).filter((op) => op.type === "DELETE");
|
|
103
|
+
if (deleteOps.length === 0) {
|
|
184
104
|
return this.ResponseHelper.Error("No data found with the specified query");
|
|
185
105
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
});
|
|
106
|
+
return this.ResponseHelper.Success({
|
|
107
|
+
message: "Data deleted successfully",
|
|
108
|
+
deleteData: deleteOps.map((op) => op.oldData),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return this.ResponseHelper.Error("Failed to delete data");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* to be sorted to the query
|
|
118
|
+
* @param {object} sort - The sort to be set.
|
|
119
|
+
* @returns {DeleteOperation} - An instance of the DeleteOperation class.
|
|
120
|
+
*/
|
|
121
|
+
Sort(sort) {
|
|
122
|
+
this.sort = sort;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Resolves the single document deleteOne should target: runs the same
|
|
127
|
+
* index-or-full-scan search deleteMany's Transaction path uses internally,
|
|
128
|
+
* then applies .Sort() (if set) and picks the first match - matching the
|
|
129
|
+
* "one specific document" semantics deleteOne has always had.
|
|
130
|
+
*
|
|
131
|
+
* @returns The target document's ID, or null if nothing matched.
|
|
132
|
+
*/
|
|
133
|
+
resolveTargetDocumentId() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
var _a;
|
|
136
|
+
let ReadResponse;
|
|
137
|
+
if (((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.documentId) !== undefined) {
|
|
138
|
+
const FilePath = [
|
|
139
|
+
`${this.baseQuery.documentId}${Keys_1.General.DBMS_File_EXT}`,
|
|
140
|
+
];
|
|
141
|
+
ReadResponse = yield this.LoadAllBufferRawData(FilePath);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const fileNames = yield new ReadIndex_service_1.ReadIndex(this.path).getFileFromIndex(this.baseQuery);
|
|
145
|
+
if (fileNames.length > 0) {
|
|
146
|
+
ReadResponse = yield this.LoadAllBufferRawData(fileNames);
|
|
228
147
|
}
|
|
229
148
|
else {
|
|
230
|
-
|
|
149
|
+
ReadResponse = yield this.LoadAllBufferRawData();
|
|
231
150
|
}
|
|
232
151
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (acquiredLocks.length > 0) {
|
|
236
|
-
yield lockManager.releaseAllLocks(acquiredLocks).catch(() => { });
|
|
237
|
-
}
|
|
152
|
+
if (!("data" in ReadResponse)) {
|
|
153
|
+
return null;
|
|
238
154
|
}
|
|
155
|
+
const SearchedData = yield new Searcher_utils_1.default(ReadResponse.data, true).find(this.baseQuery, "data");
|
|
156
|
+
if (SearchedData.length === 0) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
let selectedFirstData = SearchedData[0];
|
|
160
|
+
if (Object.keys(this.sort).length !== 0) {
|
|
161
|
+
const Sorter = new SortData_utils_1.default(SearchedData, this.sort);
|
|
162
|
+
const SortedData = yield Sorter.sort("data");
|
|
163
|
+
selectedFirstData = SortedData[0];
|
|
164
|
+
}
|
|
165
|
+
const fileName = selectedFirstData === null || selectedFirstData === void 0 ? void 0 : selectedFirstData.fileName;
|
|
166
|
+
return fileName ? fileName.split(".")[0] : null;
|
|
239
167
|
});
|
|
240
168
|
}
|
|
241
169
|
/**
|
|
242
170
|
* Loads all buffer raw data from the specified directory.
|
|
243
171
|
*
|
|
244
|
-
* This method performs the following steps:
|
|
245
|
-
* 1. Checks if the directory is locked.
|
|
246
|
-
* 2. If the directory is not locked, it lists all files in the directory.
|
|
247
|
-
* 3. Reads each file.
|
|
248
|
-
* 4. Stores the data in the `AllData` array.
|
|
249
|
-
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
250
|
-
*
|
|
251
172
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
252
|
-
*
|
|
253
|
-
* @throws {Error} Throws an error if any operation fails.
|
|
254
173
|
*/
|
|
255
174
|
LoadAllBufferRawData(documentIdDirectFile) {
|
|
256
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -264,29 +183,6 @@ class DeleteOperation {
|
|
|
264
183
|
return result;
|
|
265
184
|
});
|
|
266
185
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Deletes a file from the specified path.
|
|
269
|
-
*
|
|
270
|
-
* @param fileName - The name of the file to be deleted
|
|
271
|
-
* @returns A response object indicating success or failure
|
|
272
|
-
* Success response: { status: true, message: "File deleted successfully" }
|
|
273
|
-
* Error response: { status: false, message: <error message> }
|
|
274
|
-
* @private
|
|
275
|
-
*/
|
|
276
|
-
deleteFile(fileName) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
return yield this.fileManager.DeleteFileWithLock(this.path, fileName);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* to be sorted to the query
|
|
283
|
-
* @param {object} sort - The sort to be set.
|
|
284
|
-
* @returns {DeleteOperation} - An instance of the DeleteOperation class.
|
|
285
|
-
*/
|
|
286
|
-
Sort(sort) {
|
|
287
|
-
this.sort = sort;
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
186
|
}
|
|
291
187
|
exports.default = DeleteOperation;
|
|
292
188
|
//# sourceMappingURL=Delete.operation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delete.operation.js","sourceRoot":"","sources":["../../../source/Services/CRUD Operation/Delete.operation.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;;;AAMvD,mFAA0D;AAC1D,+FAAgE;
|
|
1
|
+
{"version":3,"file":"Delete.operation.js","sourceRoot":"","sources":["../../../source/Services/CRUD Operation/Delete.operation.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;;;AAMvD,mFAA0D;AAC1D,+FAAgE;AAEhE,qBAAqB;AACrB,kFAAoD;AACpD,kFAAmD;AACnD,iDAAiD;AACjD,kEAAuD;AAC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;YACd,CAAC;YAED,IAAI,iBAAiB,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YACxC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxC,MAAM,MAAM,GAAY,IAAI,wBAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC7D,MAAM,UAAU,GAAU,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACpD,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;YAED,MAAM,QAAQ,GAAW,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,QAAQ,CAAC;YACrD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,CAAC;KAAA;IAED;;;;OAIG;IACW,oBAAoB,CAChC,oBAA2C;;YAE3C,wEAAwE;YACxE,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,aAAa,CAC/C,IAAI,CAAC,IAAI,EACT,oBAAoB,EACpB,IAAI,CAAE,yCAAyC;aAChD,CAAC;YAEF,oDAAoD;YACpD,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBACrB,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC;YACzC,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF"}
|
|
@@ -6,70 +6,56 @@ export default class UpdateOperation {
|
|
|
6
6
|
private readonly ResponseHelper;
|
|
7
7
|
private allDataWithFileName;
|
|
8
8
|
private sort;
|
|
9
|
-
private updatedAt;
|
|
10
|
-
private readonly Insertion;
|
|
11
9
|
constructor(collectionName: string, path: string, baseQuery: object | any);
|
|
12
10
|
/**
|
|
13
11
|
* Updates a single document that matches the base query.
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* 6. Releases lock
|
|
13
|
+
* Routed through a single-operation Transaction, so the update is WAL-backed:
|
|
14
|
+
* locking, the fresh re-read under lock, atomic file replacement, and index
|
|
15
|
+
* sync are all handled by Transaction/TransactionIndexManager - the same
|
|
16
|
+
* machinery insert() already uses. This method's own job is just picking
|
|
17
|
+
* *which* document to target (honoring .Sort()), since Transaction.update()
|
|
18
|
+
* touches every document a query matches.
|
|
22
19
|
*
|
|
23
20
|
* @param newData - The new data to replace the existing document
|
|
24
21
|
* @returns A Promise resolving to:
|
|
25
22
|
* - Success with updated data and previous data if successful
|
|
26
|
-
* - Error if
|
|
27
|
-
* @throws May throw errors during file operations or data processing
|
|
23
|
+
* - Error if no document matched or the transaction failed
|
|
28
24
|
*/
|
|
29
25
|
UpdateOne(newData: object | any): Promise<SuccessInterface | ErrorInterface>;
|
|
30
26
|
/**
|
|
31
27
|
* Updates multiple documents that match the base query.
|
|
32
28
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* 4. Inserts new files with updated data for each document
|
|
38
|
-
* 5. Releases all locks
|
|
29
|
+
* Routed through a single Transaction covering the whole query, so the batch
|
|
30
|
+
* is WAL-backed: locking, fresh re-reads, atomic file replacement, and index
|
|
31
|
+
* sync (one rewrite per affected index field, not one per document) are all
|
|
32
|
+
* handled by Transaction/TransactionIndexManager.
|
|
39
33
|
*
|
|
40
34
|
* @param newData - The new data to replace the existing documents
|
|
41
35
|
* @returns A Promise resolving to:
|
|
42
|
-
* - Success with
|
|
43
|
-
* - Error if
|
|
44
|
-
* @throws May throw errors during file operations or data processing
|
|
36
|
+
* - Success with the count and IDs of updated documents
|
|
37
|
+
* - Error if no document matched or the transaction failed
|
|
45
38
|
*/
|
|
46
39
|
UpdateMany(newData: object | any): Promise<SuccessInterface | ErrorInterface>;
|
|
47
40
|
/**
|
|
48
|
-
* to be sorted to the query
|
|
49
|
-
this.updatedAt = this.createdAt; // Initially updatedAt is same as createdAt
|
|
41
|
+
* to be sorted to the query
|
|
50
42
|
* @param {object} sort - The sort to be set.
|
|
51
|
-
* @returns {
|
|
43
|
+
* @returns {UpdateOperation} - An instance of the UpdateOperation class.
|
|
52
44
|
*/
|
|
53
45
|
Sort(sort: object | any): UpdateOperation;
|
|
54
46
|
/**
|
|
55
|
-
*
|
|
47
|
+
* Resolves the single document UpdateOne should target: runs the same
|
|
48
|
+
* index-or-full-scan search UpdateMany's Transaction path uses internally,
|
|
49
|
+
* then applies .Sort() (if set) and picks the first match - matching the
|
|
50
|
+
* "one specific document" semantics UpdateOne has always had.
|
|
56
51
|
*
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
52
|
+
* @returns The target document's ID, or null if nothing matched.
|
|
53
|
+
*/
|
|
54
|
+
private resolveTargetDocumentId;
|
|
55
|
+
/**
|
|
56
|
+
* Loads all buffer raw data from the specified directory.
|
|
63
57
|
*
|
|
64
58
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
65
|
-
*
|
|
66
|
-
* @throws {Error} Throws an error if any operation fails.
|
|
67
59
|
*/
|
|
68
60
|
private LoadAllBufferRawData;
|
|
69
|
-
/**
|
|
70
|
-
* Inserts a document into the collection.
|
|
71
|
-
* @param {object} data - The data to be inserted.
|
|
72
|
-
* @returns {Promise<any>} - A promise that resolves with the response of the insertion operation.
|
|
73
|
-
*/
|
|
74
|
-
private insertUpdate;
|
|
75
61
|
}
|