@jcbuisson/express-x-client 3.1.17 → 3.1.18
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/package.json +1 -1
- package/src/client.mts +10 -1
package/package.json
CHANGED
package/src/client.mts
CHANGED
|
@@ -251,6 +251,8 @@ export function offlinePlugin(app) {
|
|
|
251
251
|
.then(result => applyCreateAcknowledgement(uid, now, result))
|
|
252
252
|
.catch(async err => {
|
|
253
253
|
console.log(`*** err sync ${modelName} create`, err)
|
|
254
|
+
const currentMetadata = await db.metadata.get(uid)
|
|
255
|
+
if (!isCreateRequestStillCurrent(currentMetadata, now)) return
|
|
254
256
|
// rollback
|
|
255
257
|
await db.values.delete(uid)
|
|
256
258
|
await db.metadata.delete(uid)
|
|
@@ -261,7 +263,7 @@ export function offlinePlugin(app) {
|
|
|
261
263
|
|
|
262
264
|
async function applyCreateAcknowledgement(uid, requestCreatedAt, result) {
|
|
263
265
|
const currentMetadata = await db.metadata.get(uid)
|
|
264
|
-
if (!
|
|
266
|
+
if (!isCreateRequestStillCurrent(currentMetadata, requestCreatedAt)) return
|
|
265
267
|
const [value, meta] = Array.isArray(result) ? result : []
|
|
266
268
|
if (value?.uid) await db.values.put(value)
|
|
267
269
|
if (meta?.uid)
|
|
@@ -270,6 +272,13 @@ export function offlinePlugin(app) {
|
|
|
270
272
|
await db.metadata.update(uid, { __dirty__: false })
|
|
271
273
|
}
|
|
272
274
|
|
|
275
|
+
function isCreateRequestStillCurrent(currentMetadata, requestCreatedAt) {
|
|
276
|
+
return currentMetadata
|
|
277
|
+
&& sameTimestamp(currentMetadata.created_at, requestCreatedAt)
|
|
278
|
+
&& !currentMetadata.updated_at
|
|
279
|
+
&& !currentMetadata.deleted_at
|
|
280
|
+
}
|
|
281
|
+
|
|
273
282
|
async function applyUpdateAcknowledgement(uid, requestUpdatedAt, result) {
|
|
274
283
|
const currentMetadata = await db.metadata.get(uid)
|
|
275
284
|
if (!currentMetadata || !sameTimestamp(currentMetadata.updated_at, requestUpdatedAt)) return
|