react-native-onyx 3.0.105 → 3.0.107

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.
@@ -21,11 +21,13 @@ class OnyxSnapshotCache {
21
21
  */
22
22
  getSelectorID(selector) {
23
23
  const typedSelector = selector;
24
- if (!this.selectorIDMap.has(typedSelector)) {
25
- const id = this.selectorIDCounter++;
26
- this.selectorIDMap.set(typedSelector, id);
24
+ const existingID = this.selectorIDMap.get(typedSelector);
25
+ if (existingID !== undefined) {
26
+ return existingID;
27
27
  }
28
- return this.selectorIDMap.get(typedSelector);
28
+ const id = this.selectorIDCounter++;
29
+ this.selectorIDMap.set(typedSelector, id);
30
+ return id;
29
31
  }
30
32
  /**
31
33
  * Register a consumer for a cache key and return the cache key.
@@ -40,10 +42,11 @@ class OnyxSnapshotCache {
40
42
  * or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
41
43
  */
42
44
  registerConsumer(key, options) {
45
+ var _a;
43
46
  const selectorID = (options === null || options === void 0 ? void 0 : options.selector) ? this.getSelectorID(options.selector) : 'no_selector';
44
47
  const cacheKey = `${key}_${selectorID}`;
45
48
  // Increment reference count for this cache key
46
- const currentCount = this.cacheKeyRefCounts.get(cacheKey) || 0;
49
+ const currentCount = (_a = this.cacheKeyRefCounts.get(cacheKey)) !== null && _a !== void 0 ? _a : 0;
47
50
  this.cacheKeyRefCounts.set(cacheKey, currentCount + 1);
48
51
  return cacheKey;
49
52
  }
@@ -52,7 +55,8 @@ class OnyxSnapshotCache {
52
55
  * Decrements reference counter and removes cache entry if no consumers remain.
53
56
  */
54
57
  deregisterConsumer(key, cacheKey) {
55
- const currentCount = this.cacheKeyRefCounts.get(cacheKey) || 0;
58
+ var _a;
59
+ const currentCount = (_a = this.cacheKeyRefCounts.get(cacheKey)) !== null && _a !== void 0 ? _a : 0;
56
60
  if (currentCount <= 1) {
57
61
  // Last consumer - remove from reference counter and cache
58
62
  this.cacheKeyRefCounts.delete(cacheKey);
@@ -82,10 +86,12 @@ class OnyxSnapshotCache {
82
86
  * Set cached snapshot result for a key and cache key combination
83
87
  */
84
88
  setCachedResult(key, cacheKey, result) {
85
- if (!this.snapshotCache.has(key)) {
86
- this.snapshotCache.set(key, new Map());
89
+ let keyCache = this.snapshotCache.get(key);
90
+ if (!keyCache) {
91
+ keyCache = new Map();
92
+ this.snapshotCache.set(key, keyCache);
87
93
  }
88
- this.snapshotCache.get(key).set(cacheKey, result);
94
+ keyCache.set(cacheKey, result);
89
95
  }
90
96
  /**
91
97
  * Selective cache invalidation to prevent data unavailability
package/dist/OnyxUtils.js CHANGED
@@ -183,7 +183,7 @@ function initStoreValues(keys, initialKeyStates, evictableKeys) {
183
183
  }
184
184
  }
185
185
  function sendActionToDevTools(method, key, value, mergedValue = undefined) {
186
- DevTools_1.default.registerAction(utils_1.default.formatActionName(method, key), value, key ? { [key]: mergedValue || value } : value);
186
+ DevTools_1.default.registerAction(utils_1.default.formatActionName(method, key), value, key ? { [key]: mergedValue !== undefined ? mergedValue : value } : value);
187
187
  }
188
188
  /**
189
189
  * Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}})
@@ -32,6 +32,20 @@ const StorageErrorClass = {
32
32
  UNKNOWN: 'unknown',
33
33
  };
34
34
  exports.StorageErrorClass = StorageErrorClass;
35
+ /**
36
+ * Serializes non-Error thrown values for classifier matching. JSON.stringify is preferred for plain
37
+ * objects, but it throws on circular structures and returns undefined for BigInt/function/symbol, so
38
+ * fall back to String() to keep normalization from throwing before classifyError runs.
39
+ */
40
+ function serializeThrownValue(error) {
41
+ var _a;
42
+ try {
43
+ return (_a = JSON.stringify(error)) !== null && _a !== void 0 ? _a : String(error);
44
+ }
45
+ catch (_b) {
46
+ return String(error);
47
+ }
48
+ }
35
49
  /**
36
50
  * Normalizes any thrown value into a lowercased `{name, message}` pair for matching. Shared by every
37
51
  * provider's classifier so they all extract the error the same way.
@@ -39,7 +53,16 @@ exports.StorageErrorClass = StorageErrorClass;
39
53
  function getErrorParts(error) {
40
54
  var _a, _b;
41
55
  if (error instanceof Error || (typeof DOMException !== 'undefined' && error instanceof DOMException)) {
42
- return { name: ((_a = error.name) !== null && _a !== void 0 ? _a : '').toLowerCase(), message: ((_b = error.message) !== null && _b !== void 0 ? _b : '').toLowerCase() };
56
+ return {
57
+ name: ((_a = error.name) !== null && _a !== void 0 ? _a : '').toLowerCase(),
58
+ message: ((_b = error.message) !== null && _b !== void 0 ? _b : '').toLowerCase(),
59
+ };
60
+ }
61
+ if (typeof error === 'string') {
62
+ return { name: '', message: error.toLowerCase() };
63
+ }
64
+ if (error === null || error === undefined) {
65
+ return { name: '', message: '' };
43
66
  }
44
- return { name: '', message: String(error !== null && error !== void 0 ? error : '').toLowerCase() };
67
+ return { name: '', message: serializeThrownValue(error).toLowerCase() };
45
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.105",
3
+ "version": "3.0.107",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",