react-native-onyx 3.0.53 → 3.0.55

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/dist/OnyxUtils.js CHANGED
@@ -42,12 +42,11 @@ const underscore_1 = __importDefault(require("underscore"));
42
42
  const DevTools_1 = __importDefault(require("./DevTools"));
43
43
  const Logger = __importStar(require("./Logger"));
44
44
  const OnyxCache_1 = __importStar(require("./OnyxCache"));
45
+ const OnyxKeys_1 = __importDefault(require("./OnyxKeys"));
45
46
  const Str = __importStar(require("./Str"));
46
47
  const storage_1 = __importDefault(require("./storage"));
47
48
  const utils_1 = __importDefault(require("./utils"));
48
49
  const createDeferredTask_1 = __importDefault(require("./createDeferredTask"));
49
- const GlobalSettings = __importStar(require("./GlobalSettings"));
50
- const metrics_1 = __importDefault(require("./metrics"));
51
50
  const logMessages_1 = __importDefault(require("./logMessages"));
52
51
  // Method constants
53
52
  const METHOD = {
@@ -78,8 +77,6 @@ let mergeQueuePromise = {};
78
77
  let nextMacrotaskPromise = null;
79
78
  // Holds a mapping of all the React components that want their state subscribed to a store key
80
79
  let callbackToStateMapping = {};
81
- // Keeps a copy of the values of the onyx collection keys as a map for faster lookups
82
- let onyxCollectionKeySet = new Set();
83
80
  // Holds a mapping of the connected key to the subscriptionID for faster lookups
84
81
  let onyxKeyToSubscriptionIDs = new Map();
85
82
  // Optional user-provided key value states set when Onyx initializes or clears
@@ -174,7 +171,7 @@ function initStoreValues(keys, initialKeyStates, evictableKeys) {
174
171
  // We need the value of the collection keys later for checking if a
175
172
  // key is a collection. We store it in a map for faster lookup.
176
173
  const collectionValues = Object.values((_a = keys.COLLECTION) !== null && _a !== void 0 ? _a : {});
177
- onyxCollectionKeySet = collectionValues.reduce((acc, val) => {
174
+ const collectionKeySet = collectionValues.reduce((acc, val) => {
178
175
  acc.add(val);
179
176
  return acc;
180
177
  }, new Set());
@@ -184,7 +181,7 @@ function initStoreValues(keys, initialKeyStates, evictableKeys) {
184
181
  // Let Onyx know about which keys are safe to evict
185
182
  OnyxCache_1.default.setEvictionAllowList(evictableKeys);
186
183
  // Set collection keys in cache for optimized storage
187
- OnyxCache_1.default.setCollectionKeys(onyxCollectionKeySet);
184
+ OnyxCache_1.default.setCollectionKeys(collectionKeySet);
188
185
  if (typeof keys.COLLECTION === 'object' && typeof keys.COLLECTION.SNAPSHOT === 'string') {
189
186
  snapshotKey = keys.COLLECTION.SNAPSHOT;
190
187
  }
@@ -213,7 +210,7 @@ function get(key) {
213
210
  // RAM-only keys should never read from storage (they may have stale persisted data
214
211
  // from before the key was migrated to RAM-only). Mark as nullish so future get() calls
215
212
  // short-circuit via hasCacheForKey and avoid re-running this branch.
216
- if (isRamOnlyKey(key)) {
213
+ if (OnyxKeys_1.default.isRamOnlyKey(key)) {
217
214
  OnyxCache_1.default.addNullishStorageKey(key);
218
215
  return Promise.resolve(undefined);
219
216
  }
@@ -227,7 +224,7 @@ function get(key) {
227
224
  .then((val) => {
228
225
  if (skippableCollectionMemberIDs.size) {
229
226
  try {
230
- const [, collectionMemberID] = splitCollectionMemberKey(key);
227
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key);
231
228
  if (skippableCollectionMemberIDs.has(collectionMemberID)) {
232
229
  // The key is a skippable one, so we set the value to undefined.
233
230
  // eslint-disable-next-line no-param-reassign
@@ -269,7 +266,7 @@ function multiGet(keys) {
269
266
  for (const key of keys) {
270
267
  // RAM-only keys should never read from storage as they may have stale persisted data
271
268
  // from before the key was migrated to RAM-only.
272
- if (isRamOnlyKey(key)) {
269
+ if (OnyxKeys_1.default.isRamOnlyKey(key)) {
273
270
  if (OnyxCache_1.default.hasCacheForKey(key)) {
274
271
  dataMap.set(key, OnyxCache_1.default.get(key));
275
272
  }
@@ -314,7 +311,7 @@ function multiGet(keys) {
314
311
  for (const [key, value] of values) {
315
312
  if (skippableCollectionMemberIDs.size) {
316
313
  try {
317
- const [, collectionMemberID] = splitCollectionMemberKey(key);
314
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key);
318
315
  if (skippableCollectionMemberIDs.has(collectionMemberID)) {
319
316
  // The key is a skippable one, so we skip this iteration.
320
317
  continue;
@@ -380,126 +377,20 @@ function getAllKeys() {
380
377
  const promise = storage_1.default.getAllKeys().then((keys) => {
381
378
  // Filter out RAM-only keys from storage results as they may be stale entries
382
379
  // from before the key was migrated to RAM-only.
383
- const filteredKeys = keys.filter((key) => !isRamOnlyKey(key));
380
+ const filteredKeys = keys.filter((key) => !OnyxKeys_1.default.isRamOnlyKey(key));
384
381
  OnyxCache_1.default.setAllKeys(filteredKeys);
385
382
  // return the updated set of keys
386
383
  return OnyxCache_1.default.getAllKeys();
387
384
  });
388
385
  return OnyxCache_1.default.captureTask(OnyxCache_1.TASK.GET_ALL_KEYS, promise);
389
386
  }
390
- /**
391
- * Returns set of all registered collection keys
392
- */
393
- function getCollectionKeys() {
394
- return onyxCollectionKeySet;
395
- }
396
- /**
397
- * Checks to see if the subscriber's supplied key
398
- * is associated with a collection of keys.
399
- */
400
- function isCollectionKey(key) {
401
- return onyxCollectionKeySet.has(key);
402
- }
403
- function isCollectionMemberKey(collectionKey, key) {
404
- return key.startsWith(collectionKey) && key.length > collectionKey.length;
405
- }
406
- /**
407
- * Checks if a given key is a collection member key (not just a collection key).
408
- * @param key - The key to check
409
- * @returns true if the key is a collection member, false otherwise
410
- */
411
- function isCollectionMember(key) {
412
- const collectionKey = getCollectionKey(key);
413
- // If the key is longer than the collection key, it's a collection member
414
- return !!collectionKey && key.length > collectionKey.length;
415
- }
416
- /**
417
- * Checks if a given key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
418
- *
419
- * For example:
420
- *
421
- * For the following Onyx setup
422
- *
423
- * ramOnlyKeys: ["ramOnlyKey", "ramOnlyCollection_"]
424
- *
425
- * - `isRamOnlyKey("ramOnlyKey")` would return true
426
- * - `isRamOnlyKey("ramOnlyCollection_")` would return true
427
- * - `isRamOnlyKey("ramOnlyCollection_1")` would return true
428
- * - `isRamOnlyKey("someOtherKey")` would return false
429
- *
430
- * @param key - The key to check
431
- * @returns true if key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
432
- */
433
- function isRamOnlyKey(key) {
434
- const collectionKey = getCollectionKey(key);
435
- if (collectionKey) {
436
- return OnyxCache_1.default.isRamOnlyKey(collectionKey);
437
- }
438
- return OnyxCache_1.default.isRamOnlyKey(key);
439
- }
440
- /**
441
- * Splits a collection member key into the collection key part and the ID part.
442
- * @param key - The collection member key to split.
443
- * @param collectionKey - The collection key of the `key` param that can be passed in advance to optimize the function.
444
- * @returns A tuple where the first element is the collection part and the second element is the ID part,
445
- * or throws an Error if the key is not a collection one.
446
- */
447
- function splitCollectionMemberKey(key, collectionKey) {
448
- if (collectionKey && !isCollectionMemberKey(collectionKey, key)) {
449
- throw new Error(`Invalid '${collectionKey}' collection key provided, it isn't compatible with '${key}' key.`);
450
- }
451
- if (!collectionKey) {
452
- const resolvedKey = getCollectionKey(key);
453
- if (!resolvedKey) {
454
- throw new Error(`Invalid '${key}' key provided, only collection keys are allowed.`);
455
- }
456
- // eslint-disable-next-line no-param-reassign
457
- collectionKey = resolvedKey;
458
- }
459
- return [collectionKey, key.slice(collectionKey.length)];
460
- }
461
- /**
462
- * Checks to see if a provided key is the exact configured key of our connected subscriber
463
- * or if the provided key is a collection member key (in case our configured key is a "collection key")
464
- */
465
- function isKeyMatch(configKey, key) {
466
- return isCollectionKey(configKey) ? Str.startsWith(key, configKey) : configKey === key;
467
- }
468
- /**
469
- * Extracts the collection identifier of a given collection member key.
470
- *
471
- * For example:
472
- * - `getCollectionKey("report_123")` would return "report_"
473
- * - `getCollectionKey("report_")` would return "report_"
474
- * - `getCollectionKey("report_-1_something")` would return "report_"
475
- * - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
476
- *
477
- * @param key - The collection key to process.
478
- * @returns The plain collection key or undefined if the key is not a collection one.
479
- */
480
- function getCollectionKey(key) {
481
- // Start by finding the position of the last underscore in the string
482
- let lastUnderscoreIndex = key.lastIndexOf('_');
483
- // Iterate backwards to find the longest key that ends with '_'
484
- while (lastUnderscoreIndex > 0) {
485
- const possibleKey = key.slice(0, lastUnderscoreIndex + 1);
486
- // Check if the substring is a key in the Set
487
- if (isCollectionKey(possibleKey)) {
488
- // Return the matching key and the rest of the string
489
- return possibleKey;
490
- }
491
- // Move to the next underscore to check smaller possible keys
492
- lastUnderscoreIndex = key.lastIndexOf('_', lastUnderscoreIndex - 1);
493
- }
494
- return undefined;
495
- }
496
387
  /**
497
388
  * Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
498
389
  * If the requested key is a collection, it will return an object with all the collection members.
499
390
  */
500
391
  function tryGetCachedValue(key) {
501
392
  let val = OnyxCache_1.default.get(key);
502
- if (isCollectionKey(key)) {
393
+ if (OnyxKeys_1.default.isCollectionKey(key)) {
503
394
  const collectionData = OnyxCache_1.default.getCollectionData(key);
504
395
  if (collectionData !== undefined) {
505
396
  val = collectionData;
@@ -543,7 +434,7 @@ function getCachedCollection(collectionKey, collectionMemberKeys) {
543
434
  // If we don't have collectionMemberKeys array then we have to check whether a key is a collection member key.
544
435
  // Because in that case the keys will be coming from `cache.getAllKeys()` and we need to filter out the keys that
545
436
  // are not part of the collection.
546
- if (!collectionMemberKeys && !isCollectionMemberKey(collectionKey, key)) {
437
+ if (!collectionMemberKeys && !OnyxKeys_1.default.isCollectionMemberKey(collectionKey, key)) {
547
438
  continue;
548
439
  }
549
440
  const cachedValue = OnyxCache_1.default.get(key);
@@ -582,7 +473,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
582
473
  /**
583
474
  * e.g. Onyx.connect({key: `${ONYXKEYS.COLLECTION.REPORT}{reportID}`, callback: ...});
584
475
  */
585
- const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key);
476
+ const isSubscribedToCollectionMemberKey = OnyxKeys_1.default.isCollectionMemberKey(collectionKey, subscriber.key);
586
477
  // Regular Onyx.connect() subscriber found.
587
478
  if (typeof subscriber.callback === 'function') {
588
479
  // If they are subscribed to the collection key and using waitForCollectionCallback then we'll
@@ -628,7 +519,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
628
519
  var _a, _b;
629
520
  // Add or remove this key from the recentlyAccessedKeys lists
630
521
  if (value !== null) {
631
- OnyxCache_1.default.addLastAccessedKey(key, isCollectionKey(key));
522
+ OnyxCache_1.default.addLastAccessedKey(key, OnyxKeys_1.default.isCollectionKey(key));
632
523
  }
633
524
  else {
634
525
  OnyxCache_1.default.removeLastAccessedKey(key);
@@ -639,7 +530,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
639
530
  // do the same in keysChanged, because we only call that function when a collection key changes, and it doesn't happen that often.
640
531
  // For performance reason, we look for the given key and later if don't find it we look for the collection key, instead of checking if it is a collection key first.
641
532
  let stateMappingKeys = (_a = onyxKeyToSubscriptionIDs.get(key)) !== null && _a !== void 0 ? _a : [];
642
- const collectionKey = getCollectionKey(key);
533
+ const collectionKey = OnyxKeys_1.default.getCollectionKey(key);
643
534
  if (collectionKey) {
644
535
  // Getting the collection key from the specific key because only collection keys were stored in the mapping.
645
536
  stateMappingKeys = [...stateMappingKeys, ...((_b = onyxKeyToSubscriptionIDs.get(collectionKey)) !== null && _b !== void 0 ? _b : [])];
@@ -650,7 +541,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
650
541
  const cachedCollections = {};
651
542
  for (const stateMappingKey of stateMappingKeys) {
652
543
  const subscriber = callbackToStateMapping[stateMappingKey];
653
- if (!subscriber || !isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
544
+ if (!subscriber || !OnyxKeys_1.default.isKeyMatch(subscriber.key, key) || !canUpdateSubscriber(subscriber)) {
654
545
  continue;
655
546
  }
656
547
  // Subscriber is a regular call to connect() and provided a callback
@@ -658,7 +549,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
658
549
  if (lastConnectionCallbackData.has(subscriber.subscriptionID) && lastConnectionCallbackData.get(subscriber.subscriptionID) === value) {
659
550
  continue;
660
551
  }
661
- if (isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) {
552
+ if (OnyxKeys_1.default.isCollectionKey(subscriber.key) && subscriber.waitForCollectionCallback) {
662
553
  // Skip individual key changes for collection callbacks during collection updates
663
554
  // to prevent duplicate callbacks - the collection update will handle this properly
664
555
  if (isProcessingCollectionUpdate) {
@@ -762,7 +653,7 @@ function scheduleNotifyCollectionSubscribers(key, value, previousValue) {
762
653
  function remove(key, isProcessingCollectionUpdate) {
763
654
  OnyxCache_1.default.drop(key);
764
655
  scheduleSubscriberUpdate(key, undefined, undefined, isProcessingCollectionUpdate);
765
- if (isRamOnlyKey(key)) {
656
+ if (OnyxKeys_1.default.isRamOnlyKey(key)) {
766
657
  return Promise.resolve();
767
658
  }
768
659
  return storage_1.default.removeItem(key).then(() => undefined);
@@ -918,12 +809,12 @@ function initializeWithDefaultKeyStates() {
918
809
  for (const [key, value] of pairs) {
919
810
  // RAM-only keys should not be cached from storage as they may have stale persisted data
920
811
  // from before the key was migrated to RAM-only.
921
- if (isRamOnlyKey(key)) {
812
+ if (OnyxKeys_1.default.isRamOnlyKey(key)) {
922
813
  continue;
923
814
  }
924
815
  // Skip collection members that are marked as skippable
925
- if (skippableCollectionMemberIDs.size && getCollectionKey(key)) {
926
- const [, collectionMemberID] = splitCollectionMemberKey(key);
816
+ if (skippableCollectionMemberIDs.size && OnyxKeys_1.default.getCollectionKey(key)) {
817
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key);
927
818
  if (skippableCollectionMemberIDs.has(collectionMemberID)) {
928
819
  continue;
929
820
  }
@@ -981,7 +872,7 @@ function isValidNonEmptyCollectionForMerge(collection) {
981
872
  function doAllCollectionItemsBelongToSameParent(collectionKey, collectionKeys) {
982
873
  let hasCollectionKeyCheckFailed = false;
983
874
  for (const dataKey of collectionKeys) {
984
- if (isKeyMatch(collectionKey, dataKey)) {
875
+ if (OnyxKeys_1.default.isKeyMatch(collectionKey, dataKey)) {
985
876
  continue;
986
877
  }
987
878
  if (process.env.NODE_ENV === 'development') {
@@ -1017,7 +908,7 @@ function subscribeToKey(connectOptions) {
1017
908
  // Performance improvement
1018
909
  // If the mapping is connected to an onyx key that is not a collection
1019
910
  // we can skip the call to getAllKeys() and return an array with a single item
1020
- if (!!mapping.key && typeof mapping.key === 'string' && !isCollectionKey(mapping.key) && OnyxCache_1.default.getAllKeys().has(mapping.key)) {
911
+ if (!!mapping.key && typeof mapping.key === 'string' && !OnyxKeys_1.default.isCollectionKey(mapping.key) && OnyxCache_1.default.getAllKeys().has(mapping.key)) {
1021
912
  return new Set([mapping.key]);
1022
913
  }
1023
914
  return getAllKeys();
@@ -1028,7 +919,7 @@ function subscribeToKey(connectOptions) {
1028
919
  // subscribed to a "collection key" or a single key.
1029
920
  const matchingKeys = [];
1030
921
  // Performance optimization: For single key subscriptions, avoid O(n) iteration
1031
- if (!isCollectionKey(mapping.key)) {
922
+ if (!OnyxKeys_1.default.isCollectionKey(mapping.key)) {
1032
923
  if (keys.has(mapping.key)) {
1033
924
  matchingKeys.push(mapping.key);
1034
925
  }
@@ -1036,7 +927,7 @@ function subscribeToKey(connectOptions) {
1036
927
  else {
1037
928
  // Collection case - need to iterate through all keys to find matches (O(n))
1038
929
  for (const key of keys) {
1039
- if (!isKeyMatch(mapping.key, key)) {
930
+ if (!OnyxKeys_1.default.isKeyMatch(mapping.key, key)) {
1040
931
  continue;
1041
932
  }
1042
933
  matchingKeys.push(key);
@@ -1049,7 +940,7 @@ function subscribeToKey(connectOptions) {
1049
940
  if (mapping.key) {
1050
941
  OnyxCache_1.default.addNullishStorageKey(mapping.key);
1051
942
  }
1052
- const matchedKey = isCollectionKey(mapping.key) && mapping.waitForCollectionCallback ? mapping.key : undefined;
943
+ const matchedKey = OnyxKeys_1.default.isCollectionKey(mapping.key) && mapping.waitForCollectionCallback ? mapping.key : undefined;
1053
944
  // Here we cannot use batching because the nullish value is expected to be set immediately for default props
1054
945
  // or they will be undefined.
1055
946
  sendDataToConnection(mapping, null, matchedKey);
@@ -1059,7 +950,7 @@ function subscribeToKey(connectOptions) {
1059
950
  // into an object and just make a single call. The latter behavior is enabled by providing a waitForCollectionCallback key
1060
951
  // combined with a subscription to a collection key.
1061
952
  if (typeof mapping.callback === 'function') {
1062
- if (isCollectionKey(mapping.key)) {
953
+ if (OnyxKeys_1.default.isCollectionKey(mapping.key)) {
1063
954
  if (mapping.waitForCollectionCallback) {
1064
955
  getCollectionDataAndSendAsObject(matchingKeys, mapping);
1065
956
  return;
@@ -1108,7 +999,7 @@ function updateSnapshots(data, mergeFn) {
1108
999
  let updatedData = {};
1109
1000
  for (const { key, value } of data) {
1110
1001
  // snapshots are normal keys so we want to skip update if they are written to Onyx
1111
- if (isCollectionMemberKey(snapshotCollectionKey, key)) {
1002
+ if (OnyxKeys_1.default.isCollectionMemberKey(snapshotCollectionKey, key)) {
1112
1003
  continue;
1113
1004
  }
1114
1005
  if (typeof snapshotEntryValue !== 'object' || !('data' in snapshotEntryValue)) {
@@ -1164,7 +1055,7 @@ function setWithRetry({ key, value, options }, retryAttempt) {
1164
1055
  }
1165
1056
  if (skippableCollectionMemberIDs.size) {
1166
1057
  try {
1167
- const [, collectionMemberID] = OnyxUtils.splitCollectionMemberKey(key);
1058
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key);
1168
1059
  if (skippableCollectionMemberIDs.has(collectionMemberID)) {
1169
1060
  // The key is a skippable one, so we set the new value to null.
1170
1061
  // eslint-disable-next-line no-param-reassign
@@ -1213,7 +1104,7 @@ function setWithRetry({ key, value, options }, retryAttempt) {
1213
1104
  return updatePromise;
1214
1105
  }
1215
1106
  // If a key is a RAM-only key or a member of RAM-only collection, we skip the step that modifies the storage
1216
- if (isRamOnlyKey(key)) {
1107
+ if (OnyxKeys_1.default.isRamOnlyKey(key)) {
1217
1108
  OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.SET, key, valueWithoutNestedNullValues);
1218
1109
  return updatePromise;
1219
1110
  }
@@ -1237,7 +1128,7 @@ function multiSetWithRetry(data, retryAttempt) {
1237
1128
  if (skippableCollectionMemberIDs.size) {
1238
1129
  newData = Object.keys(newData).reduce((result, key) => {
1239
1130
  try {
1240
- const [, collectionMemberID] = OnyxUtils.splitCollectionMemberKey(key);
1131
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key);
1241
1132
  // If the collection member key is a skippable one we set its value to null.
1242
1133
  // eslint-disable-next-line no-param-reassign
1243
1134
  result[key] = !skippableCollectionMemberIDs.has(collectionMemberID) ? newData[key] : null;
@@ -1264,7 +1155,7 @@ function multiSetWithRetry(data, retryAttempt) {
1264
1155
  const keyValuePairsToStore = keyValuePairsToSet.filter((keyValuePair) => {
1265
1156
  const [key] = keyValuePair;
1266
1157
  // Filter out the RAM-only key value pairs, as they should not be saved to storage
1267
- return !isRamOnlyKey(key);
1158
+ return !OnyxKeys_1.default.isRamOnlyKey(key);
1268
1159
  });
1269
1160
  return storage_1.default.multiSet(keyValuePairsToStore)
1270
1161
  .catch((error) => OnyxUtils.retryOperation(error, multiSetWithRetry, newData, retryAttempt))
@@ -1296,7 +1187,7 @@ function setCollectionWithRetry({ collectionKey, collection }, retryAttempt) {
1296
1187
  if (skippableCollectionMemberIDs.size) {
1297
1188
  resultCollection = resultCollectionKeys.reduce((result, key) => {
1298
1189
  try {
1299
- const [, collectionMemberID] = OnyxUtils.splitCollectionMemberKey(key, collectionKey);
1190
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key, collectionKey);
1300
1191
  // If the collection member key is a skippable one we set its value to null.
1301
1192
  // eslint-disable-next-line no-param-reassign
1302
1193
  result[key] = !skippableCollectionMemberIDs.has(collectionMemberID) ? resultCollection[key] : null;
@@ -1327,7 +1218,7 @@ function setCollectionWithRetry({ collectionKey, collection }, retryAttempt) {
1327
1218
  OnyxCache_1.default.set(key, value);
1328
1219
  const updatePromise = OnyxUtils.scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
1329
1220
  // RAM-only keys are not supposed to be saved to storage
1330
- if (isRamOnlyKey(collectionKey)) {
1221
+ if (OnyxKeys_1.default.isRamOnlyKey(collectionKey)) {
1331
1222
  OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.SET_COLLECTION, undefined, mutableCollection);
1332
1223
  return updatePromise;
1333
1224
  }
@@ -1366,7 +1257,7 @@ function mergeCollectionWithPatches({ collectionKey, collection, mergeReplaceNul
1366
1257
  if (skippableCollectionMemberIDs.size) {
1367
1258
  resultCollection = resultCollectionKeys.reduce((result, key) => {
1368
1259
  try {
1369
- const [, collectionMemberID] = splitCollectionMemberKey(key, collectionKey);
1260
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key, collectionKey);
1370
1261
  // If the collection member key is a skippable one we set its value to null.
1371
1262
  // eslint-disable-next-line no-param-reassign
1372
1263
  result[key] = !skippableCollectionMemberIDs.has(collectionMemberID) ? resultCollection[key] : null;
@@ -1429,11 +1320,11 @@ function mergeCollectionWithPatches({ collectionKey, collection, mergeReplaceNul
1429
1320
  // New keys will be added via multiSet while existing keys will be updated using multiMerge
1430
1321
  // This is because setting a key that doesn't exist yet with multiMerge will throw errors
1431
1322
  // We can skip this step for RAM-only keys as they should never be saved to storage
1432
- if (!isRamOnlyKey(collectionKey) && keyValuePairsForExistingCollection.length > 0) {
1323
+ if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForExistingCollection.length > 0) {
1433
1324
  promises.push(storage_1.default.multiMerge(keyValuePairsForExistingCollection));
1434
1325
  }
1435
1326
  // We can skip this step for RAM-only keys as they should never be saved to storage
1436
- if (!isRamOnlyKey(collectionKey) && keyValuePairsForNewCollection.length > 0) {
1327
+ if (!OnyxKeys_1.default.isRamOnlyKey(collectionKey) && keyValuePairsForNewCollection.length > 0) {
1437
1328
  promises.push(storage_1.default.multiSet(keyValuePairsForNewCollection));
1438
1329
  }
1439
1330
  // finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
@@ -1474,7 +1365,7 @@ function partialSetCollection({ collectionKey, collection }, retryAttempt) {
1474
1365
  if (skippableCollectionMemberIDs.size) {
1475
1366
  resultCollection = resultCollectionKeys.reduce((result, key) => {
1476
1367
  try {
1477
- const [, collectionMemberID] = splitCollectionMemberKey(key, collectionKey);
1368
+ const [, collectionMemberID] = OnyxKeys_1.default.splitCollectionMemberKey(key, collectionKey);
1478
1369
  // If the collection member key is a skippable one we set its value to null.
1479
1370
  // eslint-disable-next-line no-param-reassign
1480
1371
  result[key] = !skippableCollectionMemberIDs.has(collectionMemberID) ? resultCollection[key] : null;
@@ -1496,7 +1387,7 @@ function partialSetCollection({ collectionKey, collection }, retryAttempt) {
1496
1387
  for (const [key, value] of keyValuePairs)
1497
1388
  OnyxCache_1.default.set(key, value);
1498
1389
  const updatePromise = scheduleNotifyCollectionSubscribers(collectionKey, mutableCollection, previousCollection);
1499
- if (isRamOnlyKey(collectionKey)) {
1390
+ if (OnyxKeys_1.default.isRamOnlyKey(collectionKey)) {
1500
1391
  sendActionToDevTools(METHOD.SET_COLLECTION, undefined, mutableCollection);
1501
1392
  return updatePromise;
1502
1393
  }
@@ -1535,18 +1426,11 @@ const OnyxUtils = {
1535
1426
  sendActionToDevTools,
1536
1427
  get,
1537
1428
  getAllKeys,
1538
- getCollectionKeys,
1539
- isCollectionKey,
1540
- isCollectionMemberKey,
1541
- isCollectionMember,
1542
- splitCollectionMemberKey,
1543
- isKeyMatch,
1544
1429
  tryGetCachedValue,
1545
1430
  getCachedCollection,
1546
1431
  keysChanged,
1547
1432
  keyChanged,
1548
1433
  sendDataToConnection,
1549
- getCollectionKey,
1550
1434
  getCollectionDataAndSendAsObject,
1551
1435
  scheduleSubscriberUpdate,
1552
1436
  scheduleNotifyCollectionSubscribers,
@@ -1582,52 +1466,5 @@ const OnyxUtils = {
1582
1466
  setWithRetry,
1583
1467
  multiSetWithRetry,
1584
1468
  setCollectionWithRetry,
1585
- isRamOnlyKey,
1586
1469
  };
1587
- GlobalSettings.addGlobalSettingsChangeListener(({ enablePerformanceMetrics }) => {
1588
- if (!enablePerformanceMetrics) {
1589
- return;
1590
- }
1591
- // We are reassigning the functions directly so that internal function calls are also decorated
1592
- // @ts-expect-error Reassign
1593
- initStoreValues = (0, metrics_1.default)(initStoreValues, 'OnyxUtils.initStoreValues');
1594
- // @ts-expect-error Complex type signature
1595
- get = (0, metrics_1.default)(get, 'OnyxUtils.get');
1596
- // @ts-expect-error Reassign
1597
- getAllKeys = (0, metrics_1.default)(getAllKeys, 'OnyxUtils.getAllKeys');
1598
- // @ts-expect-error Reassign
1599
- getCollectionKeys = (0, metrics_1.default)(getCollectionKeys, 'OnyxUtils.getCollectionKeys');
1600
- // @ts-expect-error Reassign
1601
- keysChanged = (0, metrics_1.default)(keysChanged, 'OnyxUtils.keysChanged');
1602
- // @ts-expect-error Reassign
1603
- keyChanged = (0, metrics_1.default)(keyChanged, 'OnyxUtils.keyChanged');
1604
- // @ts-expect-error Reassign
1605
- sendDataToConnection = (0, metrics_1.default)(sendDataToConnection, 'OnyxUtils.sendDataToConnection');
1606
- // @ts-expect-error Reassign
1607
- scheduleSubscriberUpdate = (0, metrics_1.default)(scheduleSubscriberUpdate, 'OnyxUtils.scheduleSubscriberUpdate');
1608
- // @ts-expect-error Reassign
1609
- scheduleNotifyCollectionSubscribers = (0, metrics_1.default)(scheduleNotifyCollectionSubscribers, 'OnyxUtils.scheduleNotifyCollectionSubscribers');
1610
- // @ts-expect-error Reassign
1611
- remove = (0, metrics_1.default)(remove, 'OnyxUtils.remove');
1612
- // @ts-expect-error Reassign
1613
- reportStorageQuota = (0, metrics_1.default)(reportStorageQuota, 'OnyxUtils.reportStorageQuota');
1614
- // @ts-expect-error Complex type signature
1615
- retryOperation = (0, metrics_1.default)(retryOperation, 'OnyxUtils.retryOperation');
1616
- // @ts-expect-error Reassign
1617
- broadcastUpdate = (0, metrics_1.default)(broadcastUpdate, 'OnyxUtils.broadcastUpdate');
1618
- // @ts-expect-error Reassign
1619
- initializeWithDefaultKeyStates = (0, metrics_1.default)(initializeWithDefaultKeyStates, 'OnyxUtils.initializeWithDefaultKeyStates');
1620
- // @ts-expect-error Complex type signature
1621
- multiGet = (0, metrics_1.default)(multiGet, 'OnyxUtils.multiGet');
1622
- // @ts-expect-error Reassign
1623
- tupleGet = (0, metrics_1.default)(tupleGet, 'OnyxUtils.tupleGet');
1624
- // @ts-expect-error Reassign
1625
- subscribeToKey = (0, metrics_1.default)(subscribeToKey, 'OnyxUtils.subscribeToKey');
1626
- // @ts-expect-error Reassign
1627
- setWithRetry = (0, metrics_1.default)(setWithRetry, 'OnyxUtils.setWithRetry');
1628
- // @ts-expect-error Reassign
1629
- multiSetWithRetry = (0, metrics_1.default)(multiSetWithRetry, 'OnyxUtils.multiSetWithRetry');
1630
- // @ts-expect-error Reassign
1631
- setCollectionWithRetry = (0, metrics_1.default)(setCollectionWithRetry, 'OnyxUtils.setCollectionWithRetry');
1632
- });
1633
1470
  exports.default = OnyxUtils;
@@ -40,8 +40,6 @@ const Logger = __importStar(require("../Logger"));
40
40
  const platforms_1 = __importDefault(require("./platforms"));
41
41
  const InstanceSync_1 = __importDefault(require("./InstanceSync"));
42
42
  const MemoryOnlyProvider_1 = __importDefault(require("./providers/MemoryOnlyProvider"));
43
- const GlobalSettings = __importStar(require("../GlobalSettings"));
44
- const metrics_1 = __importDefault(require("../metrics"));
45
43
  let provider = platforms_1.default;
46
44
  let shouldKeepInstancesSync = false;
47
45
  let finishInitalization;
@@ -200,21 +198,4 @@ const storage = {
200
198
  InstanceSync_1.default.init(onStorageKeyChanged, this);
201
199
  },
202
200
  };
203
- GlobalSettings.addGlobalSettingsChangeListener(({ enablePerformanceMetrics }) => {
204
- if (!enablePerformanceMetrics) {
205
- return;
206
- }
207
- // Apply decorators
208
- storage.getItem = (0, metrics_1.default)(storage.getItem, 'Storage.getItem');
209
- storage.multiGet = (0, metrics_1.default)(storage.multiGet, 'Storage.multiGet');
210
- storage.setItem = (0, metrics_1.default)(storage.setItem, 'Storage.setItem');
211
- storage.multiSet = (0, metrics_1.default)(storage.multiSet, 'Storage.multiSet');
212
- storage.mergeItem = (0, metrics_1.default)(storage.mergeItem, 'Storage.mergeItem');
213
- storage.multiMerge = (0, metrics_1.default)(storage.multiMerge, 'Storage.multiMerge');
214
- storage.removeItem = (0, metrics_1.default)(storage.removeItem, 'Storage.removeItem');
215
- storage.removeItems = (0, metrics_1.default)(storage.removeItems, 'Storage.removeItems');
216
- storage.clear = (0, metrics_1.default)(storage.clear, 'Storage.clear');
217
- storage.getAllKeys = (0, metrics_1.default)(storage.getAllKeys, 'Storage.getAllKeys');
218
- storage.getAll = (0, metrics_1.default)(storage.getAll, 'Storage.getAll');
219
- });
220
201
  exports.default = storage;
package/dist/types.d.ts CHANGED
@@ -348,11 +348,6 @@ type InitOptions = {
348
348
  * of Onyx running in different tabs/windows. Defaults to true for platforms that support local storage (web/desktop)
349
349
  */
350
350
  shouldSyncMultipleInstances?: boolean;
351
- /**
352
- * If enabled it will use the performance API to measure the time taken by Onyx operations.
353
- * @default false
354
- */
355
- enablePerformanceMetrics?: boolean;
356
351
  /**
357
352
  * If enabled, it will connect to Redux DevTools Extension for debugging.
358
353
  * This allows you to see all Onyx state changes in the Redux DevTools.
package/dist/useOnyx.js CHANGED
@@ -41,9 +41,8 @@ const react_1 = require("react");
41
41
  const OnyxCache_1 = __importStar(require("./OnyxCache"));
42
42
  const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
43
43
  const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
44
- const GlobalSettings = __importStar(require("./GlobalSettings"));
44
+ const OnyxKeys_1 = __importDefault(require("./OnyxKeys"));
45
45
  const usePrevious_1 = __importDefault(require("./usePrevious"));
46
- const metrics_1 = __importDefault(require("./metrics"));
47
46
  const OnyxSnapshotCache_1 = __importDefault(require("./OnyxSnapshotCache"));
48
47
  const useLiveRef_1 = __importDefault(require("./useLiveRef"));
49
48
  function useOnyx(key, options, dependencies = []) {
@@ -251,7 +250,7 @@ function useOnyx(key, options, dependencies = []) {
251
250
  onStoreChange();
252
251
  },
253
252
  initWithStoredValues: options === null || options === void 0 ? void 0 : options.initWithStoredValues,
254
- waitForCollectionCallback: OnyxUtils_1.default.isCollectionKey(key),
253
+ waitForCollectionCallback: OnyxKeys_1.default.isCollectionKey(key),
255
254
  reuseConnection: options === null || options === void 0 ? void 0 : options.reuseConnection,
256
255
  });
257
256
  checkEvictableKey();
@@ -265,16 +264,10 @@ function useOnyx(key, options, dependencies = []) {
265
264
  onStoreChangeFnRef.current = null;
266
265
  };
267
266
  }, [key, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.reuseConnection, checkEvictableKey]);
268
- const getSnapshotDecorated = (0, react_1.useMemo)(() => {
269
- if (!GlobalSettings.isPerformanceMetricsEnabled()) {
270
- return getSnapshot;
271
- }
272
- return (0, metrics_1.default)(getSnapshot, 'useOnyx.getSnapshot');
273
- }, [getSnapshot]);
274
267
  (0, react_1.useEffect)(() => {
275
268
  checkEvictableKey();
276
269
  }, [checkEvictableKey]);
277
- const result = (0, react_1.useSyncExternalStore)(subscribe, getSnapshotDecorated);
270
+ const result = (0, react_1.useSyncExternalStore)(subscribe, getSnapshot);
278
271
  return result;
279
272
  }
280
273
  exports.default = useOnyx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.53",
3
+ "version": "3.0.55",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -93,7 +93,6 @@
93
93
  "react-native-device-info": "^10.3.0",
94
94
  "react-native-nitro-modules": "^0.27.2",
95
95
  "react-native-nitro-sqlite": "^9.2.0",
96
- "react-native-performance": "^5.1.0",
97
96
  "react-test-renderer": "18.2.0",
98
97
  "reassure": "1.4.0",
99
98
  "ts-node": "^10.9.2",
@@ -106,16 +105,12 @@
106
105
  "react-native": ">=0.75.0",
107
106
  "react-native-device-info": "^10.3.0",
108
107
  "react-native-nitro-modules": ">=0.27.2",
109
- "react-native-nitro-sqlite": "^9.2.0",
110
- "react-native-performance": ">=5.1.0"
108
+ "react-native-nitro-sqlite": "^9.2.0"
111
109
  },
112
110
  "peerDependenciesMeta": {
113
111
  "idb-keyval": {
114
112
  "optional": true
115
113
  },
116
- "react-native-performance": {
117
- "optional": true
118
- },
119
114
  "react-native-nitro-modules": {
120
115
  "optional": true
121
116
  },
@@ -1,11 +0,0 @@
1
- /**
2
- * Stores settings from Onyx.init globally so they can be made accessible by other parts of the library.
3
- */
4
- declare const globalSettings: {
5
- enablePerformanceMetrics: boolean;
6
- };
7
- type GlobalSettings = typeof globalSettings;
8
- declare function addGlobalSettingsChangeListener(listener: (settings: GlobalSettings) => unknown): () => void;
9
- declare function setPerformanceMetricsEnabled(enabled: boolean): void;
10
- declare function isPerformanceMetricsEnabled(): boolean;
11
- export { setPerformanceMetricsEnabled, isPerformanceMetricsEnabled, addGlobalSettingsChangeListener };