react-native-nitro-storage 0.12.0 → 0.13.0

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.
@@ -574,8 +574,9 @@ export function createStorageCore(
574
574
  operation: StorageChangeOperation,
575
575
  source: StorageChangeSource,
576
576
  changes: StorageKeyChangeEvent[],
577
+ emitWhenEmpty = false,
577
578
  ): void {
578
- if (changes.length === 0) {
579
+ if (changes.length === 0 && !emitWhenEmpty) {
579
580
  return;
580
581
  }
581
582
 
@@ -1024,9 +1025,18 @@ export function createStorageCore(
1024
1025
  return;
1025
1026
  }
1026
1027
  measureOperation("storage:clear", scope, () => {
1027
- const previousValues = shouldReadPreviousEventValues(scope)
1028
- ? storage.getAll(scope)
1029
- : {};
1028
+ let previousValues: Record<string, string> = {};
1029
+ let previousValuesUnreadable = false;
1030
+ if (shouldReadPreviousEventValues(scope)) {
1031
+ try {
1032
+ previousValues = storage.getAll(scope);
1033
+ } catch (error) {
1034
+ if (scope !== StorageScope.Disk) {
1035
+ throw error;
1036
+ }
1037
+ previousValuesUnreadable = true;
1038
+ }
1039
+ }
1030
1040
  if (scope === StorageScope.Memory) {
1031
1041
  memoryStore.clear();
1032
1042
  memoryExpirationDeadlines.clear();
@@ -1049,9 +1059,15 @@ export function createStorageCore(
1049
1059
  return;
1050
1060
  }
1051
1061
 
1062
+ let diskFlushFailed = false;
1052
1063
  if (scope === StorageScope.Disk) {
1053
- flushDiskWrites();
1054
- durability.clearAllPendingDiskWrites();
1064
+ try {
1065
+ flushDiskWrites();
1066
+ durability.clearAllPendingDiskWrites();
1067
+ } catch {
1068
+ diskFlushFailed = true;
1069
+ previousValuesUnreadable = shouldReadPreviousEventValues(scope);
1070
+ }
1055
1071
  }
1056
1072
 
1057
1073
  if (scope === StorageScope.Secure) {
@@ -1061,6 +1077,9 @@ export function createStorageCore(
1061
1077
 
1062
1078
  clearScopeRawCache(scope);
1063
1079
  adapter.backend.clear(scope);
1080
+ if (diskFlushFailed) {
1081
+ durability.clearAllPendingDiskWrites();
1082
+ }
1064
1083
  emitBatchChange(
1065
1084
  scope,
1066
1085
  "clear",
@@ -1075,6 +1094,7 @@ export function createStorageCore(
1075
1094
  adapter.changeSource,
1076
1095
  ),
1077
1096
  ),
1097
+ previousValuesUnreadable,
1078
1098
  );
1079
1099
  });
1080
1100
  },