s3db.js 10.0.6 → 10.0.7

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-cli.js CHANGED
File without changes
package/dist/s3db.cjs.js CHANGED
@@ -3869,6 +3869,10 @@ class CachePlugin extends Plugin {
3869
3869
  }
3870
3870
  }
3871
3871
  shouldCacheResource(resourceName) {
3872
+ const resourceMetadata = this.database.savedMetadata?.resources?.[resourceName];
3873
+ if (resourceMetadata?.createdBy && resourceMetadata.createdBy !== "user" && !this.config.include) {
3874
+ return false;
3875
+ }
3872
3876
  if (resourceName.startsWith("plg_") && !this.config.include) {
3873
3877
  return false;
3874
3878
  }
@@ -4418,8 +4422,9 @@ class EventualConsistencyPlugin extends Plugin {
4418
4422
  behavior: "body-overflow",
4419
4423
  timestamps: true,
4420
4424
  partitions: partitionConfig,
4421
- asyncPartitions: true
4425
+ asyncPartitions: true,
4422
4426
  // Use async partitions for better performance
4427
+ createdBy: "EventualConsistencyPlugin"
4423
4428
  })
4424
4429
  );
4425
4430
  if (!ok && !this.database.resources[transactionResourceName]) {
@@ -4436,7 +4441,8 @@ class EventualConsistencyPlugin extends Plugin {
4436
4441
  workerId: "string|optional"
4437
4442
  },
4438
4443
  behavior: "body-only",
4439
- timestamps: false
4444
+ timestamps: false,
4445
+ createdBy: "EventualConsistencyPlugin"
4440
4446
  })
4441
4447
  );
4442
4448
  if (!lockOk && !this.database.resources[lockResourceName]) {
@@ -4548,7 +4554,8 @@ class EventualConsistencyPlugin extends Plugin {
4548
4554
  byCohort: {
4549
4555
  fields: { cohort: "string" }
4550
4556
  }
4551
- }
4557
+ },
4558
+ createdBy: "EventualConsistencyPlugin"
4552
4559
  })
4553
4560
  );
4554
4561
  if (!ok && !this.database.resources[analyticsResourceName]) {
@@ -4973,6 +4980,23 @@ class EventualConsistencyPlugin extends Plugin {
4973
4980
  if (this.config.enableAnalytics && transactionsToUpdate.length > 0) {
4974
4981
  await this.updateAnalytics(transactionsToUpdate);
4975
4982
  }
4983
+ if (this.targetResource.cache && typeof this.targetResource.cache.delete === "function") {
4984
+ try {
4985
+ const cacheKey = await this.targetResource.cacheKeyFor({ id: originalId });
4986
+ await this.targetResource.cache.delete(cacheKey);
4987
+ if (this.config.verbose) {
4988
+ console.log(
4989
+ `[EventualConsistency] ${this.config.resource}.${this.config.field} - Cache invalidated for ${originalId}`
4990
+ );
4991
+ }
4992
+ } catch (cacheErr) {
4993
+ if (this.config.verbose) {
4994
+ console.warn(
4995
+ `[EventualConsistency] ${this.config.resource}.${this.config.field} - Failed to invalidate cache for ${originalId}: ${cacheErr?.message}`
4996
+ );
4997
+ }
4998
+ }
4999
+ }
4976
5000
  }
4977
5001
  return consolidatedValue;
4978
5002
  } finally {
@@ -9360,7 +9384,8 @@ ${errorDetails}`,
9360
9384
  versioningEnabled = false,
9361
9385
  events = {},
9362
9386
  asyncEvents = true,
9363
- asyncPartitions = true
9387
+ asyncPartitions = true,
9388
+ createdBy = "user"
9364
9389
  } = config;
9365
9390
  this.name = name;
9366
9391
  this.client = client;
@@ -9389,7 +9414,8 @@ ${errorDetails}`,
9389
9414
  autoDecrypt,
9390
9415
  allNestedObjectsOptional,
9391
9416
  asyncEvents,
9392
- asyncPartitions
9417
+ asyncPartitions,
9418
+ createdBy
9393
9419
  };
9394
9420
  this.hooks = {
9395
9421
  beforeInsert: [],
@@ -11753,7 +11779,7 @@ class Database extends EventEmitter {
11753
11779
  this.id = idGenerator(7);
11754
11780
  this.version = "1";
11755
11781
  this.s3dbVersion = (() => {
11756
- const [ok, err, version] = tryFn(() => true ? "10.0.6" : "latest");
11782
+ const [ok, err, version] = tryFn(() => true ? "10.0.7" : "latest");
11757
11783
  return ok ? version : "latest";
11758
11784
  })();
11759
11785
  this.resources = {};
@@ -12114,6 +12140,7 @@ class Database extends EventEmitter {
12114
12140
  metadata.resources[name] = {
12115
12141
  currentVersion: version,
12116
12142
  partitions: resource.config.partitions || {},
12143
+ createdBy: existingResource?.createdBy || resource.config.createdBy || "user",
12117
12144
  versions: {
12118
12145
  ...existingResource?.versions,
12119
12146
  // Preserve previous versions
@@ -12472,6 +12499,7 @@ class Database extends EventEmitter {
12472
12499
  * @param {boolean} [config.autoDecrypt=true] - Auto-decrypt secret fields
12473
12500
  * @param {Function|number} [config.idGenerator] - Custom ID generator or size
12474
12501
  * @param {number} [config.idSize=22] - Size for auto-generated IDs
12502
+ * @param {string} [config.createdBy='user'] - Who created this resource ('user', 'plugin', or plugin name)
12475
12503
  * @returns {Promise<Resource>} The created or updated resource
12476
12504
  */
12477
12505
  async createResource({ name, attributes, behavior = "user-managed", hooks, ...config }) {
@@ -12530,7 +12558,8 @@ class Database extends EventEmitter {
12530
12558
  idGenerator: config.idGenerator,
12531
12559
  idSize: config.idSize,
12532
12560
  asyncEvents: config.asyncEvents,
12533
- events: config.events || {}
12561
+ events: config.events || {},
12562
+ createdBy: config.createdBy || "user"
12534
12563
  });
12535
12564
  resource.database = this;
12536
12565
  this.resources[name] = resource;