s3db.js 10.0.14 → 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 +19 -36
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +19 -36
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/cache.plugin.js +19 -7
- package/src/plugins/eventual-consistency.plugin.js +21 -50
- package/src/plugins/backup.plugin.js.backup +0 -1026
package/dist/s3db.cjs.js
CHANGED
|
@@ -3926,6 +3926,14 @@ class CachePlugin extends Plugin {
|
|
|
3926
3926
|
];
|
|
3927
3927
|
for (const method of cacheMethods) {
|
|
3928
3928
|
resource.useMiddleware(method, async (ctx, next) => {
|
|
3929
|
+
let skipCache = false;
|
|
3930
|
+
const lastArg = ctx.args[ctx.args.length - 1];
|
|
3931
|
+
if (lastArg && typeof lastArg === "object" && lastArg.skipCache === true) {
|
|
3932
|
+
skipCache = true;
|
|
3933
|
+
}
|
|
3934
|
+
if (skipCache) {
|
|
3935
|
+
return await next();
|
|
3936
|
+
}
|
|
3929
3937
|
let key;
|
|
3930
3938
|
if (method === "getMany") {
|
|
3931
3939
|
key = await resource.cacheKeyFor({ action: method, params: { ids: ctx.args[0] } });
|
|
@@ -5248,45 +5256,20 @@ class EventualConsistencyPlugin extends Plugin {
|
|
|
5248
5256
|
`[EventualConsistency] ${this.config.resource}.${this.config.field} - ${originalId}: ${currentValue} \u2192 ${consolidatedValue} (${consolidatedValue > currentValue ? "+" : ""}${consolidatedValue - currentValue})`
|
|
5249
5257
|
);
|
|
5250
5258
|
}
|
|
5251
|
-
const [updateOk, updateErr] = await tryFn(
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
if (
|
|
5258
|
-
return ok2;
|
|
5259
|
-
}
|
|
5260
|
-
if (err2?.message?.includes("does not exist")) {
|
|
5259
|
+
const [updateOk, updateErr] = await tryFn(
|
|
5260
|
+
() => this.targetResource.update(originalId, {
|
|
5261
|
+
[this.config.field]: consolidatedValue
|
|
5262
|
+
})
|
|
5263
|
+
);
|
|
5264
|
+
if (!updateOk) {
|
|
5265
|
+
if (updateErr?.message?.includes("does not exist")) {
|
|
5261
5266
|
if (this.config.verbose) {
|
|
5262
|
-
console.
|
|
5263
|
-
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} doesn't exist
|
|
5267
|
+
console.warn(
|
|
5268
|
+
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} doesn't exist. Skipping consolidation. ${transactions.length} transactions will remain pending until record is created.`
|
|
5264
5269
|
);
|
|
5265
5270
|
}
|
|
5266
|
-
|
|
5267
|
-
() => this.targetResource.insert({
|
|
5268
|
-
id: originalId,
|
|
5269
|
-
[this.config.field]: consolidatedValue
|
|
5270
|
-
})
|
|
5271
|
-
);
|
|
5272
|
-
if (insertOk) {
|
|
5273
|
-
return insertOk;
|
|
5274
|
-
}
|
|
5275
|
-
if (insertErr?.message?.includes("already exists")) {
|
|
5276
|
-
if (this.config.verbose) {
|
|
5277
|
-
console.log(
|
|
5278
|
-
`[EventualConsistency] ${this.config.resource}.${this.config.field} - Record ${originalId} was created by another consolidation during retry, updating instead`
|
|
5279
|
-
);
|
|
5280
|
-
}
|
|
5281
|
-
return await this.targetResource.update(originalId, {
|
|
5282
|
-
[this.config.field]: consolidatedValue
|
|
5283
|
-
});
|
|
5284
|
-
}
|
|
5285
|
-
throw insertErr;
|
|
5271
|
+
return consolidatedValue;
|
|
5286
5272
|
}
|
|
5287
|
-
throw err2;
|
|
5288
|
-
});
|
|
5289
|
-
if (!updateOk) {
|
|
5290
5273
|
console.error(
|
|
5291
5274
|
`[EventualConsistency] ${this.config.resource}.${this.config.field} - FAILED to update ${originalId}: ${updateErr?.message || updateErr}`,
|
|
5292
5275
|
{ error: updateErr, consolidatedValue, currentValue }
|
|
@@ -12152,7 +12135,7 @@ class Database extends EventEmitter {
|
|
|
12152
12135
|
this.id = idGenerator(7);
|
|
12153
12136
|
this.version = "1";
|
|
12154
12137
|
this.s3dbVersion = (() => {
|
|
12155
|
-
const [ok, err, version] = tryFn(() => true ? "10.0.
|
|
12138
|
+
const [ok, err, version] = tryFn(() => true ? "10.0.16" : "latest");
|
|
12156
12139
|
return ok ? version : "latest";
|
|
12157
12140
|
})();
|
|
12158
12141
|
this.resources = {};
|