s3db.js 11.0.0 → 11.0.2

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.cjs.js CHANGED
@@ -5403,11 +5403,55 @@ async function consolidateRecord(originalId, transactionResource, targetResource
5403
5403
  `[EventualConsistency] ${config.resource}.${config.field} - ${originalId}: ${currentValue} \u2192 ${consolidatedValue} (${consolidatedValue > currentValue ? "+" : ""}${consolidatedValue - currentValue})`
5404
5404
  );
5405
5405
  }
5406
- const [updateOk, updateErr] = await tryFn(
5406
+ if (config.verbose) {
5407
+ console.log(
5408
+ `\u{1F525} [DEBUG] BEFORE targetResource.update() {
5409
+ originalId: '${originalId}',
5410
+ field: '${config.field}',
5411
+ consolidatedValue: ${consolidatedValue},
5412
+ currentValue: ${currentValue}
5413
+ }`
5414
+ );
5415
+ }
5416
+ const [updateOk, updateErr, updateResult] = await tryFn(
5407
5417
  () => targetResource.update(originalId, {
5408
5418
  [config.field]: consolidatedValue
5409
5419
  })
5410
5420
  );
5421
+ if (config.verbose) {
5422
+ console.log(
5423
+ `\u{1F525} [DEBUG] AFTER targetResource.update() {
5424
+ updateOk: ${updateOk},
5425
+ updateErr: ${updateErr?.message || "undefined"},
5426
+ updateResult: ${JSON.stringify(updateResult, null, 2)},
5427
+ hasField: ${updateResult?.[config.field]}
5428
+ }`
5429
+ );
5430
+ }
5431
+ if (updateOk && config.verbose) {
5432
+ const [verifyOk, verifyErr, verifiedRecord] = await tryFn(
5433
+ () => targetResource.get(originalId, { skipCache: true })
5434
+ );
5435
+ console.log(
5436
+ `\u{1F525} [DEBUG] VERIFICATION (fresh from S3, no cache) {
5437
+ verifyOk: ${verifyOk},
5438
+ verifiedRecord[${config.field}]: ${verifiedRecord?.[config.field]},
5439
+ expectedValue: ${consolidatedValue},
5440
+ \u2705 MATCH: ${verifiedRecord?.[config.field] === consolidatedValue}
5441
+ }`
5442
+ );
5443
+ if (verifyOk && verifiedRecord?.[config.field] !== consolidatedValue) {
5444
+ console.error(
5445
+ `\u274C [CRITICAL BUG] Update reported success but value not persisted!
5446
+ Resource: ${config.resource}
5447
+ Field: ${config.field}
5448
+ Record ID: ${originalId}
5449
+ Expected: ${consolidatedValue}
5450
+ Actually got: ${verifiedRecord?.[config.field]}
5451
+ This indicates a bug in s3db.js resource.update()`
5452
+ );
5453
+ }
5454
+ }
5411
5455
  if (!updateOk) {
5412
5456
  if (updateErr?.message?.includes("does not exist")) {
5413
5457
  if (config.verbose) {
@@ -5714,6 +5758,15 @@ async function runGarbageCollection(transactionResource, lockResource, config, e
5714
5758
 
5715
5759
  async function updateAnalytics(transactions, analyticsResource, config) {
5716
5760
  if (!analyticsResource || transactions.length === 0) return;
5761
+ if (!config.field) {
5762
+ throw new Error(
5763
+ `[EventualConsistency] CRITICAL BUG: config.field is undefined in updateAnalytics()!
5764
+ This indicates a race condition in the plugin where multiple handlers are sharing the same config object.
5765
+ Config: ${JSON.stringify({ resource: config.resource, field: config.field })}
5766
+ Transactions count: ${transactions.length}
5767
+ AnalyticsResource: ${analyticsResource?.name || "unknown"}`
5768
+ );
5769
+ }
5717
5770
  if (config.verbose) {
5718
5771
  console.log(
5719
5772
  `[EventualConsistency] ${config.resource}.${config.field} - Updating analytics for ${transactions.length} transactions...`
@@ -12733,7 +12786,7 @@ class Database extends EventEmitter {
12733
12786
  this.id = idGenerator(7);
12734
12787
  this.version = "1";
12735
12788
  this.s3dbVersion = (() => {
12736
- const [ok, err, version] = tryFn(() => true ? "11.0.0" : "latest");
12789
+ const [ok, err, version] = tryFn(() => true ? "11.0.2" : "latest");
12737
12790
  return ok ? version : "latest";
12738
12791
  })();
12739
12792
  this.resources = {};