react-native-onyx 2.0.108 → 2.0.110

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.
@@ -1,25 +1,25 @@
1
1
  /// <reference types="jest" />
2
2
  declare const StorageMock: {
3
- init: jest.Mock<void, []>;
4
- getItem: jest.Mock<Promise<unknown>, [key: any]>;
5
- multiGet: jest.Mock<Promise<import("../providers/types").KeyValuePairList>, [keys: import("../providers/types").KeyList]>;
6
- setItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [key: any, value: unknown]>;
7
- multiSet: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult>, [pairs: import("../providers/types").KeyValuePairList]>;
8
- mergeItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult>, [key: any, deltaChanges: unknown, preMergedValue: unknown, shouldSetValue?: boolean | undefined]>;
9
- multiMerge: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult | IDBValidKey[]>, [pairs: import("../providers/types").KeyValuePairList]>;
10
- removeItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [key: string]>;
11
- removeItems: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [keys: import("../providers/types").KeyList]>;
12
- clear: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, []>;
13
- getAllKeys: jest.Mock<Promise<import("../providers/types").KeyList>, []>;
3
+ init: jest.Mock<void, [], any>;
4
+ getItem: jest.Mock<Promise<unknown>, [key: any], any>;
5
+ multiGet: jest.Mock<Promise<import("../providers/types").KeyValuePairList>, [keys: import("../providers/types").KeyList], any>;
6
+ setItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [key: any, value: unknown], any>;
7
+ multiSet: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult>, [pairs: import("../providers/types").KeyValuePairList], any>;
8
+ mergeItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult>, [key: any, deltaChanges: unknown, preMergedValue: unknown, shouldSetValue?: boolean | undefined], any>;
9
+ multiMerge: jest.Mock<Promise<void | import("react-native-nitro-sqlite").BatchQueryResult | IDBValidKey[]>, [pairs: import("../providers/types").KeyValuePairList], any>;
10
+ removeItem: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [key: string], any>;
11
+ removeItems: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [keys: import("../providers/types").KeyList], any>;
12
+ clear: jest.Mock<Promise<void | import("react-native-nitro-sqlite").QueryResult<import("react-native-nitro-sqlite").QueryResultRow>>, [], any>;
13
+ getAllKeys: jest.Mock<Promise<import("../providers/types").KeyList>, [], any>;
14
14
  getDatabaseSize: jest.Mock<Promise<{
15
15
  bytesUsed: number;
16
16
  bytesRemaining: number;
17
- }>, []>;
18
- keepInstancesSync: jest.Mock<any, any>;
17
+ }>, [], any>;
18
+ keepInstancesSync: jest.Mock<any, any, any>;
19
19
  mockSet: (key: string, value: unknown) => Promise<unknown>;
20
20
  getMockStore: jest.Mock<{
21
21
  [x: string]: unknown;
22
- }, []>;
23
- setMockStore: jest.Mock<void, [data: any]>;
22
+ }, [], any>;
23
+ setMockStore: jest.Mock<void, [data: any], any>;
24
24
  };
25
25
  export default StorageMock;
package/dist/useOnyx.js CHANGED
@@ -36,29 +36,6 @@ const useLiveRef_1 = __importDefault(require("./useLiveRef"));
36
36
  const usePrevious_1 = __importDefault(require("./usePrevious"));
37
37
  const metrics_1 = __importDefault(require("./metrics"));
38
38
  const Logger = __importStar(require("./Logger"));
39
- /**
40
- * Gets the cached value from the Onyx cache. If the key is a collection key, it will return all the values in the collection.
41
- * It is a fork of `tryGetCachedValue` from `OnyxUtils` caused by different selector logic in `useOnyx`. It should be unified in the future, when `withOnyx` is removed.
42
- */
43
- function tryGetCachedValue(key) {
44
- if (!OnyxUtils_1.default.isCollectionKey(key)) {
45
- return OnyxCache_1.default.get(key);
46
- }
47
- const allCacheKeys = OnyxCache_1.default.getAllKeys();
48
- // It is possible we haven't loaded all keys yet so we do not know if the
49
- // collection actually exists.
50
- if (allCacheKeys.size === 0) {
51
- return;
52
- }
53
- const values = {};
54
- allCacheKeys.forEach((cacheKey) => {
55
- if (!cacheKey.startsWith(key)) {
56
- return;
57
- }
58
- values[cacheKey] = OnyxCache_1.default.get(cacheKey);
59
- });
60
- return values;
61
- }
62
39
  function useOnyx(key, options, dependencies = []) {
63
40
  const connectionRef = (0, react_1.useRef)(null);
64
41
  const previousKey = (0, usePrevious_1.default)(key);
@@ -146,7 +123,7 @@ function useOnyx(key, options, dependencies = []) {
146
123
  // update `newValueRef` when `Onyx.connect()` callback is fired.
147
124
  if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) {
148
125
  // Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.
149
- const value = tryGetCachedValue(key);
126
+ const value = OnyxUtils_1.default.tryGetCachedValue(key);
150
127
  const selectedValue = selectorRef.current ? selectorRef.current(value) : value;
151
128
  newValueRef.current = (selectedValue !== null && selectedValue !== void 0 ? selectedValue : undefined);
152
129
  // This flag is `false` when the original Onyx value (without selector) is not defined yet.
@@ -204,7 +181,7 @@ function useOnyx(key, options, dependencies = []) {
204
181
  // we log an alert so it can be acknowledged by the consumer. Additionally, we won't log alerts
205
182
  // if there's a `Onyx.clear()` task in progress.
206
183
  if ((options === null || options === void 0 ? void 0 : options.canBeMissing) === false && newStatus === 'loaded' && !isOnyxValueDefined && !OnyxCache_1.default.hasPendingTask(OnyxCache_1.TASK.CLEAR)) {
207
- Logger.logAlert(`useOnyx returned no data for key with canBeMissing set to false.`, { key, showAlert: true });
184
+ Logger.logAlert(`useOnyx returned no data for key with canBeMissing set to false for key ${key}`, { showAlert: true });
208
185
  }
209
186
  }
210
187
  return resultRef.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.108",
3
+ "version": "2.0.110",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -54,12 +54,12 @@
54
54
  "@actions/core": "^1.10.1",
55
55
  "@jest/globals": "^29.7.0",
56
56
  "@lwc/eslint-plugin-lwc": "^1.7.2",
57
- "@ngneat/falso": "^7.2.0",
57
+ "@ngneat/falso": "^7.3.0",
58
58
  "@react-native-community/eslint-config": "^3.2.0",
59
+ "@react-native/babel-preset": "0.76.3",
59
60
  "@react-native/polyfills": "^2.0.0",
60
- "@testing-library/jest-native": "^3.4.2",
61
- "@testing-library/react-native": "^10.0.0",
62
- "@types/jest": "^28.1.8",
61
+ "@testing-library/react-native": "^13.2.0",
62
+ "@types/jest": "^29.5.14",
63
63
  "@types/jsdoc-to-markdown": "^7.0.6",
64
64
  "@types/lodash": "^4.14.202",
65
65
  "@types/node": "^20.11.5",
@@ -78,21 +78,21 @@
78
78
  "eslint-plugin-jsx-a11y": "^6.8.0",
79
79
  "eslint-plugin-react": "^7.31.10",
80
80
  "idb-keyval": "^6.2.1",
81
- "jest": "^26.5.2",
82
- "jest-cli": "^26.5.2",
81
+ "jest": "^29.7.0",
82
+ "jest-cli": "^29.7.0",
83
+ "jest-environment-jsdom": "^29.7.0",
83
84
  "jsdoc-to-markdown": "^7.1.0",
84
- "metro-react-native-babel-preset": "^0.77.0",
85
85
  "nodemon": "^3.0.3",
86
86
  "prettier": "^2.8.8",
87
87
  "prop-types": "^15.7.2",
88
88
  "react": "18.2.0",
89
- "react-dom": "^18.2.0",
89
+ "react-dom": "18.2.0",
90
90
  "react-native": "0.76.3",
91
91
  "react-native-device-info": "^10.3.0",
92
92
  "react-native-nitro-modules": "^0.24.1",
93
93
  "react-native-nitro-sqlite": "^9.1.8",
94
94
  "react-native-performance": "^2.0.0",
95
- "react-test-renderer": "18.1.0",
95
+ "react-test-renderer": "18.2.0",
96
96
  "reassure": "1.4.0",
97
97
  "ts-node": "^10.9.2",
98
98
  "type-fest": "^3.12.0",
@@ -101,8 +101,8 @@
101
101
  "peerDependencies": {
102
102
  "idb-keyval": "^6.2.1",
103
103
  "react": ">=18.1.0",
104
- "react-native": ">=0.75.0",
105
104
  "react-dom": ">=18.1.0",
105
+ "react-native": ">=0.75.0",
106
106
  "react-native-device-info": "^10.3.0",
107
107
  "react-native-nitro-modules": ">=0.24.1",
108
108
  "react-native-nitro-sqlite": "^9.1.4",