@jcbuisson/express-x-client 3.1.20 → 3.1.26
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 +18 -1
package/package.json
CHANGED
package/src/client.mts
CHANGED
|
@@ -265,6 +265,11 @@ export function offlinePlugin(app) {
|
|
|
265
265
|
const currentMetadata = await db.metadata.get(uid)
|
|
266
266
|
if (!isCreateRequestStillCurrent(currentMetadata, requestCreatedAt)) return
|
|
267
267
|
const [value, meta] = Array.isArray(result) ? result : []
|
|
268
|
+
if (!value?.uid && meta?.deleted_at) {
|
|
269
|
+
await db.values.delete(uid)
|
|
270
|
+
await db.metadata.delete(uid)
|
|
271
|
+
return
|
|
272
|
+
}
|
|
268
273
|
if (value?.uid) await db.values.put(value)
|
|
269
274
|
if (meta?.uid)
|
|
270
275
|
await db.metadata.put({ ...meta, __dirty__: false })
|
|
@@ -293,7 +298,12 @@ export function offlinePlugin(app) {
|
|
|
293
298
|
async function applyDeleteAcknowledgement(uid, requestDeletedAt, result) {
|
|
294
299
|
const currentMetadata = await db.metadata.get(uid)
|
|
295
300
|
if (!currentMetadata || !sameTimestamp(currentMetadata.deleted_at, requestDeletedAt)) return
|
|
296
|
-
const [, meta] = Array.isArray(result) ? result : []
|
|
301
|
+
const [value, meta] = Array.isArray(result) ? result : []
|
|
302
|
+
if (value?.uid && !meta?.deleted_at) {
|
|
303
|
+
const restoredValue = { ...value }
|
|
304
|
+
delete restoredValue.__deleted__
|
|
305
|
+
await db.values.put(restoredValue)
|
|
306
|
+
}
|
|
297
307
|
if (meta?.uid)
|
|
298
308
|
await db.metadata.put({ ...meta, __dirty__: false })
|
|
299
309
|
else
|
|
@@ -525,6 +535,8 @@ export function offlinePlugin(app) {
|
|
|
525
535
|
// uid to Dexie between the idbValues.filter snapshot and this step,
|
|
526
536
|
// add() would throw ConstraintError and abort the entire transaction,
|
|
527
537
|
// silently dropping every other addClient record in the batch.
|
|
538
|
+
const currentMetadata = await idbMetadata.get(value.uid)
|
|
539
|
+
if (currentMetadata && compareMetadataTime(metaData, currentMetadata) <= 0) continue
|
|
528
540
|
await idbValues.put(value)
|
|
529
541
|
await idbMetadata.put({ ...metaData, __dirty__: false })
|
|
530
542
|
}
|
|
@@ -569,6 +581,11 @@ export function offlinePlugin(app) {
|
|
|
569
581
|
const serverMeta = Array.isArray(result) ? result[1] : null
|
|
570
582
|
currentMetadata = await idbMetadata.get(elt.uid)
|
|
571
583
|
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
584
|
+
if (Array.isArray(result) && !result[0]?.uid && serverMeta?.deleted_at) {
|
|
585
|
+
await idbValues.delete(elt.uid)
|
|
586
|
+
await idbMetadata.delete(elt.uid)
|
|
587
|
+
continue
|
|
588
|
+
}
|
|
572
589
|
if (serverMeta?.uid) await idbMetadata.put({ ...serverMeta, __dirty__: false })
|
|
573
590
|
else await idbMetadata.update(elt.uid, { __dirty__: false })
|
|
574
591
|
} catch(err) {
|