axiodb 12.11.27 → 13.0.0
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 +15 -45
- package/lib/Helper/DocumentLoader.helper.d.ts +1 -1
- package/lib/Helper/DocumentLoader.helper.js +3 -3
- package/lib/Helper/DocumentLoader.helper.js.map +1 -1
- package/lib/Helper/SortedIndexValues.helper.d.ts +45 -0
- package/lib/Helper/SortedIndexValues.helper.js +105 -0
- package/lib/Helper/SortedIndexValues.helper.js.map +1 -0
- package/lib/Services/Aggregation/Aggregation.Operation.d.ts +3 -8
- package/lib/Services/Aggregation/Aggregation.Operation.js +4 -11
- package/lib/Services/Aggregation/Aggregation.Operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Create.operation.js +14 -2
- package/lib/Services/CRUD Operation/Create.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Delete.operation.d.ts +3 -7
- package/lib/Services/CRUD Operation/Delete.operation.js +35 -22
- package/lib/Services/CRUD Operation/Delete.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Reader.operation.d.ts +3 -8
- package/lib/Services/CRUD Operation/Reader.operation.js +8 -12
- package/lib/Services/CRUD Operation/Reader.operation.js.map +1 -1
- package/lib/Services/CRUD Operation/Update.operation.d.ts +3 -18
- package/lib/Services/CRUD Operation/Update.operation.js +34 -48
- package/lib/Services/CRUD Operation/Update.operation.js.map +1 -1
- package/lib/Services/Collection/collection.operation.d.ts +8 -6
- package/lib/Services/Collection/collection.operation.js +35 -29
- package/lib/Services/Collection/collection.operation.js.map +1 -1
- package/lib/Services/Database/database.operation.d.ts +1 -3
- package/lib/Services/Database/database.operation.js +10 -59
- package/lib/Services/Database/database.operation.js.map +1 -1
- package/lib/Services/Index/DeleteIndex.service.js +10 -0
- package/lib/Services/Index/DeleteIndex.service.js.map +1 -1
- package/lib/Services/Index/Index.service.js +1 -0
- package/lib/Services/Index/Index.service.js.map +1 -1
- package/lib/Services/Index/IndexCache.service.d.ts +7 -0
- package/lib/Services/Index/IndexCache.service.js.map +1 -1
- package/lib/Services/Index/InsertIndex.service.js +12 -0
- package/lib/Services/Index/InsertIndex.service.js.map +1 -1
- package/lib/Services/Index/ReadIndex.service.d.ts +31 -0
- package/lib/Services/Index/ReadIndex.service.js +49 -0
- package/lib/Services/Index/ReadIndex.service.js.map +1 -1
- package/lib/Services/Transaction/Session.service.d.ts +1 -3
- package/lib/Services/Transaction/Session.service.js +2 -4
- package/lib/Services/Transaction/Session.service.js.map +1 -1
- package/lib/Services/Transaction/Transaction.service.d.ts +1 -4
- package/lib/Services/Transaction/Transaction.service.js +5 -22
- package/lib/Services/Transaction/Transaction.service.js.map +1 -1
- package/lib/Services/Transaction/TransactionIndexManager.service.d.ts +1 -3
- package/lib/Services/Transaction/TransactionIndexManager.service.js +26 -5
- package/lib/Services/Transaction/TransactionIndexManager.service.js.map +1 -1
- package/lib/Services/Transaction/TransactionRegistry.service.js +3 -3
- package/lib/Services/Transaction/TransactionRegistry.service.js.map +1 -1
- package/lib/Services/Transaction/WriteAheadLog.service.d.ts +1 -3
- package/lib/Services/Transaction/WriteAheadLog.service.js +4 -21
- package/lib/Services/Transaction/WriteAheadLog.service.js.map +1 -1
- package/lib/client/DatabaseProxy.d.ts +1 -1
- package/lib/client/DatabaseProxy.js +1 -3
- package/lib/client/DatabaseProxy.js.map +1 -1
- package/lib/config/DB.d.ts +0 -3
- package/lib/config/DB.js +0 -2
- package/lib/config/DB.js.map +1 -1
- package/lib/engine/Filesystem/FileManager.d.ts +7 -0
- package/lib/engine/Filesystem/FileManager.js +58 -1
- package/lib/engine/Filesystem/FileManager.js.map +1 -1
- package/lib/engine/node/WorkerForDataLoad.engine.js +8 -26
- package/lib/engine/node/WorkerForDataLoad.engine.js.map +1 -1
- package/lib/server/controller/Collections/Collection.controller.js +2 -2
- package/lib/server/controller/Collections/Collection.controller.js.map +1 -1
- package/lib/server/public/AxioControl/.vite/manifest.json +2 -2
- package/lib/server/public/AxioControl/assets/index-05O5admf.css +1 -0
- package/lib/server/public/AxioControl/assets/{index-DyJg6FRw.js → index-Ddne1B8d.js} +11 -11
- package/lib/server/public/AxioControl/index.html +2 -2
- package/lib/server/public/AxioControl/sw.js +1 -1
- package/lib/tcp/handler/handlers/Collection.handler.js +2 -2
- package/lib/tcp/handler/handlers/Collection.handler.js.map +1 -1
- package/lib/utility/BufferLoaderWithWorker.utils.d.ts +1 -3
- package/lib/utility/BufferLoaderWithWorker.utils.js +8 -32
- package/lib/utility/BufferLoaderWithWorker.utils.js.map +1 -1
- package/package.json +1 -3
- package/lib/Helper/Crypto.helper.d.ts +0 -14
- package/lib/Helper/Crypto.helper.js +0 -55
- package/lib/Helper/Crypto.helper.js.map +0 -1
- package/lib/Helper/CryptoGraphy.helper.d.ts +0 -15
- package/lib/Helper/CryptoGraphy.helper.js +0 -52
- package/lib/Helper/CryptoGraphy.helper.js.map +0 -1
- package/lib/server/public/AxioControl/assets/index-D3V1EZ2f.css +0 -1
package/README.md
CHANGED
|
@@ -184,8 +184,7 @@ await session.withTransaction(async (tx) => {
|
|
|
184
184
|
- **Async, Non-blocking Updates:** cache writes don't block the response path
|
|
185
185
|
- **Collection-Scoped Keys:** cache keys include the collection path, so there's no cross-collection collision
|
|
186
186
|
|
|
187
|
-
###
|
|
188
|
-
- **AES-256 Encryption:** optional per collection, with an auto-generated or custom key
|
|
187
|
+
### Security
|
|
189
188
|
- **File-level Isolation:** each document lives in its own `.axiodb` file with locking
|
|
190
189
|
- See [Built-in Web GUI & Authentication](#-built-in-web-gui--authentication-rbac) for RBAC/login and [Security Best Practices](#-best-practices) below
|
|
191
190
|
|
|
@@ -648,8 +647,6 @@ A Super Admin can create additional roles from the predefined permission catalog
|
|
|
648
647
|
```javascript
|
|
649
648
|
createCollection(
|
|
650
649
|
name: string, // Name of the collection (required)
|
|
651
|
-
isEncrypted?: boolean, // Whether to encrypt the collection (default: false)
|
|
652
|
-
encryptionKey?: string // Custom encryption key (optional, auto-generated if not provided)
|
|
653
650
|
)
|
|
654
651
|
```
|
|
655
652
|
|
|
@@ -661,16 +658,9 @@ const db = new AxioDB();
|
|
|
661
658
|
|
|
662
659
|
const userDB = await db.createDB("MyDB");
|
|
663
660
|
|
|
664
|
-
// Create a
|
|
661
|
+
// Create a collection
|
|
665
662
|
const userCollection = await userDB.createCollection("Users");
|
|
666
663
|
|
|
667
|
-
// Create an encrypted collection with a custom key
|
|
668
|
-
const secureCollection = await userDB.createCollection(
|
|
669
|
-
"SecureUsers",
|
|
670
|
-
true,
|
|
671
|
-
"mySecretKey",
|
|
672
|
-
);
|
|
673
|
-
|
|
674
664
|
await userCollection.insert({
|
|
675
665
|
name: "John Doe",
|
|
676
666
|
email: "john.doe@example.com",
|
|
@@ -708,25 +698,6 @@ const electronics = await products
|
|
|
708
698
|
.exec();
|
|
709
699
|
```
|
|
710
700
|
|
|
711
|
-
### Worked example: encrypted user records
|
|
712
|
-
|
|
713
|
-
```javascript
|
|
714
|
-
const users = await db.createCollection(
|
|
715
|
-
'users',
|
|
716
|
-
true, // encrypted
|
|
717
|
-
process.env.USER_ENCRYPTION_KEY, // custom key from env — see Best Practices below
|
|
718
|
-
);
|
|
719
|
-
|
|
720
|
-
await users.insert({
|
|
721
|
-
username: 'johndoe',
|
|
722
|
-
email: 'john@example.com',
|
|
723
|
-
passwordHash: hashedPassword,
|
|
724
|
-
createdAt: new Date(),
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
const user = await users.query({ username: 'johndoe' }).exec();
|
|
728
|
-
```
|
|
729
|
-
|
|
730
701
|
---
|
|
731
702
|
|
|
732
703
|
## 🌟 Advanced Features
|
|
@@ -747,7 +718,7 @@ const user = await users.query({ username: 'johndoe' }).exec();
|
|
|
747
718
|
|
|
748
719
|
### Database
|
|
749
720
|
|
|
750
|
-
- `createCollection(name: string
|
|
721
|
+
- `createCollection(name: string): Promise<Collection>`
|
|
751
722
|
- `deleteCollection(name: string): Promise<SuccessInterface | ErrorInterface>`
|
|
752
723
|
- `getCollectionInfo(): Promise<SuccessInterface>`
|
|
753
724
|
|
|
@@ -814,18 +785,20 @@ await collection.delete({ status: 'inactive' }).deleteMany();
|
|
|
814
785
|
|
|
815
786
|
## ✅ Best Practices
|
|
816
787
|
|
|
817
|
-
**Use environment variables for
|
|
788
|
+
**Use environment variables for TCP credentials — never hardcode them:**
|
|
818
789
|
|
|
819
790
|
```javascript
|
|
820
791
|
// ❌ Bad
|
|
821
|
-
const
|
|
792
|
+
const client = new AxioDBCloud("axiodb://localhost:27019", {
|
|
793
|
+
username: 'admin',
|
|
794
|
+
password: 'myPassword123',
|
|
795
|
+
});
|
|
822
796
|
|
|
823
797
|
// ✅ Good
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
);
|
|
798
|
+
const client = new AxioDBCloud("axiodb://localhost:27019", {
|
|
799
|
+
username: process.env.AXIODB_TCP_USERNAME,
|
|
800
|
+
password: process.env.AXIODB_TCP_PASSWORD,
|
|
801
|
+
});
|
|
829
802
|
```
|
|
830
803
|
|
|
831
804
|
**Use `documentId` for the fastest possible lookups** — it's the one field that's always indexed automatically, backed by `InMemoryCache`:
|
|
@@ -851,9 +824,8 @@ await database.deleteCollection('tempCollection');
|
|
|
851
824
|
await db.deleteDatabase('tempDB');
|
|
852
825
|
```
|
|
853
826
|
|
|
854
|
-
**
|
|
855
|
-
-
|
|
856
|
-
- Never hardcode keys — use environment variables or a secrets manager
|
|
827
|
+
**Access control:**
|
|
828
|
+
- Never hardcode credentials — use environment variables or a secrets manager
|
|
857
829
|
- Implement proper access controls and take regular backups
|
|
858
830
|
- For AxioDBCloud/GUI, rotate the default `admin` password immediately (see [Authentication & Access Control](#-built-in-web-gui--authentication-rbac))
|
|
859
831
|
|
|
@@ -865,7 +837,6 @@ For vulnerability reporting, see [SECURITY.md](SECURITY.md).
|
|
|
865
837
|
|
|
866
838
|
- **Tree Structure for Fast Data Retrieval:** hierarchical storage enables O(1) document lookups and efficient indexing. Each document is isolated in its own file, supporting selective loading and easy backup.
|
|
867
839
|
- **Worker Threads for Parallel Processing:** leverages Node.js Worker Threads for non-blocking I/O, multi-core utilization, and scalable performance — especially for read operations.
|
|
868
|
-
- **Two-Pointer Searching Algorithm:** optimized for range queries and filtered searches, minimizing memory usage and computational overhead.
|
|
869
840
|
- **`InMemoryCache` System:** automatic eviction policies, TTL support, and memory optimization, delivering sub-millisecond response times for frequently accessed data.
|
|
870
841
|
- **Query Processing Pipeline:** intelligent caching, parallelized processing, lazy evaluation, and just-in-time query optimization.
|
|
871
842
|
- **Single Instance Architecture:** ensures ACID compliance, strong data consistency, and simplified deployment — one `AxioDB` instance manages all databases and collections.
|
|
@@ -911,7 +882,6 @@ For vulnerability reporting, see [SECURITY.md](SECURITY.md).
|
|
|
911
882
|
| **Built-in caching** | ❌ | ❌ | ❌ | ✅ InMemoryCache |
|
|
912
883
|
| **Worker Threads** | ❌ | ❌ | ❌ | ✅ |
|
|
913
884
|
| **ACID Transactions** | ❌ | ❌ | ✅ | ✅ |
|
|
914
|
-
| **AES-256 Encryption** | ❌ | ❌ | ❌ | ✅ |
|
|
915
885
|
| **Aggregation Pipelines** | ❌ | Partial | ❌ | ✅ MongoDB-compatible |
|
|
916
886
|
| **TypeScript support** | ✅ | Partial | ✅ | ✅ Full |
|
|
917
887
|
| **Electron compatible** | ✅ | ✅ | ❌ (requires rebuild) | ✅ |
|
|
@@ -944,7 +914,7 @@ No. AxioDB is embedded (runs inside your app); MongoDB is a client-server databa
|
|
|
944
914
|
Yes — this is the primary use case it was built for. Zero native dependencies means no `electron-rebuild`, no platform-specific `.node` files, no compilation step.
|
|
945
915
|
|
|
946
916
|
**Q: How does AxioDB compare to better-sqlite3 / lowdb / nedb?**
|
|
947
|
-
See the [Comparisons](#-comparisons) tables above for the full breakdown — in short: no native bindings (unlike better-sqlite3), no single-file bottleneck (unlike lowdb), and actively maintained with TypeScript/transactions
|
|
917
|
+
See the [Comparisons](#-comparisons) tables above for the full breakdown — in short: no native bindings (unlike better-sqlite3), no single-file bottleneck (unlike lowdb), and actively maintained with TypeScript/transactions (unlike the abandoned nedb).
|
|
948
918
|
|
|
949
919
|
**Q: How many documents can AxioDB handle?**
|
|
950
920
|
Optimized for 10,000–500,000 documents. For 1M+, use PostgreSQL or MongoDB. `documentId` lookups take ~1ms on 10K documents with `InMemoryCache`.
|
|
@@ -6,5 +6,5 @@ import { SuccessInterface, ErrorInterface } from '../config/Interfaces/Helper/re
|
|
|
6
6
|
*/
|
|
7
7
|
export default class DocumentLoader {
|
|
8
8
|
private static readonly ResponseHelper;
|
|
9
|
-
static loadDocuments(collectionPath: string,
|
|
9
|
+
static loadDocuments(collectionPath: string, documentFiles?: string[], includeFileName?: boolean): Promise<SuccessInterface | ErrorInterface>;
|
|
10
10
|
}
|
|
@@ -21,8 +21,8 @@ const response_helper_1 = __importDefault(require("./response.helper"));
|
|
|
21
21
|
* full directory scanning (filtered to `.axiodb` files), loaded via worker threads.
|
|
22
22
|
*/
|
|
23
23
|
class DocumentLoader {
|
|
24
|
-
static loadDocuments(collectionPath_1,
|
|
25
|
-
return __awaiter(this, arguments, void 0, function* (collectionPath,
|
|
24
|
+
static loadDocuments(collectionPath_1, documentFiles_1) {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function* (collectionPath, documentFiles, includeFileName = false) {
|
|
26
26
|
try {
|
|
27
27
|
const dataFilesList = [];
|
|
28
28
|
if (documentFiles !== undefined) {
|
|
@@ -39,7 +39,7 @@ class DocumentLoader {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
// Loaded via worker threads for parallelism
|
|
42
|
-
const resultData = yield (0, BufferLoaderWithWorker_utils_1.default)(dataFilesList,
|
|
42
|
+
const resultData = yield (0, BufferLoaderWithWorker_utils_1.default)(dataFilesList, collectionPath, includeFileName);
|
|
43
43
|
return this.ResponseHelper.Success(resultData);
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentLoader.helper.js","sourceRoot":"","sources":["../../source/Helper/DocumentLoader.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uFAA+D;AAC/D,2GAAuE;AACvE,wEAA+C;AAE/C;;;;GAIG;AACH,MAAqB,cAAc;IAGjC,MAAM,CAAO,aAAa;6DACxB,cAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"DocumentLoader.helper.js","sourceRoot":"","sources":["../../source/Helper/DocumentLoader.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uFAA+D;AAC/D,2GAAuE;AACvE,wEAA+C;AAE/C;;;;GAIG;AACH,MAAqB,cAAc;IAGjC,MAAM,CAAO,aAAa;6DACxB,cAAsB,EACtB,aAAwB,EACxB,eAAe,GAAY,KAAK;YAEhC,IAAI,CAAC;gBACH,MAAM,aAAa,GAAa,EAAE,CAAC;gBAEnC,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;oBAChC,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;gBACvC,CAAC;qBAAM,CAAC;oBACN,MAAM,YAAY,GAAG,MAAM,IAAI,uBAAa,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;oBAE7E,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;wBAC3B,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CAC5D,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CACzB,CAAC;wBACF,aAAa,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;oBACrC,CAAC;yBAAM,CAAC;wBACN,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;oBAC/D,CAAC;gBACH,CAAC;gBAED,4CAA4C;gBAC5C,MAAM,UAAU,GAAG,MAAM,IAAA,sCAAgB,EACvC,aAAa,EACb,cAAc,EACd,eAAe,CAChB,CAAC;gBAEF,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACjD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KAAA;CACF;AArCyB,6BAAc,GAAG,IAAI,yBAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maintains a sorted array of unique numeric index values and provides
|
|
3
|
+
* binary-search bounds over it, so range queries ($gt/$gte/$lt/$lte) can
|
|
4
|
+
* resolve against an index instead of falling back to a full collection scan.
|
|
5
|
+
*/
|
|
6
|
+
export default class SortedIndexValues {
|
|
7
|
+
/**
|
|
8
|
+
* Index of the first element >= target (a.k.a. lower_bound).
|
|
9
|
+
* Returns `sortedValues.length` if every element is smaller than target.
|
|
10
|
+
*/
|
|
11
|
+
static lowerBound(sortedValues: number[], target: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Index of the first element > target (a.k.a. upper_bound).
|
|
14
|
+
* Returns `sortedValues.length` if every element is <= target.
|
|
15
|
+
*/
|
|
16
|
+
static upperBound(sortedValues: number[], target: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Inserts `value` keeping the array sorted and free of duplicates.
|
|
19
|
+
* No-op if the value is already present.
|
|
20
|
+
*/
|
|
21
|
+
static insertSorted(sortedValues: number[], value: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Removes `value` from the sorted array, if present.
|
|
24
|
+
*/
|
|
25
|
+
static removeSorted(sortedValues: number[], value: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Builds a sorted, de-duplicated numeric array from existing hash-map keys.
|
|
28
|
+
* Used to lazily backfill indexes created before range support existed.
|
|
29
|
+
* Non-numeric keys are skipped (range queries only ever apply to numbers).
|
|
30
|
+
*/
|
|
31
|
+
static backfillFromKeys(keys: string[]): number[];
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the inclusive [startIndex, endIndex] slice of `sortedValues` that
|
|
34
|
+
* satisfies the given range operators. Returns null if the range is empty.
|
|
35
|
+
*/
|
|
36
|
+
static resolveRange(sortedValues: number[], range: {
|
|
37
|
+
$gt?: number;
|
|
38
|
+
$gte?: number;
|
|
39
|
+
$lt?: number;
|
|
40
|
+
$lte?: number;
|
|
41
|
+
}): {
|
|
42
|
+
startIndex: number;
|
|
43
|
+
endIndex: number;
|
|
44
|
+
} | null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Maintains a sorted array of unique numeric index values and provides
|
|
5
|
+
* binary-search bounds over it, so range queries ($gt/$gte/$lt/$lte) can
|
|
6
|
+
* resolve against an index instead of falling back to a full collection scan.
|
|
7
|
+
*/
|
|
8
|
+
class SortedIndexValues {
|
|
9
|
+
/**
|
|
10
|
+
* Index of the first element >= target (a.k.a. lower_bound).
|
|
11
|
+
* Returns `sortedValues.length` if every element is smaller than target.
|
|
12
|
+
*/
|
|
13
|
+
static lowerBound(sortedValues, target) {
|
|
14
|
+
let low = 0;
|
|
15
|
+
let high = sortedValues.length;
|
|
16
|
+
while (low < high) {
|
|
17
|
+
const mid = (low + high) >>> 1;
|
|
18
|
+
if (sortedValues[mid] < target) {
|
|
19
|
+
low = mid + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
high = mid;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return low;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Index of the first element > target (a.k.a. upper_bound).
|
|
29
|
+
* Returns `sortedValues.length` if every element is <= target.
|
|
30
|
+
*/
|
|
31
|
+
static upperBound(sortedValues, target) {
|
|
32
|
+
let low = 0;
|
|
33
|
+
let high = sortedValues.length;
|
|
34
|
+
while (low < high) {
|
|
35
|
+
const mid = (low + high) >>> 1;
|
|
36
|
+
if (sortedValues[mid] <= target) {
|
|
37
|
+
low = mid + 1;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
high = mid;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return low;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Inserts `value` keeping the array sorted and free of duplicates.
|
|
47
|
+
* No-op if the value is already present.
|
|
48
|
+
*/
|
|
49
|
+
static insertSorted(sortedValues, value) {
|
|
50
|
+
const pos = this.lowerBound(sortedValues, value);
|
|
51
|
+
if (sortedValues[pos] !== value) {
|
|
52
|
+
sortedValues.splice(pos, 0, value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Removes `value` from the sorted array, if present.
|
|
57
|
+
*/
|
|
58
|
+
static removeSorted(sortedValues, value) {
|
|
59
|
+
const pos = this.lowerBound(sortedValues, value);
|
|
60
|
+
if (sortedValues[pos] === value) {
|
|
61
|
+
sortedValues.splice(pos, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds a sorted, de-duplicated numeric array from existing hash-map keys.
|
|
66
|
+
* Used to lazily backfill indexes created before range support existed.
|
|
67
|
+
* Non-numeric keys are skipped (range queries only ever apply to numbers).
|
|
68
|
+
*/
|
|
69
|
+
static backfillFromKeys(keys) {
|
|
70
|
+
const numericValues = [];
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
const numericValue = Number(key);
|
|
73
|
+
if (!Number.isNaN(numericValue)) {
|
|
74
|
+
numericValues.push(numericValue);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return numericValues.sort((a, b) => a - b);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolves the inclusive [startIndex, endIndex] slice of `sortedValues` that
|
|
81
|
+
* satisfies the given range operators. Returns null if the range is empty.
|
|
82
|
+
*/
|
|
83
|
+
static resolveRange(sortedValues, range) {
|
|
84
|
+
let startIndex = 0;
|
|
85
|
+
if (range.$gte !== undefined) {
|
|
86
|
+
startIndex = Math.max(startIndex, this.lowerBound(sortedValues, range.$gte));
|
|
87
|
+
}
|
|
88
|
+
if (range.$gt !== undefined) {
|
|
89
|
+
startIndex = Math.max(startIndex, this.upperBound(sortedValues, range.$gt));
|
|
90
|
+
}
|
|
91
|
+
let endIndex = sortedValues.length - 1;
|
|
92
|
+
if (range.$lte !== undefined) {
|
|
93
|
+
endIndex = Math.min(endIndex, this.upperBound(sortedValues, range.$lte) - 1);
|
|
94
|
+
}
|
|
95
|
+
if (range.$lt !== undefined) {
|
|
96
|
+
endIndex = Math.min(endIndex, this.lowerBound(sortedValues, range.$lt) - 1);
|
|
97
|
+
}
|
|
98
|
+
if (startIndex > endIndex) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return { startIndex, endIndex };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.default = SortedIndexValues;
|
|
105
|
+
//# sourceMappingURL=SortedIndexValues.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortedIndexValues.helper.js","sourceRoot":"","sources":["../../source/Helper/SortedIndexValues.helper.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH;IACE;;;OAGG;IACI,MAAM,CAAC,UAAU,CAAC,YAAsB,EAAE,MAAc;QAC7D,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,IAAI,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC;QAC/B,OAAO,GAAG,GAAG,IAAI,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;gBAC/B,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,GAAG,CAAC;YACb,CAAC;QACH,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GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,UAAU,GAAG,QAAQ,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -6,7 +6,6 @@ import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper
|
|
|
6
6
|
* It supports various stages including $match, $group, $sort, $project, $limit, $skip,
|
|
7
7
|
* $unwind, and $addFields.
|
|
8
8
|
*
|
|
9
|
-
* The class can handle both encrypted and non-encrypted data collections.
|
|
10
9
|
*/
|
|
11
10
|
export default class Aggregation {
|
|
12
11
|
private AllData;
|
|
@@ -14,11 +13,7 @@ export default class Aggregation {
|
|
|
14
13
|
private path;
|
|
15
14
|
private readonly collectionName;
|
|
16
15
|
private readonly ResponseHelper;
|
|
17
|
-
|
|
18
|
-
private encryptionKey?;
|
|
19
|
-
private cryptoInstance?;
|
|
20
|
-
private readonly Converter;
|
|
21
|
-
constructor(collectionName: string, path: string, Pipeline: object[] | any, isEncrypted?: boolean, encryptionKey?: string);
|
|
16
|
+
constructor(collectionName: string, path: string, Pipeline: object[] | any);
|
|
22
17
|
/**
|
|
23
18
|
* Executes the aggregation pipeline on the data.
|
|
24
19
|
*
|
|
@@ -45,8 +40,8 @@ export default class Aggregation {
|
|
|
45
40
|
* This method performs the following steps:
|
|
46
41
|
* 1. Checks if the directory is locked.
|
|
47
42
|
* 2. If the directory is not locked, it lists all files in the directory.
|
|
48
|
-
* 3. Reads each file
|
|
49
|
-
* 4. Stores the
|
|
43
|
+
* 3. Reads each file.
|
|
44
|
+
* 4. Stores the data in the `AllData` array.
|
|
50
45
|
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
51
46
|
*
|
|
52
47
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
@@ -13,9 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
|
|
16
|
-
const Crypto_helper_1 = require("../../Helper/Crypto.helper");
|
|
17
16
|
const DocumentLoader_helper_1 = __importDefault(require("../../Helper/DocumentLoader.helper"));
|
|
18
|
-
const Converter_helper_1 = __importDefault(require("../../Helper/Converter.helper"));
|
|
19
17
|
const Console_helper_1 = __importDefault(require("../../Helper/Console.helper"));
|
|
20
18
|
const ReadIndex_service_1 = require("../Index/ReadIndex.service");
|
|
21
19
|
/**
|
|
@@ -25,21 +23,16 @@ const ReadIndex_service_1 = require("../Index/ReadIndex.service");
|
|
|
25
23
|
* It supports various stages including $match, $group, $sort, $project, $limit, $skip,
|
|
26
24
|
* $unwind, and $addFields.
|
|
27
25
|
*
|
|
28
|
-
* The class can handle both encrypted and non-encrypted data collections.
|
|
29
26
|
*/
|
|
30
27
|
class Aggregation {
|
|
31
|
-
constructor(collectionName, path, Pipeline
|
|
28
|
+
constructor(collectionName, path, Pipeline) {
|
|
32
29
|
// property to store the data
|
|
33
30
|
this.AllData = [];
|
|
34
31
|
this.collectionName = collectionName;
|
|
35
32
|
this.path = path;
|
|
36
|
-
this.isEncrypted = isEncrypted;
|
|
37
|
-
this.encryptionKey = encryptionKey;
|
|
38
33
|
this.AllData = [];
|
|
39
34
|
this.Pipeline = Pipeline;
|
|
40
35
|
this.ResponseHelper = new response_helper_1.default();
|
|
41
|
-
this.Converter = new Converter_helper_1.default();
|
|
42
|
-
this.cryptoInstance = new Crypto_helper_1.CryptoHelper(this.encryptionKey);
|
|
43
36
|
}
|
|
44
37
|
/**
|
|
45
38
|
* Executes the aggregation pipeline on the data.
|
|
@@ -248,8 +241,8 @@ class Aggregation {
|
|
|
248
241
|
* This method performs the following steps:
|
|
249
242
|
* 1. Checks if the directory is locked.
|
|
250
243
|
* 2. If the directory is not locked, it lists all files in the directory.
|
|
251
|
-
* 3. Reads each file
|
|
252
|
-
* 4. Stores the
|
|
244
|
+
* 3. Reads each file.
|
|
245
|
+
* 4. Stores the data in the `AllData` array.
|
|
253
246
|
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
254
247
|
*
|
|
255
248
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|
|
@@ -259,7 +252,7 @@ class Aggregation {
|
|
|
259
252
|
LoadAllBufferRawData(documentIdDirectFile) {
|
|
260
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
261
254
|
// Use shared DocumentLoader helper (DRY - consolidates duplicated code)
|
|
262
|
-
const result = yield DocumentLoader_helper_1.default.loadDocuments(this.path,
|
|
255
|
+
const result = yield DocumentLoader_helper_1.default.loadDocuments(this.path, documentIdDirectFile, false // Don't include fileName for Aggregation
|
|
263
256
|
);
|
|
264
257
|
// Store result in AllData if successful
|
|
265
258
|
if ("data" in result) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aggregation.Operation.js","sourceRoot":"","sources":["../../../source/Services/Aggregation/Aggregation.Operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mFAA0D;
|
|
1
|
+
{"version":3,"file":"Aggregation.Operation.js","sourceRoot":"","sources":["../../../source/Services/Aggregation/Aggregation.Operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mFAA0D;AAK1D,+FAAgE;AAChE,iFAAkD;AAClD,kEAAuD;AAevD;;;;;;;GAOG;AACH;IAQE,YACE,cAAsB,EACtB,IAAY,EACZ,QAAwB;QAV1B,6BAA6B;QACrB,YAAO,GAAU,EAAE,CAAC;QAW1B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CA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,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;KAAA;IAED;;;;;;;;;;;;;OAaG;IACW,oBAAoB,CAAC,oBAA2C;;YAG5E,wEAAwE;YACxE,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,aAAa,CAC/C,IAAI,CAAC,IAAI,EACT,oBAAoB,EACpB,KAAK,CAAE,yCAAyC;aACjD,CAAC;YAEF,wCAAwC;YACxC,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;YAC7B,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF"}
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
16
17
|
const FileManager_1 = __importDefault(require("../../engine/Filesystem/FileManager"));
|
|
17
18
|
const UniqueGenerator_helper_1 = __importDefault(require("../../Helper/UniqueGenerator.helper"));
|
|
18
19
|
const response_helper_1 = __importDefault(require("../../Helper/response.helper"));
|
|
@@ -46,9 +47,20 @@ class Insertion {
|
|
|
46
47
|
// Sanitize documentId to prevent directory traversal attacks
|
|
47
48
|
const sanitizedDocumentId = PathSanitizer_helper_1.default.sanitizePathComponent(documentId);
|
|
48
49
|
const filePath = PathSanitizer_helper_1.default.safePath(this.path, `${sanitizedDocumentId}${Keys_1.General.DBMS_File_EXT}`);
|
|
49
|
-
//
|
|
50
|
-
|
|
50
|
+
// Write to a temp file, then atomically rename it over the target path.
|
|
51
|
+
// `rename()` replaces an existing destination in a single filesystem operation
|
|
52
|
+
// (same pattern Transaction.applyChanges() already uses), so a concurrent
|
|
53
|
+
// unlocked reader of filePath always sees either the old file or the new one -
|
|
54
|
+
// never a transient "file doesn't exist" gap, which a plain overwrite (or the
|
|
55
|
+
// old delete-then-recreate update path) could expose.
|
|
56
|
+
const fileManager = new FileManager_1.default();
|
|
57
|
+
const tempFilePath = `${filePath}.tmp-${(0, crypto_1.randomUUID)()}`;
|
|
58
|
+
const WriteResponse = yield fileManager.WriteFile(tempFilePath, this.Converter.ToString(data));
|
|
51
59
|
if (WriteResponse.status) {
|
|
60
|
+
const moveResponse = yield fileManager.MoveFile(tempFilePath, filePath);
|
|
61
|
+
if (!moveResponse.status) {
|
|
62
|
+
return new response_helper_1.default().Error("Failed to save data");
|
|
63
|
+
}
|
|
52
64
|
return new response_helper_1.default().Success({
|
|
53
65
|
Message: "Data Inserted Successfully",
|
|
54
66
|
documentId: documentId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.operation.js","sourceRoot":"","sources":["../../../source/Services/CRUD Operation/Create.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,sFAA8D;AAE9D,iGAAkE;AAClE,mFAA0D;AAK1D,iDAAiD;AACjD,qFAAsD;AACtD,6FAA8D;AAE9D;;GAEG;AACH;IAKE;;;;OAIG;IACH,YAAY,cAAsB,EAAE,IAAkB;QACpD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACU,IAAI,CACf,IAAkB,EAClB,kBAA2B;;YAE3B,IAAI,CAAC;gBACH,MAAM,UAAU,GACd,kBAAkB,KAAK,SAAS;oBAC9B,CAAC,CAAC,MAAM,IAAI,CAAC,wBAAwB,EAAE;oBACvC,CAAC,CAAC,kBAAkB,CAAC;gBAEzB,6DAA6D;gBAC7D,MAAM,mBAAmB,GAAG,8BAAa,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;gBAC5E,MAAM,QAAQ,GAAG,8BAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,mBAAmB,GAAG,cAAO,CAAC,aAAa,EAAE,CAAC,CAAC;gBAErG,sDAAsD;gBACtD,MAAM,
|
|
1
|
+
{"version":3,"file":"Create.operation.js","sourceRoot":"","sources":["../../../source/Services/CRUD Operation/Create.operation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,mCAAoC;AACpC,sFAA8D;AAE9D,iGAAkE;AAClE,mFAA0D;AAK1D,iDAAiD;AACjD,qFAAsD;AACtD,6FAA8D;AAE9D;;GAEG;AACH;IAKE;;;;OAIG;IACH,YAAY,cAAsB,EAAE,IAAkB;QACpD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;IACnC,CAAC;IAED;;;OAGG;IACU,IAAI,CACf,IAAkB,EAClB,kBAA2B;;YAE3B,IAAI,CAAC;gBACH,MAAM,UAAU,GACd,kBAAkB,KAAK,SAAS;oBAC9B,CAAC,CAAC,MAAM,IAAI,CAAC,wBAAwB,EAAE;oBACvC,CAAC,CAAC,kBAAkB,CAAC;gBAEzB,6DAA6D;gBAC7D,MAAM,mBAAmB,GAAG,8BAAa,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;gBAC5E,MAAM,QAAQ,GAAG,8BAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,mBAAmB,GAAG,cAAO,CAAC,aAAa,EAAE,CAAC,CAAC;gBAErG,wEAAwE;gBACxE,+EAA+E;gBAC/E,0EAA0E;gBAC1E,+EAA+E;gBAC/E,8EAA8E;gBAC9E,sDAAsD;gBACtD,MAAM,WAAW,GAAG,IAAI,qBAAW,EAAE,CAAC;gBACtC,MAAM,YAAY,GAAG,GAAG,QAAQ,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;gBACvD,MAAM,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YAC5B,CAAC,QAAQ,OAAO,EAAE;YAElB,OAAO,EAAE,CAAC;QACZ,CAAC;KAAA;CACF"}
|
|
@@ -7,15 +7,11 @@ export default class DeleteOperation {
|
|
|
7
7
|
protected readonly collectionName: string;
|
|
8
8
|
private readonly baseQuery;
|
|
9
9
|
private readonly path;
|
|
10
|
-
private readonly isEncrypted;
|
|
11
|
-
private readonly encryptionKey;
|
|
12
10
|
private readonly ResponseHelper;
|
|
13
|
-
private readonly cryptoInstance?;
|
|
14
|
-
private readonly Converter;
|
|
15
11
|
private readonly fileManager;
|
|
16
12
|
private allDataWithFileName;
|
|
17
13
|
private sort;
|
|
18
|
-
constructor(collectionName: string, path: string, baseQuery: object | any
|
|
14
|
+
constructor(collectionName: string, path: string, baseQuery: object | any);
|
|
19
15
|
/**
|
|
20
16
|
* Deletes a single document that matches the base query.
|
|
21
17
|
*
|
|
@@ -59,8 +55,8 @@ export default class DeleteOperation {
|
|
|
59
55
|
* This method performs the following steps:
|
|
60
56
|
* 1. Checks if the directory is locked.
|
|
61
57
|
* 2. If the directory is not locked, it lists all files in the directory.
|
|
62
|
-
* 3. Reads each file
|
|
63
|
-
* 4. Stores the
|
|
58
|
+
* 3. Reads each file.
|
|
59
|
+
* 4. Stores the data in the `AllData` array.
|
|
64
60
|
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
|
|
65
61
|
*
|
|
66
62
|
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
|