s3db.js 8.1.1 → 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 +49 -24
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +49 -24
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +49 -24
- package/dist/s3db.iife.min.js +1 -1
- package/mcp/server.js +2 -1
- package/package.json +6 -2
- package/src/database.class.js +17 -4
- 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 = {};
|
|
@@ -13502,6 +13517,7 @@ ${errorDetails}`,
|
|
|
13502
13517
|
this.verbose = options.verbose || false;
|
|
13503
13518
|
this.parallelism = parseInt(options.parallelism + "") || 10;
|
|
13504
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";
|
|
@@ -13794,6 +13810,8 @@ ${errorDetails}`,
|
|
|
13794
13810
|
if (plugin.beforeSetup) await plugin.beforeSetup();
|
|
13795
13811
|
await plugin.setup(db);
|
|
13796
13812
|
if (plugin.afterSetup) await plugin.afterSetup();
|
|
13813
|
+
const pluginName = this._getPluginName(plugin);
|
|
13814
|
+
this.pluginRegistry[pluginName] = plugin;
|
|
13797
13815
|
});
|
|
13798
13816
|
await Promise.all(setupProms);
|
|
13799
13817
|
const startProms = plugins.map(async (plugin) => {
|
|
@@ -13809,8 +13827,15 @@ ${errorDetails}`,
|
|
|
13809
13827
|
* @param {Plugin} plugin - Plugin instance to register
|
|
13810
13828
|
* @param {string} [name] - Optional name for the plugin (defaults to plugin.constructor.name)
|
|
13811
13829
|
*/
|
|
13830
|
+
/**
|
|
13831
|
+
* Get the normalized plugin name
|
|
13832
|
+
* @private
|
|
13833
|
+
*/
|
|
13834
|
+
_getPluginName(plugin, customName = null) {
|
|
13835
|
+
return customName || plugin.constructor.name.replace("Plugin", "").toLowerCase();
|
|
13836
|
+
}
|
|
13812
13837
|
async usePlugin(plugin, name = null) {
|
|
13813
|
-
const pluginName =
|
|
13838
|
+
const pluginName = this._getPluginName(plugin, name);
|
|
13814
13839
|
this.plugins[pluginName] = plugin;
|
|
13815
13840
|
if (this.isConnected()) {
|
|
13816
13841
|
await plugin.setup(this);
|