s3db.js 11.0.0 → 11.0.1

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
@@ -4864,7 +4864,9 @@ function createConfig(options, detectedTimezone) {
4864
4864
  deleteConsolidatedTransactions: checkpoints.deleteConsolidated !== false,
4865
4865
  autoCheckpoint: checkpoints.auto !== false,
4866
4866
  // Debug
4867
- verbose: options.verbose || false
4867
+ verbose: options.verbose !== false,
4868
+ // Default: true (can disable with verbose: false)
4869
+ debug: options.debug || false
4868
4870
  };
4869
4871
  }
4870
4872
  function validateResourcesConfig(resources) {
@@ -5403,11 +5405,55 @@ async function consolidateRecord(originalId, transactionResource, targetResource
5403
5405
  `[EventualConsistency] ${config.resource}.${config.field} - ${originalId}: ${currentValue} \u2192 ${consolidatedValue} (${consolidatedValue > currentValue ? "+" : ""}${consolidatedValue - currentValue})`
5404
5406
  );
5405
5407
  }
5406
- const [updateOk, updateErr] = await tryFn(
5408
+ if (config.debug || config.verbose) {
5409
+ console.log(
5410
+ `\u{1F525} [DEBUG] BEFORE targetResource.update() {
5411
+ originalId: '${originalId}',
5412
+ field: '${config.field}',
5413
+ consolidatedValue: ${consolidatedValue},
5414
+ currentValue: ${currentValue}
5415
+ }`
5416
+ );
5417
+ }
5418
+ const [updateOk, updateErr, updateResult] = await tryFn(
5407
5419
  () => targetResource.update(originalId, {
5408
5420
  [config.field]: consolidatedValue
5409
5421
  })
5410
5422
  );
5423
+ if (config.debug || config.verbose) {
5424
+ console.log(
5425
+ `\u{1F525} [DEBUG] AFTER targetResource.update() {
5426
+ updateOk: ${updateOk},
5427
+ updateErr: ${updateErr?.message || "undefined"},
5428
+ updateResult: ${JSON.stringify(updateResult, null, 2)},
5429
+ hasField: ${updateResult?.[config.field]}
5430
+ }`
5431
+ );
5432
+ }
5433
+ if (updateOk && (config.debug || config.verbose)) {
5434
+ const [verifyOk, verifyErr, verifiedRecord] = await tryFn(
5435
+ () => targetResource.get(originalId, { skipCache: true })
5436
+ );
5437
+ console.log(
5438
+ `\u{1F525} [DEBUG] VERIFICATION (fresh from S3, no cache) {
5439
+ verifyOk: ${verifyOk},
5440
+ verifiedRecord[${config.field}]: ${verifiedRecord?.[config.field]},
5441
+ expectedValue: ${consolidatedValue},
5442
+ \u2705 MATCH: ${verifiedRecord?.[config.field] === consolidatedValue}
5443
+ }`
5444
+ );
5445
+ if (verifyOk && verifiedRecord?.[config.field] !== consolidatedValue) {
5446
+ console.error(
5447
+ `\u274C [CRITICAL BUG] Update reported success but value not persisted!
5448
+ Resource: ${config.resource}
5449
+ Field: ${config.field}
5450
+ Record ID: ${originalId}
5451
+ Expected: ${consolidatedValue}
5452
+ Actually got: ${verifiedRecord?.[config.field]}
5453
+ This indicates a bug in s3db.js resource.update()`
5454
+ );
5455
+ }
5456
+ }
5411
5457
  if (!updateOk) {
5412
5458
  if (updateErr?.message?.includes("does not exist")) {
5413
5459
  if (config.verbose) {
@@ -5714,7 +5760,16 @@ async function runGarbageCollection(transactionResource, lockResource, config, e
5714
5760
 
5715
5761
  async function updateAnalytics(transactions, analyticsResource, config) {
5716
5762
  if (!analyticsResource || transactions.length === 0) return;
5717
- if (config.verbose) {
5763
+ if (!config.field) {
5764
+ throw new Error(
5765
+ `[EventualConsistency] CRITICAL BUG: config.field is undefined in updateAnalytics()!
5766
+ This indicates a race condition in the plugin where multiple handlers are sharing the same config object.
5767
+ Config: ${JSON.stringify({ resource: config.resource, field: config.field, verbose: config.verbose })}
5768
+ Transactions count: ${transactions.length}
5769
+ AnalyticsResource: ${analyticsResource?.name || "unknown"}`
5770
+ );
5771
+ }
5772
+ if (config.verbose || config.debug) {
5718
5773
  console.log(
5719
5774
  `[EventualConsistency] ${config.resource}.${config.field} - Updating analytics for ${transactions.length} transactions...`
5720
5775
  );
@@ -5722,7 +5777,7 @@ async function updateAnalytics(transactions, analyticsResource, config) {
5722
5777
  try {
5723
5778
  const byHour = groupByCohort(transactions, "cohortHour");
5724
5779
  const cohortCount = Object.keys(byHour).length;
5725
- if (config.verbose) {
5780
+ if (config.verbose || config.debug) {
5726
5781
  console.log(
5727
5782
  `[EventualConsistency] ${config.resource}.${config.field} - Updating ${cohortCount} hourly analytics cohorts...`
5728
5783
  );
@@ -5732,7 +5787,7 @@ async function updateAnalytics(transactions, analyticsResource, config) {
5732
5787
  }
5733
5788
  if (config.analyticsConfig.rollupStrategy === "incremental") {
5734
5789
  const uniqueHours = Object.keys(byHour);
5735
- if (config.verbose) {
5790
+ if (config.verbose || config.debug) {
5736
5791
  console.log(
5737
5792
  `[EventualConsistency] ${config.resource}.${config.field} - Rolling up ${uniqueHours.length} hours to daily/monthly analytics...`
5738
5793
  );
@@ -5741,7 +5796,7 @@ async function updateAnalytics(transactions, analyticsResource, config) {
5741
5796
  await rollupAnalytics(cohortHour, analyticsResource, config);
5742
5797
  }
5743
5798
  }
5744
- if (config.verbose) {
5799
+ if (config.verbose || config.debug) {
5745
5800
  console.log(
5746
5801
  `[EventualConsistency] ${config.resource}.${config.field} - Analytics update complete for ${cohortCount} cohorts`
5747
5802
  );
@@ -12733,7 +12788,7 @@ class Database extends EventEmitter {
12733
12788
  this.id = idGenerator(7);
12734
12789
  this.version = "1";
12735
12790
  this.s3dbVersion = (() => {
12736
- const [ok, err, version] = tryFn(() => true ? "11.0.0" : "latest");
12791
+ const [ok, err, version] = tryFn(() => true ? "11.0.1" : "latest");
12737
12792
  return ok ? version : "latest";
12738
12793
  })();
12739
12794
  this.resources = {};