react-native-nitro-storage 0.10.3 → 0.10.4

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.
@@ -342,6 +342,20 @@ export function createStorageCore(
342
342
  let eventObserverRedactSecureValues = true;
343
343
  const storageEvents = new StorageEventRegistry();
344
344
  const metrics = createMetricsRegistry();
345
+
346
+ function setOwnDataProperty(
347
+ target: object,
348
+ key: string,
349
+ value: unknown,
350
+ ): void {
351
+ Object.defineProperty(target, key, {
352
+ configurable: true,
353
+ enumerable: true,
354
+ value,
355
+ writable: true,
356
+ });
357
+ }
358
+
345
359
  const durability = createDurabilityCoordinator({
346
360
  backend: {
347
361
  setBatch: (keys, values, scope) => {
@@ -1290,9 +1304,11 @@ export function createStorageCore(
1290
1304
  return measureOperation("storage:getKeysByPrefix", scope, () => {
1291
1305
  assertValidScope(scope);
1292
1306
  if (scope === StorageScope.Memory) {
1293
- return Array.from(memoryStore.keys()).filter((key) =>
1294
- key.startsWith(prefix),
1295
- );
1307
+ const keys: string[] = [];
1308
+ for (const key of memoryStore.keys()) {
1309
+ if (key.startsWith(prefix)) keys.push(key);
1310
+ }
1311
+ return keys;
1296
1312
  }
1297
1313
  if (scope === StorageScope.Disk) {
1298
1314
  flushDiskWrites();
@@ -1318,7 +1334,7 @@ export function createStorageCore(
1318
1334
  keys.forEach((key) => {
1319
1335
  const value = memoryStore.get(key);
1320
1336
  if (typeof value === "string") {
1321
- result[key] = value;
1337
+ setOwnDataProperty(result, key, unescapeCollidingRawValue(value));
1322
1338
  }
1323
1339
  });
1324
1340
  return result;
@@ -1334,7 +1350,7 @@ export function createStorageCore(
1334
1350
  keys.forEach((key, idx) => {
1335
1351
  const value = values[idx];
1336
1352
  if (value !== undefined) {
1337
- result[key] = unescapeCollidingRawValue(value);
1353
+ setOwnDataProperty(result, key, unescapeCollidingRawValue(value));
1338
1354
  }
1339
1355
  });
1340
1356
  return result;
@@ -1345,11 +1361,11 @@ export function createStorageCore(
1345
1361
  assertValidScope(scope);
1346
1362
  const result: Record<string, string> = {};
1347
1363
  if (scope === StorageScope.Memory) {
1348
- for (const key of memoryStore.keys()) {
1349
- const value = memoryStore.get(key);
1350
- if (typeof value === "string")
1351
- result[key] = unescapeCollidingRawValue(value);
1352
- }
1364
+ memoryStore.forEach((value, key) => {
1365
+ if (typeof value === "string") {
1366
+ setOwnDataProperty(result, key, unescapeCollidingRawValue(value));
1367
+ }
1368
+ });
1353
1369
  return result;
1354
1370
  }
1355
1371
  if (scope === StorageScope.Disk) {
@@ -1363,7 +1379,9 @@ export function createStorageCore(
1363
1379
  const values = adapter.backend.getBatch(keys, scope);
1364
1380
  keys.forEach((key, idx) => {
1365
1381
  const val = values[idx];
1366
- if (val !== undefined) result[key] = unescapeCollidingRawValue(val);
1382
+ if (val !== undefined) {
1383
+ setOwnDataProperty(result, key, unescapeCollidingRawValue(val));
1384
+ }
1367
1385
  });
1368
1386
  return result;
1369
1387
  });
@@ -3746,7 +3764,7 @@ export function createStorageCore(
3746
3764
  const initial: Record<string, true> = {};
3747
3765
  if (defaultValue) {
3748
3766
  for (const id of defaultValue) {
3749
- initial[id] = true;
3767
+ setOwnDataProperty(initial, id, true);
3750
3768
  }
3751
3769
  }
3752
3770
 
@@ -3763,7 +3781,7 @@ export function createStorageCore(
3763
3781
  return;
3764
3782
  }
3765
3783
  const next = { ...current };
3766
- next[id] = true;
3784
+ setOwnDataProperty(next, id, true);
3767
3785
  item.set(next);
3768
3786
  };
3769
3787
 
@@ -3789,7 +3807,7 @@ export function createStorageCore(
3789
3807
  const getTyped = (): Partial<Record<TMember, true>> => {
3790
3808
  const typed: Partial<Record<TMember, true>> = {};
3791
3809
  for (const id of Object.keys(item.get())) {
3792
- typed[id as TMember] = true;
3810
+ setOwnDataProperty(typed, id, true);
3793
3811
  }
3794
3812
  return typed;
3795
3813
  };