@jcbuisson/express-x-client 3.1.19 → 3.1.23
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
|
@@ -293,7 +293,12 @@ export function offlinePlugin(app) {
|
|
|
293
293
|
async function applyDeleteAcknowledgement(uid, requestDeletedAt, result) {
|
|
294
294
|
const currentMetadata = await db.metadata.get(uid)
|
|
295
295
|
if (!currentMetadata || !sameTimestamp(currentMetadata.deleted_at, requestDeletedAt)) return
|
|
296
|
-
const [, meta] = Array.isArray(result) ? result : []
|
|
296
|
+
const [value, meta] = Array.isArray(result) ? result : []
|
|
297
|
+
if (value?.uid && !meta?.deleted_at) {
|
|
298
|
+
const restoredValue = { ...value }
|
|
299
|
+
delete restoredValue.__deleted__
|
|
300
|
+
await db.values.put(restoredValue)
|
|
301
|
+
}
|
|
297
302
|
if (meta?.uid)
|
|
298
303
|
await db.metadata.put({ ...meta, __dirty__: false })
|
|
299
304
|
else
|
|
@@ -525,6 +530,8 @@ export function offlinePlugin(app) {
|
|
|
525
530
|
// uid to Dexie between the idbValues.filter snapshot and this step,
|
|
526
531
|
// add() would throw ConstraintError and abort the entire transaction,
|
|
527
532
|
// silently dropping every other addClient record in the batch.
|
|
533
|
+
const currentMetadata = await idbMetadata.get(value.uid)
|
|
534
|
+
if (currentMetadata && compareMetadataTime(metaData, currentMetadata) <= 0) continue
|
|
528
535
|
await idbValues.put(value)
|
|
529
536
|
await idbMetadata.put({ ...metaData, __dirty__: false })
|
|
530
537
|
}
|
|
@@ -558,6 +565,8 @@ export function offlinePlugin(app) {
|
|
|
558
565
|
// get() call: idbValues.get(undefined) itself throws before fullValue is
|
|
559
566
|
// assigned, so checking fullValue == null afterwards is too late.
|
|
560
567
|
if (elt.uid == null) continue
|
|
568
|
+
let currentMetadata = await idbMetadata.get(elt.uid)
|
|
569
|
+
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
561
570
|
const fullValue = await idbValues.get(elt.uid)
|
|
562
571
|
if (fullValue == null) continue // record deleted concurrently
|
|
563
572
|
delete fullValue.uid
|
|
@@ -565,10 +574,14 @@ export function offlinePlugin(app) {
|
|
|
565
574
|
try {
|
|
566
575
|
const result = await app.service(modelName).createWithMeta(elt.uid, fullValue, elt.created_at)
|
|
567
576
|
const serverMeta = Array.isArray(result) ? result[1] : null
|
|
577
|
+
currentMetadata = await idbMetadata.get(elt.uid)
|
|
578
|
+
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
568
579
|
if (serverMeta?.uid) await idbMetadata.put({ ...serverMeta, __dirty__: false })
|
|
569
580
|
else await idbMetadata.update(elt.uid, { __dirty__: false })
|
|
570
581
|
} catch(err) {
|
|
571
582
|
console.log("*** err sync user addDatabase", err, elt.uid, fullValue, elt.created_at)
|
|
583
|
+
currentMetadata = await idbMetadata.get(elt.uid)
|
|
584
|
+
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
572
585
|
// rollback
|
|
573
586
|
await idbValues.delete(elt.uid)
|
|
574
587
|
await idbMetadata.delete(elt.uid)
|
|
@@ -578,6 +591,8 @@ export function offlinePlugin(app) {
|
|
|
578
591
|
// 5- update elements of `updateDatabase` with full data from cache
|
|
579
592
|
for (const elt of updateDatabase) {
|
|
580
593
|
if (elt.uid == null) continue
|
|
594
|
+
let currentMetadata = await idbMetadata.get(elt.uid)
|
|
595
|
+
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
581
596
|
const fullValue = await idbValues.get(elt.uid)
|
|
582
597
|
if (fullValue == null) continue // record deleted concurrently
|
|
583
598
|
delete fullValue.uid
|
|
@@ -585,6 +600,8 @@ export function offlinePlugin(app) {
|
|
|
585
600
|
try {
|
|
586
601
|
const result = await app.service(modelName).updateWithMeta(elt.uid, fullValue, elt.updated_at)
|
|
587
602
|
const serverMeta = Array.isArray(result) ? result[1] : null
|
|
603
|
+
currentMetadata = await idbMetadata.get(elt.uid)
|
|
604
|
+
if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
|
|
588
605
|
if (serverMeta?.uid) await idbMetadata.put({ ...serverMeta, __dirty__: false })
|
|
589
606
|
else await idbMetadata.update(elt.uid, { __dirty__: false })
|
|
590
607
|
} catch(err) {
|