s3db.js 8.1.3 → 8.2.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/bin/cli.js +430 -0
- package/dist/s3db.cjs.js +41 -25
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +41 -25
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +41 -25
- package/dist/s3db.iife.min.js +1 -1
- package/mcp/server.js +2 -1
- package/package.json +6 -2
- package/src/database.class.js +3 -2
- package/src/plugins/audit.plugin.js +43 -22
package/dist/s3db.es.js
CHANGED
|
@@ -1363,17 +1363,13 @@ class AuditPlugin extends plugin_class_default {
|
|
|
1363
1363
|
const plugin = this;
|
|
1364
1364
|
resource.deleteMany = async function(ids) {
|
|
1365
1365
|
const objectsToDelete = [];
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
objectsToDelete.push({ id });
|
|
1373
|
-
}
|
|
1366
|
+
for (const id of ids) {
|
|
1367
|
+
const [ok, err, fetched] = await try_fn_default(() => resource.get(id));
|
|
1368
|
+
if (ok) {
|
|
1369
|
+
objectsToDelete.push(fetched);
|
|
1370
|
+
} else {
|
|
1371
|
+
objectsToDelete.push({ id });
|
|
1374
1372
|
}
|
|
1375
|
-
} else {
|
|
1376
|
-
objectsToDelete.push(...ids.map((id) => ({ id })));
|
|
1377
1373
|
}
|
|
1378
1374
|
const result = await originalDeleteMany(ids);
|
|
1379
1375
|
for (const oldData of objectsToDelete) {
|
|
@@ -1478,18 +1474,37 @@ class AuditPlugin extends plugin_class_default {
|
|
|
1478
1474
|
async getAuditLogs(options = {}) {
|
|
1479
1475
|
if (!this.auditResource) return [];
|
|
1480
1476
|
const { resourceName, operation, recordId, partition, startDate, endDate, limit = 100, offset = 0 } = options;
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
if (
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1477
|
+
const hasFilters = resourceName || operation || recordId || partition || startDate || endDate;
|
|
1478
|
+
let items = [];
|
|
1479
|
+
if (hasFilters) {
|
|
1480
|
+
const fetchSize = Math.min(1e4, Math.max(1e3, (limit + offset) * 20));
|
|
1481
|
+
const result = await this.auditResource.list({ limit: fetchSize });
|
|
1482
|
+
items = result || [];
|
|
1483
|
+
if (resourceName) {
|
|
1484
|
+
items = items.filter((log) => log.resourceName === resourceName);
|
|
1485
|
+
}
|
|
1486
|
+
if (operation) {
|
|
1487
|
+
items = items.filter((log) => log.operation === operation);
|
|
1488
|
+
}
|
|
1489
|
+
if (recordId) {
|
|
1490
|
+
items = items.filter((log) => log.recordId === recordId);
|
|
1491
|
+
}
|
|
1492
|
+
if (partition) {
|
|
1493
|
+
items = items.filter((log) => log.partition === partition);
|
|
1494
|
+
}
|
|
1495
|
+
if (startDate || endDate) {
|
|
1496
|
+
items = items.filter((log) => {
|
|
1497
|
+
const timestamp = new Date(log.timestamp);
|
|
1498
|
+
if (startDate && timestamp < new Date(startDate)) return false;
|
|
1499
|
+
if (endDate && timestamp > new Date(endDate)) return false;
|
|
1500
|
+
return true;
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
return items.slice(offset, offset + limit);
|
|
1504
|
+
} else {
|
|
1505
|
+
const result = await this.auditResource.page({ size: limit, offset });
|
|
1506
|
+
return result.items || [];
|
|
1507
|
+
}
|
|
1493
1508
|
}
|
|
1494
1509
|
async getRecordHistory(resourceName, recordId) {
|
|
1495
1510
|
return await this.getAuditLogs({ resourceName, recordId });
|
|
@@ -13503,7 +13518,7 @@ class Database extends EventEmitter {
|
|
|
13503
13518
|
this.id = idGenerator(7);
|
|
13504
13519
|
this.version = "1";
|
|
13505
13520
|
this.s3dbVersion = (() => {
|
|
13506
|
-
const [ok, err, version] = try_fn_default(() => true ? "8.
|
|
13521
|
+
const [ok, err, version] = try_fn_default(() => true ? "8.2.0" : "latest");
|
|
13507
13522
|
return ok ? version : "latest";
|
|
13508
13523
|
})();
|
|
13509
13524
|
this.resources = {};
|
|
@@ -13511,7 +13526,8 @@ class Database extends EventEmitter {
|
|
|
13511
13526
|
this.options = options;
|
|
13512
13527
|
this.verbose = options.verbose || false;
|
|
13513
13528
|
this.parallelism = parseInt(options.parallelism + "") || 10;
|
|
13514
|
-
this.plugins =
|
|
13529
|
+
this.plugins = options.plugins || [];
|
|
13530
|
+
this.pluginRegistry = {};
|
|
13515
13531
|
this.pluginList = options.plugins || [];
|
|
13516
13532
|
this.cache = options.cache;
|
|
13517
13533
|
this.passphrase = options.passphrase || "secret";
|
|
@@ -13805,7 +13821,7 @@ class Database extends EventEmitter {
|
|
|
13805
13821
|
await plugin.setup(db);
|
|
13806
13822
|
if (plugin.afterSetup) await plugin.afterSetup();
|
|
13807
13823
|
const pluginName = this._getPluginName(plugin);
|
|
13808
|
-
this.
|
|
13824
|
+
this.pluginRegistry[pluginName] = plugin;
|
|
13809
13825
|
});
|
|
13810
13826
|
await Promise.all(setupProms);
|
|
13811
13827
|
const startProms = plugins.map(async (plugin) => {
|