@tanstack/db-sqlite-persistence-core 0.2.11 → 0.2.13

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/src/persisted.ts CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  compileSingleRowExpression,
3
3
  safeRandomUUID,
4
4
  toBooleanPredicate,
5
+ withCollectionConfigFactory,
5
6
  } from '@tanstack/db'
6
7
  import {
7
8
  InvalidPersistedCollectionConfigError,
@@ -1244,6 +1245,9 @@ class PersistedCollectionRuntime<
1244
1245
  this.syncControls.begin?.({ immediate: true })
1245
1246
 
1246
1247
  for (const row of rows) {
1248
+ if (this.collection?._hasHydratedKey(row.key)) {
1249
+ continue
1250
+ }
1247
1251
  this.syncControls.write?.({
1248
1252
  type: `update`,
1249
1253
  value: row.value,
@@ -2641,12 +2645,21 @@ export function persistedCollectionOptions<
2641
2645
  collectionId,
2642
2646
  )
2643
2647
 
2644
- return {
2648
+ const result = {
2645
2649
  ...syncOptions,
2646
2650
  id: collectionId,
2647
2651
  sync: createWrappedSyncConfig<T, TKey>(syncOptions.sync, runtime),
2648
2652
  persistence,
2649
2653
  }
2654
+
2655
+ return withCollectionConfigFactory(
2656
+ result,
2657
+ () =>
2658
+ persistedCollectionOptions({
2659
+ ...options,
2660
+ id: collectionId,
2661
+ }) as typeof result,
2662
+ )
2650
2663
  }
2651
2664
 
2652
2665
  const { schemaVersion, ...localOnlyOptions } = options
@@ -2734,7 +2747,7 @@ export function persistedCollectionOptions<
2734
2747
  ...persistedUtils,
2735
2748
  }
2736
2749
 
2737
- return {
2750
+ const result = {
2738
2751
  ...localOnlyOptions,
2739
2752
  id: collectionId,
2740
2753
  persistence,
@@ -2746,6 +2759,15 @@ export function persistedCollectionOptions<
2746
2759
  startSync: true,
2747
2760
  gcTime: localOnlyOptions.gcTime ?? 0,
2748
2761
  }
2762
+
2763
+ return withCollectionConfigFactory(
2764
+ result,
2765
+ () =>
2766
+ persistedCollectionOptions({
2767
+ ...options,
2768
+ id: collectionId,
2769
+ }) as typeof result,
2770
+ )
2749
2771
  }
2750
2772
 
2751
2773
  export function encodePersistedStorageKey(key: string | number): string {