react-native-onyx 2.0.104 → 2.0.105

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/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import type { Connection } from './OnyxConnectionManager';
6
6
  import useOnyx from './useOnyx';
7
7
  import withOnyx from './withOnyx';
8
8
  import type { WithOnyxState } from './withOnyx/types';
9
+ import type { OnyxSQLiteKeyValuePair } from './storage/providers/SQLiteProvider';
9
10
  export default Onyx;
10
11
  export { useOnyx, withOnyx };
11
- export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, WithOnyxState, Connection, UseOnyxOptions, };
12
+ export type { ConnectOptions, CustomTypeOptions, FetchStatus, KeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, ResultMetadata, Selector, UseOnyxResult, WithOnyxState, Connection, UseOnyxOptions, OnyxSQLiteKeyValuePair, };
@@ -3,13 +3,13 @@ declare const StorageMock: {
3
3
  init: jest.Mock<void, []>;
4
4
  getItem: jest.Mock<Promise<unknown>, [key: any]>;
5
5
  multiGet: jest.Mock<Promise<import("../providers/types").KeyValuePairList>, [keys: import("../providers/types").KeyList]>;
6
- setItem: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, [key: any, value: unknown]>;
7
- multiSet: jest.Mock<Promise<void | import("react-native-quick-sqlite").BatchQueryResult>, [pairs: import("../providers/types").KeyValuePairList]>;
8
- mergeItem: jest.Mock<Promise<void | import("react-native-quick-sqlite").BatchQueryResult>, [key: any, deltaChanges: unknown, preMergedValue: unknown, shouldSetValue?: boolean | undefined]>;
9
- multiMerge: jest.Mock<Promise<void | import("react-native-quick-sqlite").BatchQueryResult | IDBValidKey[]>, [pairs: import("../providers/types").KeyValuePairList]>;
10
- removeItem: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, [key: string]>;
11
- removeItems: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, [keys: import("../providers/types").KeyList]>;
12
- clear: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, []>;
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
13
  getAllKeys: jest.Mock<Promise<import("../providers/types").KeyList>, []>;
14
14
  getDatabaseSize: jest.Mock<Promise<{
15
15
  bytesUsed: number;
@@ -1,3 +1,13 @@
1
1
  import type StorageProvider from './types';
2
+ /**
3
+ * The type of the key-value pair stored in the SQLite database
4
+ * @property record_key - the key of the record
5
+ * @property valueJSON - the value of the record in JSON string format
6
+ */
7
+ type OnyxSQLiteKeyValuePair = {
8
+ record_key: string;
9
+ valueJSON: string;
10
+ };
2
11
  declare const provider: StorageProvider;
3
12
  export default provider;
13
+ export type { OnyxSQLiteKeyValuePair };
@@ -3,9 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_native_quick_sqlite_1 = require("react-native-quick-sqlite");
6
+ const react_native_nitro_sqlite_1 = require("react-native-nitro-sqlite");
7
7
  const react_native_device_info_1 = require("react-native-device-info");
8
8
  const utils_1 = __importDefault(require("../../utils"));
9
+ // By default, NitroSQLite does not accept nullish values due to current limitations in Nitro Modules.
10
+ // This flag enables a feature in NitroSQLite that allows for nullish values to be passed to operations, such as "execute" or "executeBatch".
11
+ // Simple null handling can potentially add a minor performance overhead,
12
+ // since parameters and results from SQLite queries need to be parsed from and to JavaScript nullish values.
13
+ // https://github.com/margelo/react-native-nitro-sqlite#sending-and-receiving-nullish-values
14
+ (0, react_native_nitro_sqlite_1.enableSimpleNullHandling)();
9
15
  const DB_NAME = 'OnyxDB';
10
16
  let db;
11
17
  const provider = {
@@ -17,7 +23,7 @@ const provider = {
17
23
  * Initializes the storage provider
18
24
  */
19
25
  init() {
20
- db = (0, react_native_quick_sqlite_1.open)({ name: DB_NAME });
26
+ db = (0, react_native_nitro_sqlite_1.open)({ name: DB_NAME });
21
27
  db.execute('CREATE TABLE IF NOT EXISTS keyvaluepairs (record_key TEXT NOT NULL PRIMARY KEY , valueJSON JSON NOT NULL) WITHOUT ROWID;');
22
28
  // All of the 3 pragmas below were suggested by SQLite team.
23
29
  // You can find more info about them here: https://www.sqlite.org/pragma.html
@@ -31,6 +37,9 @@ const provider = {
31
37
  return null;
32
38
  }
33
39
  const result = rows === null || rows === void 0 ? void 0 : rows.item(0);
40
+ if (result == null) {
41
+ return null;
42
+ }
34
43
  return JSON.parse(result.valueJSON);
35
44
  });
36
45
  },
@@ -47,11 +56,12 @@ const provider = {
47
56
  return db.executeAsync('REPLACE INTO keyvaluepairs (record_key, valueJSON) VALUES (?, ?);', [key, JSON.stringify(value)]);
48
57
  },
49
58
  multiSet(pairs) {
50
- const stringifiedPairs = pairs.map((pair) => [pair[0], JSON.stringify(pair[1] === undefined ? null : pair[1])]);
51
- if (utils_1.default.isEmptyObject(stringifiedPairs)) {
59
+ const query = 'REPLACE INTO keyvaluepairs (record_key, valueJSON) VALUES (?, json(?));';
60
+ const params = pairs.map((pair) => [pair[0], JSON.stringify(pair[1] === undefined ? null : pair[1])]);
61
+ if (utils_1.default.isEmptyObject(params)) {
52
62
  return Promise.resolve();
53
63
  }
54
- return db.executeBatchAsync([['REPLACE INTO keyvaluepairs (record_key, valueJSON) VALUES (?, json(?));', stringifiedPairs]]);
64
+ return db.executeBatchAsync([{ query, params }]);
55
65
  },
56
66
  multiMerge(pairs) {
57
67
  // Note: We use `ON CONFLICT DO UPDATE` here instead of `INSERT OR REPLACE INTO`
@@ -61,12 +71,12 @@ const provider = {
61
71
  ON CONFLICT DO UPDATE
62
72
  SET valueJSON = JSON_PATCH(valueJSON, JSON(:value));
63
73
  `;
64
- const nonNullishPairs = pairs.filter((pair) => pair[1] !== undefined);
65
- const queryArguments = nonNullishPairs.map((pair) => {
74
+ const nonUndefinedPairs = pairs.filter((pair) => pair[1] !== undefined);
75
+ const params = nonUndefinedPairs.map((pair) => {
66
76
  const value = JSON.stringify(pair[1]);
67
77
  return [pair[0], value];
68
78
  });
69
- return db.executeBatchAsync([[query, queryArguments]]);
79
+ return db.executeBatchAsync([{ query, params }]);
70
80
  },
71
81
  mergeItem(key, deltaChanges, preMergedValue, shouldSetValue) {
72
82
  if (shouldSetValue) {
@@ -88,9 +98,9 @@ const provider = {
88
98
  clear: () => db.executeAsync('DELETE FROM keyvaluepairs;', []),
89
99
  getDatabaseSize() {
90
100
  return Promise.all([db.executeAsync('PRAGMA page_size;'), db.executeAsync('PRAGMA page_count;'), (0, react_native_device_info_1.getFreeDiskStorage)()]).then(([pageSizeResult, pageCountResult, bytesRemaining]) => {
91
- var _a, _b;
92
- const pageSize = (_a = pageSizeResult.rows) === null || _a === void 0 ? void 0 : _a.item(0).page_size;
93
- const pageCount = (_b = pageCountResult.rows) === null || _b === void 0 ? void 0 : _b.item(0).page_count;
101
+ var _a, _b, _c, _d, _e, _f;
102
+ const pageSize = (_c = (_b = (_a = pageSizeResult.rows) === null || _a === void 0 ? void 0 : _a.item(0)) === null || _b === void 0 ? void 0 : _b.page_size) !== null && _c !== void 0 ? _c : 0;
103
+ const pageCount = (_f = (_e = (_d = pageCountResult.rows) === null || _d === void 0 ? void 0 : _d.item(0)) === null || _e === void 0 ? void 0 : _e.page_count) !== null && _f !== void 0 ? _f : 0;
94
104
  return {
95
105
  bytesUsed: pageSize * pageCount,
96
106
  bytesRemaining,
@@ -1,4 +1,4 @@
1
- import type { BatchQueryResult, QueryResult } from 'react-native-quick-sqlite';
1
+ import type { BatchQueryResult, QueryResult } from 'react-native-nitro-sqlite';
2
2
  import type { OnyxKey, OnyxValue } from '../../types';
3
3
  type KeyValuePair = [OnyxKey, OnyxValue<OnyxKey>];
4
4
  type KeyList = OnyxKey[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.104",
3
+ "version": "2.0.105",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -28,6 +28,7 @@
28
28
  "main": "dist/index.js",
29
29
  "types": "dist/index.d.ts",
30
30
  "scripts": {
31
+ "prepare": "npm run build",
31
32
  "lint": "eslint .",
32
33
  "typecheck": "tsc --noEmit",
33
34
  "test": "jest",
@@ -86,10 +87,11 @@
86
87
  "prop-types": "^15.7.2",
87
88
  "react": "18.2.0",
88
89
  "react-dom": "^18.2.0",
89
- "react-native": "0.71.2",
90
+ "react-native": "0.76.3",
90
91
  "react-native-device-info": "^10.3.0",
92
+ "react-native-nitro-modules": "^0.24.1",
93
+ "react-native-nitro-sqlite": "^9.1.8",
91
94
  "react-native-performance": "^2.0.0",
92
- "react-native-quick-sqlite": "^8.0.6",
93
95
  "react-test-renderer": "18.1.0",
94
96
  "reassure": "1.4.0",
95
97
  "ts-node": "^10.9.2",
@@ -99,10 +101,12 @@
99
101
  "peerDependencies": {
100
102
  "idb-keyval": "^6.2.1",
101
103
  "react": ">=18.1.0",
104
+ "react-native": ">=0.75.0",
102
105
  "react-dom": ">=18.1.0",
103
106
  "react-native-device-info": "^10.3.0",
104
- "react-native-performance": "^5.1.0",
105
- "react-native-quick-sqlite": "^8.0.0-beta.2"
107
+ "react-native-nitro-modules": ">=0.24.1",
108
+ "react-native-nitro-sqlite": "^9.1.4",
109
+ "react-native-performance": "^5.1.0"
106
110
  },
107
111
  "peerDependenciesMeta": {
108
112
  "idb-keyval": {
@@ -111,7 +115,10 @@
111
115
  "react-native-performance": {
112
116
  "optional": true
113
117
  },
114
- "react-native-quick-sqlite": {
118
+ "react-native-nitro-modules": {
119
+ "optional": true
120
+ },
121
+ "react-native-nitro-sqlite": {
115
122
  "optional": true
116
123
  },
117
124
  "react-native-device-info": {