@jcbuisson/express-x-client 3.1.18 → 3.1.19

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 +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "3.1.18",
3
+ "version": "3.1.19",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/client.mts",
package/src/client.mts CHANGED
@@ -534,6 +534,8 @@ export function offlinePlugin(app) {
534
534
  if (deleteClient.length > 0) {
535
535
  await idbValues.db.transaction('rw', [idbValues, idbMetadata], async () => {
536
536
  for (const [uid] of deleteClient) {
537
+ const currentMetadata = await idbMetadata.get(uid)
538
+ if (!metadataUnchangedSinceRequest(currentMetadata, clientMetadataDict[uid])) continue
537
539
  await idbValues.delete(uid)
538
540
  await idbMetadata.delete(uid)
539
541
  }
@@ -541,6 +543,8 @@ export function offlinePlugin(app) {
541
543
  }
542
544
  // 3- update elements of cache with server's newer version
543
545
  for (const [elt, serverMeta] of updateClient) {
546
+ const currentMetadata = await idbMetadata.get(elt.uid)
547
+ if (!metadataUnchangedSinceRequest(currentMetadata, clientMetadataDict[elt.uid])) continue
544
548
  const value = { ...elt }
545
549
  delete value.__deleted__
546
550
  await idbValues.put(value)
@@ -596,6 +600,14 @@ export function offlinePlugin(app) {
596
600
  }
597
601
  }
598
602
 
603
+ function metadataUnchangedSinceRequest(currentMetadata, requestMetadata) {
604
+ return currentMetadata
605
+ && requestMetadata
606
+ && sameTimestamp(currentMetadata.created_at, requestMetadata.created_at)
607
+ && sameTimestamp(currentMetadata.updated_at, requestMetadata.updated_at)
608
+ && sameTimestamp(currentMetadata.deleted_at, requestMetadata.deleted_at)
609
+ }
610
+
599
611
  // Singleton map to reuse Dexie instances per database name
600
612
  const dbInstances = new Map();
601
613