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/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
- if (plugin.config.includeData) {
1367
- for (const id of ids) {
1368
- const [ok, err, fetched] = await try_fn_default(() => resource.get(id));
1369
- if (ok) {
1370
- objectsToDelete.push(fetched);
1371
- } else {
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
- let query = {};
1482
- if (resourceName) query.resourceName = resourceName;
1483
- if (operation) query.operation = operation;
1484
- if (recordId) query.recordId = recordId;
1485
- if (partition) query.partition = partition;
1486
- if (startDate || endDate) {
1487
- query.timestamp = {};
1488
- if (startDate) query.timestamp.$gte = startDate;
1489
- if (endDate) query.timestamp.$lte = endDate;
1490
- }
1491
- const result = await this.auditResource.page({ query, limit, offset });
1492
- return result.items || [];
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.1.3" : "latest");
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.plugins[pluginName] = plugin;
13824
+ this.pluginRegistry[pluginName] = plugin;
13809
13825
  });
13810
13826
  await Promise.all(setupProms);
13811
13827
  const startProms = plugins.map(async (plugin) => {