s3db.js 10.0.8 → 10.0.9
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 +32 -8
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +32 -8
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/eventual-consistency.plugin.js +40 -6
- package/src/resource.class.js +4 -2
package/dist/s3db.es.js
CHANGED
|
@@ -4954,11 +4954,35 @@ class EventualConsistencyPlugin extends Plugin {
|
|
|
4954
4954
|
`[EventualConsistency] ${this.config.resource}.${this.config.field} - ${originalId}: ${currentValue} \u2192 ${consolidatedValue} (${consolidatedValue > currentValue ? "+" : ""}${consolidatedValue - currentValue})`
|
|
4955
4955
|
);
|
|
4956
4956
|
}
|
|
4957
|
-
const [updateOk, updateErr] = await tryFn(
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4957
|
+
const [updateOk, updateErr] = await tryFn(async () => {
|
|
4958
|
+
const [ok2, err2] = await tryFn(
|
|
4959
|
+
() => this.targetResource.update(originalId, {
|
|
4960
|
+
[this.config.field]: consolidatedValue
|
|
4961
|
+
})
|
|
4962
|
+
);
|
|
4963
|
+
if (!ok2 && (err2?.code === "NoSuchKey" || err2?.code === "NotFound")) {
|
|
4964
|
+
if (this.config.verbose) {
|
|
4965
|
+
console.log(
|
|
4966
|
+
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} doesn't exist, creating with ${this.config.field}=${consolidatedValue}`
|
|
4967
|
+
);
|
|
4968
|
+
}
|
|
4969
|
+
return await this.targetResource.insert({
|
|
4970
|
+
id: originalId,
|
|
4971
|
+
[this.config.field]: consolidatedValue
|
|
4972
|
+
});
|
|
4973
|
+
}
|
|
4974
|
+
if (!ok2) {
|
|
4975
|
+
throw err2;
|
|
4976
|
+
}
|
|
4977
|
+
return ok2;
|
|
4978
|
+
});
|
|
4979
|
+
if (!updateOk) {
|
|
4980
|
+
console.error(
|
|
4981
|
+
`[EventualConsistency] ${this.config.resource}.${this.config.field} - FAILED to update ${originalId}: ${updateErr?.message || updateErr}`,
|
|
4982
|
+
{ error: updateErr, consolidatedValue, currentValue }
|
|
4983
|
+
);
|
|
4984
|
+
throw updateErr;
|
|
4985
|
+
}
|
|
4962
4986
|
if (updateOk) {
|
|
4963
4987
|
const transactionsToUpdate = transactions.filter((txn) => txn.id !== "__synthetic__");
|
|
4964
4988
|
const { results, errors } = await PromisePool.for(transactionsToUpdate).withConcurrency(10).process(async (txn) => {
|
|
@@ -9440,11 +9464,11 @@ ${errorDetails}`,
|
|
|
9440
9464
|
if (Array.isArray(listeners)) {
|
|
9441
9465
|
for (const listener of listeners) {
|
|
9442
9466
|
if (typeof listener === "function") {
|
|
9443
|
-
this.on(eventName, listener);
|
|
9467
|
+
this.on(eventName, listener.bind(this));
|
|
9444
9468
|
}
|
|
9445
9469
|
}
|
|
9446
9470
|
} else if (typeof listeners === "function") {
|
|
9447
|
-
this.on(eventName, listeners);
|
|
9471
|
+
this.on(eventName, listeners.bind(this));
|
|
9448
9472
|
}
|
|
9449
9473
|
}
|
|
9450
9474
|
}
|
|
@@ -11775,7 +11799,7 @@ class Database extends EventEmitter {
|
|
|
11775
11799
|
this.id = idGenerator(7);
|
|
11776
11800
|
this.version = "1";
|
|
11777
11801
|
this.s3dbVersion = (() => {
|
|
11778
|
-
const [ok, err, version] = tryFn(() => true ? "10.0.
|
|
11802
|
+
const [ok, err, version] = tryFn(() => true ? "10.0.9" : "latest");
|
|
11779
11803
|
return ok ? version : "latest";
|
|
11780
11804
|
})();
|
|
11781
11805
|
this.resources = {};
|