s3db.js 10.0.6 → 10.0.8

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
@@ -3865,6 +3865,10 @@ class CachePlugin extends Plugin {
3865
3865
  }
3866
3866
  }
3867
3867
  shouldCacheResource(resourceName) {
3868
+ const resourceMetadata = this.database.savedMetadata?.resources?.[resourceName];
3869
+ if (resourceMetadata?.createdBy && resourceMetadata.createdBy !== "user" && !this.config.include) {
3870
+ return false;
3871
+ }
3868
3872
  if (resourceName.startsWith("plg_") && !this.config.include) {
3869
3873
  return false;
3870
3874
  }
@@ -4414,8 +4418,9 @@ class EventualConsistencyPlugin extends Plugin {
4414
4418
  behavior: "body-overflow",
4415
4419
  timestamps: true,
4416
4420
  partitions: partitionConfig,
4417
- asyncPartitions: true
4421
+ asyncPartitions: true,
4418
4422
  // Use async partitions for better performance
4423
+ createdBy: "EventualConsistencyPlugin"
4419
4424
  })
4420
4425
  );
4421
4426
  if (!ok && !this.database.resources[transactionResourceName]) {
@@ -4432,7 +4437,8 @@ class EventualConsistencyPlugin extends Plugin {
4432
4437
  workerId: "string|optional"
4433
4438
  },
4434
4439
  behavior: "body-only",
4435
- timestamps: false
4440
+ timestamps: false,
4441
+ createdBy: "EventualConsistencyPlugin"
4436
4442
  })
4437
4443
  );
4438
4444
  if (!lockOk && !this.database.resources[lockResourceName]) {
@@ -4544,7 +4550,8 @@ class EventualConsistencyPlugin extends Plugin {
4544
4550
  byCohort: {
4545
4551
  fields: { cohort: "string" }
4546
4552
  }
4547
- }
4553
+ },
4554
+ createdBy: "EventualConsistencyPlugin"
4548
4555
  })
4549
4556
  );
4550
4557
  if (!ok && !this.database.resources[analyticsResourceName]) {
@@ -4969,6 +4976,23 @@ class EventualConsistencyPlugin extends Plugin {
4969
4976
  if (this.config.enableAnalytics && transactionsToUpdate.length > 0) {
4970
4977
  await this.updateAnalytics(transactionsToUpdate);
4971
4978
  }
4979
+ if (this.targetResource.cache && typeof this.targetResource.cache.delete === "function") {
4980
+ try {
4981
+ const cacheKey = await this.targetResource.cacheKeyFor({ id: originalId });
4982
+ await this.targetResource.cache.delete(cacheKey);
4983
+ if (this.config.verbose) {
4984
+ console.log(
4985
+ `[EventualConsistency] ${this.config.resource}.${this.config.field} - Cache invalidated for ${originalId}`
4986
+ );
4987
+ }
4988
+ } catch (cacheErr) {
4989
+ if (this.config.verbose) {
4990
+ console.warn(
4991
+ `[EventualConsistency] ${this.config.resource}.${this.config.field} - Failed to invalidate cache for ${originalId}: ${cacheErr?.message}`
4992
+ );
4993
+ }
4994
+ }
4995
+ }
4972
4996
  }
4973
4997
  return consolidatedValue;
4974
4998
  } finally {
@@ -9356,7 +9380,8 @@ ${errorDetails}`,
9356
9380
  versioningEnabled = false,
9357
9381
  events = {},
9358
9382
  asyncEvents = true,
9359
- asyncPartitions = true
9383
+ asyncPartitions = true,
9384
+ createdBy = "user"
9360
9385
  } = config;
9361
9386
  this.name = name;
9362
9387
  this.client = client;
@@ -9385,7 +9410,8 @@ ${errorDetails}`,
9385
9410
  autoDecrypt,
9386
9411
  allNestedObjectsOptional,
9387
9412
  asyncEvents,
9388
- asyncPartitions
9413
+ asyncPartitions,
9414
+ createdBy
9389
9415
  };
9390
9416
  this.hooks = {
9391
9417
  beforeInsert: [],
@@ -11749,7 +11775,7 @@ class Database extends EventEmitter {
11749
11775
  this.id = idGenerator(7);
11750
11776
  this.version = "1";
11751
11777
  this.s3dbVersion = (() => {
11752
- const [ok, err, version] = tryFn(() => true ? "10.0.6" : "latest");
11778
+ const [ok, err, version] = tryFn(() => true ? "10.0.8" : "latest");
11753
11779
  return ok ? version : "latest";
11754
11780
  })();
11755
11781
  this.resources = {};
@@ -12110,6 +12136,7 @@ class Database extends EventEmitter {
12110
12136
  metadata.resources[name] = {
12111
12137
  currentVersion: version,
12112
12138
  partitions: resource.config.partitions || {},
12139
+ createdBy: existingResource?.createdBy || resource.config.createdBy || "user",
12113
12140
  versions: {
12114
12141
  ...existingResource?.versions,
12115
12142
  // Preserve previous versions
@@ -12468,6 +12495,7 @@ class Database extends EventEmitter {
12468
12495
  * @param {boolean} [config.autoDecrypt=true] - Auto-decrypt secret fields
12469
12496
  * @param {Function|number} [config.idGenerator] - Custom ID generator or size
12470
12497
  * @param {number} [config.idSize=22] - Size for auto-generated IDs
12498
+ * @param {string} [config.createdBy='user'] - Who created this resource ('user', 'plugin', or plugin name)
12471
12499
  * @returns {Promise<Resource>} The created or updated resource
12472
12500
  */
12473
12501
  async createResource({ name, attributes, behavior = "user-managed", hooks, ...config }) {
@@ -12526,7 +12554,8 @@ class Database extends EventEmitter {
12526
12554
  idGenerator: config.idGenerator,
12527
12555
  idSize: config.idSize,
12528
12556
  asyncEvents: config.asyncEvents,
12529
- events: config.events || {}
12557
+ events: config.events || {},
12558
+ createdBy: config.createdBy || "user"
12530
12559
  });
12531
12560
  resource.database = this;
12532
12561
  this.resources[name] = resource;