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.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
- if (plugin.config.includeData) {
1357
- for (const id of ids) {
1358
- const [ok, err, fetched] = await try_fn_default(() => resource.get(id));
1359
- if (ok) {
1360
- objectsToDelete.push(fetched);
1361
- } else {
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
- let query = {};
1472
- if (resourceName) query.resourceName = resourceName;
1473
- if (operation) query.operation = operation;
1474
- if (recordId) query.recordId = recordId;
1475
- if (partition) query.partition = partition;
1476
- if (startDate || endDate) {
1477
- query.timestamp = {};
1478
- if (startDate) query.timestamp.$gte = startDate;
1479
- if (endDate) query.timestamp.$lte = endDate;
1480
- }
1481
- const result = await this.auditResource.page({ query, limit, offset });
1482
- return result.items || [];
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.1.3" : "latest");
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.plugins[pluginName] = plugin;
13814
+ this.pluginRegistry[pluginName] = plugin;
13799
13815
  });
13800
13816
  await Promise.all(setupProms);
13801
13817
  const startProms = plugins.map(async (plugin) => {