@jcbuisson/express-x-client 3.1.19 → 3.1.20

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.mts +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "3.1.19",
3
+ "version": "3.1.20",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/client.mts",
package/src/client.mts CHANGED
@@ -558,6 +558,8 @@ export function offlinePlugin(app) {
558
558
  // get() call: idbValues.get(undefined) itself throws before fullValue is
559
559
  // assigned, so checking fullValue == null afterwards is too late.
560
560
  if (elt.uid == null) continue
561
+ let currentMetadata = await idbMetadata.get(elt.uid)
562
+ if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
561
563
  const fullValue = await idbValues.get(elt.uid)
562
564
  if (fullValue == null) continue // record deleted concurrently
563
565
  delete fullValue.uid
@@ -565,10 +567,14 @@ export function offlinePlugin(app) {
565
567
  try {
566
568
  const result = await app.service(modelName).createWithMeta(elt.uid, fullValue, elt.created_at)
567
569
  const serverMeta = Array.isArray(result) ? result[1] : null
570
+ currentMetadata = await idbMetadata.get(elt.uid)
571
+ if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
568
572
  if (serverMeta?.uid) await idbMetadata.put({ ...serverMeta, __dirty__: false })
569
573
  else await idbMetadata.update(elt.uid, { __dirty__: false })
570
574
  } catch(err) {
571
575
  console.log("*** err sync user addDatabase", err, elt.uid, fullValue, elt.created_at)
576
+ currentMetadata = await idbMetadata.get(elt.uid)
577
+ if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
572
578
  // rollback
573
579
  await idbValues.delete(elt.uid)
574
580
  await idbMetadata.delete(elt.uid)
@@ -578,6 +584,8 @@ export function offlinePlugin(app) {
578
584
  // 5- update elements of `updateDatabase` with full data from cache
579
585
  for (const elt of updateDatabase) {
580
586
  if (elt.uid == null) continue
587
+ let currentMetadata = await idbMetadata.get(elt.uid)
588
+ if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
581
589
  const fullValue = await idbValues.get(elt.uid)
582
590
  if (fullValue == null) continue // record deleted concurrently
583
591
  delete fullValue.uid
@@ -585,6 +593,8 @@ export function offlinePlugin(app) {
585
593
  try {
586
594
  const result = await app.service(modelName).updateWithMeta(elt.uid, fullValue, elt.updated_at)
587
595
  const serverMeta = Array.isArray(result) ? result[1] : null
596
+ currentMetadata = await idbMetadata.get(elt.uid)
597
+ if (!metadataUnchangedSinceRequest(currentMetadata, elt)) continue
588
598
  if (serverMeta?.uid) await idbMetadata.put({ ...serverMeta, __dirty__: false })
589
599
  else await idbMetadata.update(elt.uid, { __dirty__: false })
590
600
  } catch(err) {