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.iife.js
CHANGED
|
@@ -1353,17 +1353,13 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
1353
1353
|
const plugin = this;
|
|
1354
1354
|
resource.deleteMany = async function(ids) {
|
|
1355
1355
|
const objectsToDelete = [];
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
objectsToDelete.push({ id });
|
|
1363
|
-
}
|
|
1356
|
+
for (const id of ids) {
|
|
1357
|
+
const [ok, err, fetched] = await try_fn_default(() => resource.get(id));
|
|
1358
|
+
if (ok) {
|
|
1359
|
+
objectsToDelete.push(fetched);
|
|
1360
|
+
} else {
|
|
1361
|
+
objectsToDelete.push({ id });
|
|
1364
1362
|
}
|
|
1365
|
-
} else {
|
|
1366
|
-
objectsToDelete.push(...ids.map((id) => ({ id })));
|
|
1367
1363
|
}
|
|
1368
1364
|
const result = await originalDeleteMany(ids);
|
|
1369
1365
|
for (const oldData of objectsToDelete) {
|
|
@@ -1468,18 +1464,37 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
1468
1464
|
async getAuditLogs(options = {}) {
|
|
1469
1465
|
if (!this.auditResource) return [];
|
|
1470
1466
|
const { resourceName, operation, recordId, partition, startDate, endDate, limit = 100, offset = 0 } = options;
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
if (
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1467
|
+
const hasFilters = resourceName || operation || recordId || partition || startDate || endDate;
|
|
1468
|
+
let items = [];
|
|
1469
|
+
if (hasFilters) {
|
|
1470
|
+
const fetchSize = Math.min(1e4, Math.max(1e3, (limit + offset) * 20));
|
|
1471
|
+
const result = await this.auditResource.list({ limit: fetchSize });
|
|
1472
|
+
items = result || [];
|
|
1473
|
+
if (resourceName) {
|
|
1474
|
+
items = items.filter((log) => log.resourceName === resourceName);
|
|
1475
|
+
}
|
|
1476
|
+
if (operation) {
|
|
1477
|
+
items = items.filter((log) => log.operation === operation);
|
|
1478
|
+
}
|
|
1479
|
+
if (recordId) {
|
|
1480
|
+
items = items.filter((log) => log.recordId === recordId);
|
|
1481
|
+
}
|
|
1482
|
+
if (partition) {
|
|
1483
|
+
items = items.filter((log) => log.partition === partition);
|
|
1484
|
+
}
|
|
1485
|
+
if (startDate || endDate) {
|
|
1486
|
+
items = items.filter((log) => {
|
|
1487
|
+
const timestamp = new Date(log.timestamp);
|
|
1488
|
+
if (startDate && timestamp < new Date(startDate)) return false;
|
|
1489
|
+
if (endDate && timestamp > new Date(endDate)) return false;
|
|
1490
|
+
return true;
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
return items.slice(offset, offset + limit);
|
|
1494
|
+
} else {
|
|
1495
|
+
const result = await this.auditResource.page({ size: limit, offset });
|
|
1496
|
+
return result.items || [];
|
|
1497
|
+
}
|
|
1483
1498
|
}
|
|
1484
1499
|
async getRecordHistory(resourceName, recordId) {
|
|
1485
1500
|
return await this.getAuditLogs({ resourceName, recordId });
|
|
@@ -13493,7 +13508,7 @@ ${errorDetails}`,
|
|
|
13493
13508
|
this.id = idGenerator(7);
|
|
13494
13509
|
this.version = "1";
|
|
13495
13510
|
this.s3dbVersion = (() => {
|
|
13496
|
-
const [ok, err, version] = try_fn_default(() => true ? "8.
|
|
13511
|
+
const [ok, err, version] = try_fn_default(() => true ? "8.2.0" : "latest");
|
|
13497
13512
|
return ok ? version : "latest";
|
|
13498
13513
|
})();
|
|
13499
13514
|
this.resources = {};
|
|
@@ -13501,7 +13516,8 @@ ${errorDetails}`,
|
|
|
13501
13516
|
this.options = options;
|
|
13502
13517
|
this.verbose = options.verbose || false;
|
|
13503
13518
|
this.parallelism = parseInt(options.parallelism + "") || 10;
|
|
13504
|
-
this.plugins =
|
|
13519
|
+
this.plugins = options.plugins || [];
|
|
13520
|
+
this.pluginRegistry = {};
|
|
13505
13521
|
this.pluginList = options.plugins || [];
|
|
13506
13522
|
this.cache = options.cache;
|
|
13507
13523
|
this.passphrase = options.passphrase || "secret";
|
|
@@ -13795,7 +13811,7 @@ ${errorDetails}`,
|
|
|
13795
13811
|
await plugin.setup(db);
|
|
13796
13812
|
if (plugin.afterSetup) await plugin.afterSetup();
|
|
13797
13813
|
const pluginName = this._getPluginName(plugin);
|
|
13798
|
-
this.
|
|
13814
|
+
this.pluginRegistry[pluginName] = plugin;
|
|
13799
13815
|
});
|
|
13800
13816
|
await Promise.all(setupProms);
|
|
13801
13817
|
const startProms = plugins.map(async (plugin) => {
|