s3db.js 10.0.15 → 10.0.16
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 +11 -36
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +11 -36
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/eventual-consistency.plugin.js +21 -50
package/dist/s3db.es.js
CHANGED
|
@@ -5252,45 +5252,20 @@ class EventualConsistencyPlugin extends Plugin {
|
|
|
5252
5252
|
`[EventualConsistency] ${this.config.resource}.${this.config.field} - ${originalId}: ${currentValue} \u2192 ${consolidatedValue} (${consolidatedValue > currentValue ? "+" : ""}${consolidatedValue - currentValue})`
|
|
5253
5253
|
);
|
|
5254
5254
|
}
|
|
5255
|
-
const [updateOk, updateErr] = await tryFn(
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
if (
|
|
5262
|
-
return ok2;
|
|
5263
|
-
}
|
|
5264
|
-
if (err2?.message?.includes("does not exist")) {
|
|
5255
|
+
const [updateOk, updateErr] = await tryFn(
|
|
5256
|
+
() => this.targetResource.update(originalId, {
|
|
5257
|
+
[this.config.field]: consolidatedValue
|
|
5258
|
+
})
|
|
5259
|
+
);
|
|
5260
|
+
if (!updateOk) {
|
|
5261
|
+
if (updateErr?.message?.includes("does not exist")) {
|
|
5265
5262
|
if (this.config.verbose) {
|
|
5266
|
-
console.
|
|
5267
|
-
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} doesn't exist
|
|
5263
|
+
console.warn(
|
|
5264
|
+
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} doesn't exist. Skipping consolidation. ${transactions.length} transactions will remain pending until record is created.`
|
|
5268
5265
|
);
|
|
5269
5266
|
}
|
|
5270
|
-
|
|
5271
|
-
() => this.targetResource.insert({
|
|
5272
|
-
id: originalId,
|
|
5273
|
-
[this.config.field]: consolidatedValue
|
|
5274
|
-
})
|
|
5275
|
-
);
|
|
5276
|
-
if (insertOk) {
|
|
5277
|
-
return insertOk;
|
|
5278
|
-
}
|
|
5279
|
-
if (insertErr?.message?.includes("already exists")) {
|
|
5280
|
-
if (this.config.verbose) {
|
|
5281
|
-
console.log(
|
|
5282
|
-
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} was created by another consolidation during retry, updating instead`
|
|
5283
|
-
);
|
|
5284
|
-
}
|
|
5285
|
-
return await this.targetResource.update(originalId, {
|
|
5286
|
-
[this.config.field]: consolidatedValue
|
|
5287
|
-
});
|
|
5288
|
-
}
|
|
5289
|
-
throw insertErr;
|
|
5267
|
+
return consolidatedValue;
|
|
5290
5268
|
}
|
|
5291
|
-
throw err2;
|
|
5292
|
-
});
|
|
5293
|
-
if (!updateOk) {
|
|
5294
5269
|
console.error(
|
|
5295
5270
|
`[EventualConsistency] ${this.config.resource}.${this.config.field} - FAILED to update ${originalId}: ${updateErr?.message || updateErr}`,
|
|
5296
5271
|
{ error: updateErr, consolidatedValue, currentValue }
|
|
@@ -12156,7 +12131,7 @@ class Database extends EventEmitter {
|
|
|
12156
12131
|
this.id = idGenerator(7);
|
|
12157
12132
|
this.version = "1";
|
|
12158
12133
|
this.s3dbVersion = (() => {
|
|
12159
|
-
const [ok, err, version] = tryFn(() => true ? "10.0.
|
|
12134
|
+
const [ok, err, version] = tryFn(() => true ? "10.0.16" : "latest");
|
|
12160
12135
|
return ok ? version : "latest";
|
|
12161
12136
|
})();
|
|
12162
12137
|
this.resources = {};
|