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