react-native-nitro-storage 0.10.0 → 0.10.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-storage",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Synchronous React Native storage powered by Nitro Modules and JSI: typed Memory, Disk, Keychain/Android Keystore secure storage, biometric auth, MMKV migration, Expo, Zustand/Jotai persistence, and web IndexedDB support.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -124,7 +124,7 @@
124
124
  },
125
125
  "devDependencies": {
126
126
  "@expo/config-plugins": "^57.0.6",
127
- "@react-native/babel-preset": "^0.86.2",
127
+ "@react-native/babel-preset": "^0.86.3",
128
128
  "@testing-library/react-native": "^13.3.3",
129
129
  "@types/react": "~19.2.18"
130
130
  },
@@ -13,9 +13,8 @@ export type DurabilityCoordinator = {
13
13
  isDiskWritesAsync(): boolean;
14
14
  hasPendingDiskWrite(key: string): boolean;
15
15
  hasPendingSecureWrite(key: string): boolean;
16
- readPendingDiskWrite(key: string): string | undefined;
17
- readPendingSecureWrite(key: string): string | undefined;
18
- readPendingSecureAccessControl(key: string): AccessControl | undefined;
16
+ getPendingDiskWrite(key: string): PendingDiskWrite | undefined;
17
+ getPendingSecureWrite(key: string): PendingSecureWrite | undefined;
19
18
  clearPendingDiskWrite(key: string): void;
20
19
  clearPendingSecureWrite(key: string): void;
21
20
  clearPendingDiskWriteIf(write: PendingDiskWrite): void;
@@ -235,10 +234,8 @@ export function createDurabilityCoordinator(options: {
235
234
  isDiskWritesAsync: () => diskWritesAsync,
236
235
  hasPendingDiskWrite: (key) => pendingDiskWrites.has(key),
237
236
  hasPendingSecureWrite: (key) => pendingSecureWrites.has(key),
238
- readPendingDiskWrite: (key) => pendingDiskWrites.get(key)?.value,
239
- readPendingSecureWrite: (key) => pendingSecureWrites.get(key)?.value,
240
- readPendingSecureAccessControl: (key) =>
241
- pendingSecureWrites.get(key)?.accessControl,
237
+ getPendingDiskWrite: (key) => pendingDiskWrites.get(key),
238
+ getPendingSecureWrite: (key) => pendingSecureWrites.get(key),
242
239
  clearPendingDiskWrite: (key) => {
243
240
  pendingDiskWrites.delete(key);
244
241
  },
@@ -554,22 +554,6 @@ export function createStorageCore(
554
554
  metrics.record(operation, scope, durationMs, keysCount);
555
555
  }
556
556
 
557
- function readPendingSecureWrite(key: string): string | undefined {
558
- return durability.readPendingSecureWrite(key);
559
- }
560
-
561
- function readPendingDiskWrite(key: string): string | undefined {
562
- return durability.readPendingDiskWrite(key);
563
- }
564
-
565
- function hasPendingDiskWrite(key: string): boolean {
566
- return durability.hasPendingDiskWrite(key);
567
- }
568
-
569
- function hasPendingSecureWrite(key: string): boolean {
570
- return durability.hasPendingSecureWrite(key);
571
- }
572
-
573
557
  function clearPendingDiskWrite(key: string): void {
574
558
  durability.clearPendingDiskWrite(key);
575
559
  }
@@ -622,12 +606,18 @@ export function createStorageCore(
622
606
  return typeof value === "string" ? value : undefined;
623
607
  }
624
608
 
625
- if (scope === StorageScope.Disk && hasPendingDiskWrite(key)) {
626
- return readPendingDiskWrite(key);
609
+ if (scope === StorageScope.Disk) {
610
+ const pending = durability.getPendingDiskWrite(key);
611
+ if (pending !== undefined) {
612
+ return pending.value;
613
+ }
627
614
  }
628
615
 
629
- if (scope === StorageScope.Secure && hasPendingSecureWrite(key)) {
630
- return readPendingSecureWrite(key);
616
+ if (scope === StorageScope.Secure) {
617
+ const pending = durability.getPendingSecureWrite(key);
618
+ if (pending !== undefined) {
619
+ return pending.value;
620
+ }
631
621
  }
632
622
 
633
623
  return adapter.backend.get(key, scope);
@@ -653,18 +643,22 @@ export function createStorageCore(
653
643
  : undefined;
654
644
  }
655
645
 
656
- if (scope === StorageScope.Disk && hasPendingDiskWrite(key)) {
657
- const pending = readPendingDiskWrite(key);
658
- return pending === undefined
659
- ? undefined
660
- : unescapeCollidingRawValue(pending);
646
+ if (scope === StorageScope.Disk) {
647
+ const pending = durability.getPendingDiskWrite(key);
648
+ if (pending !== undefined) {
649
+ return pending.value === undefined
650
+ ? undefined
651
+ : unescapeCollidingRawValue(pending.value);
652
+ }
661
653
  }
662
654
 
663
- if (scope === StorageScope.Secure && hasPendingSecureWrite(key)) {
664
- const pending = readPendingSecureWrite(key);
665
- return pending === undefined
666
- ? undefined
667
- : unescapeCollidingRawValue(pending);
655
+ if (scope === StorageScope.Secure) {
656
+ const pending = durability.getPendingSecureWrite(key);
657
+ if (pending !== undefined) {
658
+ return pending.value === undefined
659
+ ? undefined
660
+ : unescapeCollidingRawValue(pending.value);
661
+ }
668
662
  }
669
663
 
670
664
  const raw = adapter.backend.get(key, scope);
@@ -1664,28 +1658,32 @@ export function createStorageCore(
1664
1658
  }
1665
1659
 
1666
1660
  if (nonMemoryScope === StorageScope.Disk) {
1667
- if (durability.hasPendingDiskWrite(storageKey)) {
1668
- return durability.readPendingDiskWrite(storageKey);
1661
+ const pending = durability.getPendingDiskWrite(storageKey);
1662
+ if (pending !== undefined) {
1663
+ return pending.value;
1669
1664
  }
1670
1665
  }
1671
1666
 
1672
1667
  if (nonMemoryScope === StorageScope.Secure && !isBiometric) {
1673
- if (durability.hasPendingSecureWrite(storageKey)) {
1674
- return durability.readPendingSecureWrite(storageKey);
1668
+ const pending = durability.getPendingSecureWrite(storageKey);
1669
+ if (pending !== undefined) {
1670
+ return pending.value;
1675
1671
  }
1676
1672
  }
1677
1673
 
1678
1674
  migrateRenamesIfNeeded();
1679
1675
 
1680
1676
  if (nonMemoryScope === StorageScope.Disk) {
1681
- if (durability.hasPendingDiskWrite(storageKey)) {
1682
- return durability.readPendingDiskWrite(storageKey);
1677
+ const pending = durability.getPendingDiskWrite(storageKey);
1678
+ if (pending !== undefined) {
1679
+ return pending.value;
1683
1680
  }
1684
1681
  }
1685
1682
 
1686
1683
  if (nonMemoryScope === StorageScope.Secure && !isBiometric) {
1687
- if (durability.hasPendingSecureWrite(storageKey)) {
1688
- return durability.readPendingSecureWrite(storageKey);
1684
+ const pending = durability.getPendingSecureWrite(storageKey);
1685
+ if (pending !== undefined) {
1686
+ return pending.value;
1689
1687
  }
1690
1688
  }
1691
1689
 
@@ -1964,21 +1962,22 @@ export function createStorageCore(
1964
1962
  const records = getItemStateKeys().map((key) => {
1965
1963
  let pending: ItemPendingSnapshot | undefined;
1966
1964
  if (nonMemoryScope === StorageScope.Disk) {
1967
- if (durability.hasPendingDiskWrite(key)) {
1965
+ const pendingWrite = durability.getPendingDiskWrite(key);
1966
+ if (pendingWrite !== undefined) {
1968
1967
  pending = {
1969
- value: durability.readPendingDiskWrite(key),
1968
+ value: pendingWrite.value,
1969
+ };
1970
+ }
1971
+ } else if (nonMemoryScope === StorageScope.Secure && !isBiometric) {
1972
+ const pendingWrite = durability.getPendingSecureWrite(key);
1973
+ if (pendingWrite !== undefined) {
1974
+ pending = {
1975
+ value: pendingWrite.value,
1976
+ ...(pendingWrite.accessControl === undefined
1977
+ ? {}
1978
+ : { accessControl: pendingWrite.accessControl }),
1970
1979
  };
1971
1980
  }
1972
- } else if (
1973
- nonMemoryScope === StorageScope.Secure &&
1974
- !isBiometric &&
1975
- durability.hasPendingSecureWrite(key)
1976
- ) {
1977
- const accessControl = durability.readPendingSecureAccessControl(key);
1978
- pending = {
1979
- value: durability.readPendingSecureWrite(key),
1980
- ...(accessControl === undefined ? {} : { accessControl }),
1981
- };
1982
1981
  }
1983
1982
 
1984
1983
  return {
@@ -2714,13 +2713,15 @@ export function createStorageCore(
2714
2713
  if (isMemory) return memoryStore.has(storageKey);
2715
2714
  if (isBiometric) return adapter.backend.hasSecureBiometric(storageKey);
2716
2715
  if (nonMemoryScope === StorageScope.Disk) {
2717
- if (durability.hasPendingDiskWrite(storageKey)) {
2718
- return durability.readPendingDiskWrite(storageKey) !== undefined;
2716
+ const pending = durability.getPendingDiskWrite(storageKey);
2717
+ if (pending !== undefined) {
2718
+ return pending.value !== undefined;
2719
2719
  }
2720
2720
  }
2721
2721
  if (nonMemoryScope === StorageScope.Secure) {
2722
- if (durability.hasPendingSecureWrite(storageKey)) {
2723
- return durability.readPendingSecureWrite(storageKey) !== undefined;
2722
+ const pending = durability.getPendingSecureWrite(storageKey);
2723
+ if (pending !== undefined) {
2724
+ return pending.value !== undefined;
2724
2725
  }
2725
2726
  }
2726
2727
  return adapter.backend.has(storageKey, config.scope);
@@ -2869,15 +2870,17 @@ export function createStorageCore(
2869
2870
 
2870
2871
  items.forEach((item, index) => {
2871
2872
  if (scope === StorageScope.Disk) {
2872
- if (durability.hasPendingDiskWrite(item.key)) {
2873
- rawValues[index] = durability.readPendingDiskWrite(item.key);
2873
+ const pending = durability.getPendingDiskWrite(item.key);
2874
+ if (pending !== undefined) {
2875
+ rawValues[index] = pending.value;
2874
2876
  return;
2875
2877
  }
2876
2878
  }
2877
2879
 
2878
2880
  if (scope === StorageScope.Secure) {
2879
- if (durability.hasPendingSecureWrite(item.key)) {
2880
- rawValues[index] = durability.readPendingSecureWrite(item.key);
2881
+ const pending = durability.getPendingSecureWrite(item.key);
2882
+ if (pending !== undefined) {
2883
+ rawValues[index] = pending.value;
2881
2884
  return;
2882
2885
  }
2883
2886
  }