lmcs-db 1.0.3 → 2.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 +247 -68
- package/dist/LmcsDB.d.ts +13 -0
- package/dist/LmcsDB.js +20 -5
- package/dist/LmcsDB.js.map +1 -1
- package/dist/core/collection.d.ts +33 -0
- package/dist/core/collection.js +287 -0
- package/dist/core/database.d.ts +35 -0
- package/dist/core/database.js +165 -0
- package/dist/core/indexer.d.ts +20 -0
- package/dist/core/indexer.js +89 -0
- package/dist/core/transaction-context.d.ts +13 -0
- package/dist/core/transaction-context.js +48 -0
- package/dist/core/transaction.d.ts +25 -0
- package/dist/core/transaction.js +122 -0
- package/dist/crypto/key-derivation.d.ts +0 -0
- package/dist/crypto/key-derivation.js +1 -0
- package/dist/crypto/manager.d.ts +22 -0
- package/dist/crypto/manager.js +76 -0
- package/dist/crypto/vault.d.ts +18 -0
- package/dist/crypto/vault.js +44 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +12 -9
- package/dist/persistence/AsyncWriteWorker.d.ts +30 -0
- package/dist/persistence/AsyncWriteWorker.js +76 -0
- package/dist/persistence/AsyncWriteWorker.js.map +1 -0
- package/dist/storage/BinaryStorage.d.ts +3 -0
- package/dist/storage/BinaryStorage.js +43 -5
- package/dist/storage/BinaryStorage.js.map +1 -1
- package/dist/storage/aol.d.ts +26 -0
- package/dist/storage/aol.js +166 -0
- package/dist/storage/base.d.ts +36 -0
- package/dist/storage/base.js +13 -0
- package/dist/storage/binary.d.ts +21 -0
- package/dist/storage/binary.js +124 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.js +13 -0
- package/dist/storage/json.d.ts +18 -0
- package/dist/storage/json.js +153 -0
- package/dist/storage/memory.d.ts +14 -0
- package/dist/storage/memory.js +42 -0
- package/dist/utils/checksum.d.ts +0 -0
- package/dist/utils/checksum.js +1 -0
- package/dist/utils/errors.d.ts +16 -0
- package/dist/utils/errors.js +37 -0
- package/dist/utils/lock.d.ts +9 -0
- package/dist/utils/lock.js +75 -0
- package/package.json +11 -5
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileLocker = void 0;
|
|
37
|
+
const lockfile = __importStar(require("proper-lockfile"));
|
|
38
|
+
class FileLocker {
|
|
39
|
+
locks = new Map();
|
|
40
|
+
queues = new Map();
|
|
41
|
+
async acquire(filePath, options) {
|
|
42
|
+
const release = await lockfile.lock(filePath, {
|
|
43
|
+
retries: options?.retries ?? 5,
|
|
44
|
+
stale: 5000,
|
|
45
|
+
realpath: false
|
|
46
|
+
});
|
|
47
|
+
this.locks.set(filePath, release);
|
|
48
|
+
}
|
|
49
|
+
async release(filePath) {
|
|
50
|
+
const release = this.locks.get(filePath);
|
|
51
|
+
if (release) {
|
|
52
|
+
await release();
|
|
53
|
+
this.locks.delete(filePath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async withLock(filePath, fn) {
|
|
57
|
+
// Serialize access within the same process
|
|
58
|
+
const currentQueue = this.queues.get(filePath) || Promise.resolve();
|
|
59
|
+
let result;
|
|
60
|
+
const nextPromise = currentQueue.then(async () => {
|
|
61
|
+
await this.acquire(filePath);
|
|
62
|
+
try {
|
|
63
|
+
result = await fn();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await this.release(filePath);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// Update queue, catching errors to ensure the chain continues
|
|
70
|
+
this.queues.set(filePath, nextPromise.catch(() => { }));
|
|
71
|
+
await nextPromise;
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.FileLocker = FileLocker;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lmcs-db",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Lightweight Modular Collection Storage - Secure & Transactional",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
|
-
"test": "
|
|
10
|
+
"test": "jest"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"database",
|
|
@@ -37,11 +37,17 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/leandroasilva/lmcs-db#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"proper-lockfile": "^4.1.2",
|
|
40
41
|
"uuid": "^11.1.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@types/
|
|
44
|
-
"
|
|
44
|
+
"@types/jest": "^30.0.0",
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
47
|
+
"@types/uuid": "^9.0.8",
|
|
48
|
+
"jest": "^30.2.0",
|
|
49
|
+
"ts-jest": "^29.4.6",
|
|
50
|
+
"tsx": "^4.21.0",
|
|
45
51
|
"typescript": "^5.0.0"
|
|
46
52
|
}
|
|
47
53
|
}
|