react-native-onyx 2.0.14 → 2.0.16

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/Onyx.js CHANGED
@@ -1436,14 +1436,6 @@ function setMemoryOnlyKeys(keyList) {
1436
1436
  * });
1437
1437
  */
1438
1438
  function init({ keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = Boolean(global.localStorage), debugSetState = false } = {}) {
1439
- storage_1.default.init();
1440
- if (shouldSyncMultipleInstances) {
1441
- storage_1.default.keepInstancesSync((key, value) => {
1442
- const prevValue = OnyxCache_1.default.getValue(key, false);
1443
- OnyxCache_1.default.set(key, value);
1444
- keyChanged(key, value, prevValue);
1445
- });
1446
- }
1447
1439
  if (debugSetState) {
1448
1440
  PerformanceUtils.setShouldDebugSetState(true);
1449
1441
  }
@@ -1464,6 +1456,13 @@ function init({ keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCach
1464
1456
  evictionAllowList = safeEvictionKeys;
1465
1457
  // Initialize all of our keys with data provided then give green light to any pending connections
1466
1458
  Promise.all([addAllSafeEvictionKeysToRecentlyAccessedList(), initializeWithDefaultKeyStates()]).then(deferredInitTask.resolve);
1459
+ if (shouldSyncMultipleInstances && underscore_1.default.isFunction(storage_1.default.keepInstancesSync)) {
1460
+ storage_1.default.keepInstancesSync((key, value) => {
1461
+ const prevValue = OnyxCache_1.default.getValue(key, false);
1462
+ OnyxCache_1.default.set(key, value);
1463
+ keyChanged(key, value, prevValue);
1464
+ });
1465
+ }
1467
1466
  }
1468
1467
  const Onyx = {
1469
1468
  connect,
@@ -0,0 +1,2 @@
1
+ import SQLiteStorage from './providers/SQLiteStorage';
2
+ export default SQLiteStorage;
@@ -3,5 +3,5 @@ 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 IDBKeyValProvider_1 = __importDefault(require("../providers/IDBKeyValProvider"));
7
- exports.default = IDBKeyValProvider_1.default;
6
+ const SQLiteStorage_1 = __importDefault(require("./providers/SQLiteStorage"));
7
+ exports.default = SQLiteStorage_1.default;
@@ -0,0 +1,3 @@
1
+ import type StorageProvider from './providers/types';
2
+ declare const webStorage: StorageProvider;
3
+ export default webStorage;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * This file is here to wrap IDBKeyVal with a layer that provides data-changed events like the ones that exist
8
+ * when using LocalStorage APIs in the browser. These events are great because multiple tabs can listen for when
9
+ * data changes and then stay up-to-date with everything happening in Onyx.
10
+ */
11
+ const IDBKeyVal_1 = __importDefault(require("./providers/IDBKeyVal"));
12
+ const SYNC_ONYX = 'SYNC_ONYX';
13
+ /**
14
+ * Raise an event thorough `localStorage` to let other tabs know a value changed
15
+ */
16
+ function raiseStorageSyncEvent(onyxKey) {
17
+ global.localStorage.setItem(SYNC_ONYX, onyxKey);
18
+ global.localStorage.removeItem(SYNC_ONYX);
19
+ }
20
+ function raiseStorageSyncManyKeysEvent(onyxKeys) {
21
+ onyxKeys.forEach((onyxKey) => {
22
+ raiseStorageSyncEvent(onyxKey);
23
+ });
24
+ }
25
+ const webStorage = Object.assign(Object.assign({}, IDBKeyVal_1.default), {
26
+ /**
27
+ * @param onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
28
+ */
29
+ keepInstancesSync(onStorageKeyChanged) {
30
+ // Override set, remove and clear to raise storage events that we intercept in other tabs
31
+ this.setItem = (key, value) => IDBKeyVal_1.default.setItem(key, value).then(() => raiseStorageSyncEvent(key));
32
+ this.removeItem = (key) => IDBKeyVal_1.default.removeItem(key).then(() => raiseStorageSyncEvent(key));
33
+ this.removeItems = (keys) => IDBKeyVal_1.default.removeItems(keys).then(() => raiseStorageSyncManyKeysEvent(keys));
34
+ this.mergeItem = (key, batchedChanges, modifiedData) => IDBKeyVal_1.default.mergeItem(key, batchedChanges, modifiedData).then(() => raiseStorageSyncEvent(key));
35
+ // If we just call Storage.clear other tabs will have no idea which keys were available previously
36
+ // so that they can call keysChanged for them. That's why we iterate over every key and raise a storage sync
37
+ // event for each one
38
+ this.clear = () => {
39
+ let allKeys;
40
+ // The keys must be retrieved before storage is cleared or else the list of keys would be empty
41
+ return IDBKeyVal_1.default.getAllKeys()
42
+ .then((keys) => {
43
+ allKeys = keys;
44
+ })
45
+ .then(() => IDBKeyVal_1.default.clear())
46
+ .then(() => {
47
+ // Now that storage is cleared, the storage sync event can happen which is a more atomic action
48
+ // for other browser tabs
49
+ allKeys.forEach(raiseStorageSyncEvent);
50
+ });
51
+ };
52
+ // This listener will only be triggered by events coming from other tabs
53
+ global.addEventListener('storage', (event) => {
54
+ // Ignore events that don't originate from the SYNC_ONYX logic
55
+ if (event.key !== SYNC_ONYX || !event.newValue) {
56
+ return;
57
+ }
58
+ const onyxKey = event.newValue;
59
+ IDBKeyVal_1.default.getItem(onyxKey).then((value) => onStorageKeyChanged(onyxKey, value));
60
+ });
61
+ } });
62
+ exports.default = webStorage;
@@ -2,7 +2,6 @@
2
2
  import type { KeyValuePairList } from '../providers/types';
3
3
  declare const idbKeyvalMockSpy: {
4
4
  idbKeyvalSet: jest.Mock<Promise<any>, [key: any, value: any]>;
5
- init: jest.Mock<void, []>;
6
5
  setItem: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, [key: string, value: IDBValidKey]>;
7
6
  getItem: jest.Mock<Promise<IDBValidKey | null>, [key: string]>;
8
7
  removeItem: jest.Mock<Promise<void | import("react-native-quick-sqlite").QueryResult>, [key: string]>;
@@ -20,6 +19,5 @@ declare const idbKeyvalMockSpy: {
20
19
  bytesRemaining: number;
21
20
  }>, []>;
22
21
  setMemoryOnlyKeys: jest.Mock<void, []>;
23
- keepInstancesSync: jest.Mock<void, [onStorageKeyChanged: import("../providers/types").OnStorageKeyChanged]>;
24
22
  };
25
23
  export default idbKeyvalMockSpy;
@@ -10,8 +10,6 @@ const set = jest.fn((key, value) => {
10
10
  return Promise.resolve(value);
11
11
  });
12
12
  const idbKeyvalMock = {
13
- name: 'KeyValMockProvider',
14
- init: () => undefined,
15
13
  setItem(key, value) {
16
14
  return set(key, value);
17
15
  },
@@ -60,11 +58,9 @@ const idbKeyvalMock = {
60
58
  },
61
59
  // eslint-disable-next-line @typescript-eslint/no-empty-function
62
60
  setMemoryOnlyKeys() { },
63
- keepInstancesSync: () => undefined,
64
61
  };
65
62
  const idbKeyvalMockSpy = {
66
63
  idbKeyvalSet: set,
67
- init: jest.fn(idbKeyvalMock.init),
68
64
  setItem: jest.fn(idbKeyvalMock.setItem),
69
65
  getItem: jest.fn(idbKeyvalMock.getItem),
70
66
  removeItem: jest.fn(idbKeyvalMock.removeItem),
@@ -81,6 +77,5 @@ const idbKeyvalMockSpy = {
81
77
  }),
82
78
  getDatabaseSize: jest.fn(idbKeyvalMock.getDatabaseSize),
83
79
  setMemoryOnlyKeys: jest.fn(idbKeyvalMock.setMemoryOnlyKeys),
84
- keepInstancesSync: jest.fn(idbKeyvalMock.keepInstancesSync),
85
80
  };
86
81
  exports.default = idbKeyvalMockSpy;
@@ -1,6 +1,2 @@
1
- import type StorageProvider from './providers/types';
2
- type Storage = {
3
- getStorageProvider: () => StorageProvider;
4
- } & Omit<StorageProvider, 'name'>;
5
- declare const Storage: Storage;
6
- export default Storage;
1
+ import WebStorage from './WebStorage';
2
+ export default WebStorage;
@@ -1,172 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const Logger = __importStar(require("../Logger"));
30
- const platforms_1 = __importDefault(require("./platforms"));
31
- const InstanceSync_1 = __importDefault(require("./InstanceSync"));
32
- const NoopProvider_1 = __importDefault(require("./providers/NoopProvider"));
33
- let provider = platforms_1.default;
34
- let shouldKeepInstancesSync = false;
35
- let finishInitalization;
36
- const initPromise = new Promise((resolve) => {
37
- finishInitalization = resolve;
38
- });
39
- /**
40
- * Degrade performance by removing the storage provider and only using cache
41
- */
42
- function degradePerformance(error) {
43
- Logger.logAlert(`Error while using ${provider.name}. Falling back to only using cache and dropping storage.`);
44
- console.error(error);
45
- provider = NoopProvider_1.default;
46
- }
47
- /**
48
- * Runs a piece of code and degrades performance if certain errors are thrown
49
- */
50
- function tryOrDegradePerformance(fn) {
51
- return new Promise((resolve, reject) => {
52
- initPromise.then(() => {
53
- try {
54
- resolve(fn());
55
- }
56
- catch (error) {
57
- // Test for known critical errors that the storage provider throws, e.g. when storage is full
58
- if (error instanceof Error) {
59
- // IndexedDB error when storage is full (https://github.com/Expensify/App/issues/29403)
60
- if (error.message.includes('Internal error opening backing store for indexedDB.open')) {
61
- degradePerformance(error);
62
- }
63
- }
64
- reject(error);
65
- }
66
- });
67
- });
68
- }
69
- const Storage = {
70
- /**
71
- * Returns the storage provider currently in use
72
- */
73
- getStorageProvider() {
74
- return provider;
75
- },
76
- /**
77
- * Initializes all providers in the list of storage providers
78
- * and enables fallback providers if necessary
79
- */
80
- init() {
81
- tryOrDegradePerformance(provider.init).finally(() => {
82
- finishInitalization();
83
- });
84
- },
85
- /**
86
- * Get the value of a given key or return `null` if it's not available
87
- */
88
- getItem: (key) => tryOrDegradePerformance(() => provider.getItem(key)),
89
- /**
90
- * Get multiple key-value pairs for the give array of keys in a batch
91
- */
92
- multiGet: (keys) => tryOrDegradePerformance(() => provider.multiGet(keys)),
93
- /**
94
- * Sets the value for a given key. The only requirement is that the value should be serializable to JSON string
95
- */
96
- setItem: (key, value) => tryOrDegradePerformance(() => {
97
- const promise = provider.setItem(key, value);
98
- if (shouldKeepInstancesSync) {
99
- return promise.then(() => InstanceSync_1.default.setItem(key));
100
- }
101
- return promise;
102
- }),
103
- /**
104
- * Stores multiple key-value pairs in a batch
105
- */
106
- multiSet: (pairs) => tryOrDegradePerformance(() => provider.multiSet(pairs)),
107
- /**
108
- * Merging an existing value with a new one
109
- */
110
- mergeItem: (key, changes, modifiedData) => tryOrDegradePerformance(() => {
111
- const promise = provider.mergeItem(key, changes, modifiedData);
112
- if (shouldKeepInstancesSync) {
113
- return promise.then(() => InstanceSync_1.default.mergeItem(key));
114
- }
115
- return promise;
116
- }),
117
- /**
118
- * Multiple merging of existing and new values in a batch
119
- * This function also removes all nested null values from an object.
120
- */
121
- multiMerge: (pairs) => tryOrDegradePerformance(() => provider.multiMerge(pairs)),
122
- /**
123
- * Removes given key and its value
124
- */
125
- removeItem: (key) => tryOrDegradePerformance(() => {
126
- const promise = provider.removeItem(key);
127
- if (shouldKeepInstancesSync) {
128
- return promise.then(() => InstanceSync_1.default.removeItem(key));
129
- }
130
- return promise;
131
- }),
132
- /**
133
- * Remove given keys and their values
134
- */
135
- removeItems: (keys) => tryOrDegradePerformance(() => {
136
- const promise = provider.removeItems(keys);
137
- if (shouldKeepInstancesSync) {
138
- return promise.then(() => InstanceSync_1.default.removeItems(keys));
139
- }
140
- return promise;
141
- }),
142
- /**
143
- * Clears everything
144
- */
145
- clear: () => tryOrDegradePerformance(() => {
146
- if (shouldKeepInstancesSync) {
147
- return InstanceSync_1.default.clear(() => provider.clear());
148
- }
149
- return provider.clear();
150
- }),
151
- // This is a noop for now in order to keep clients from crashing see https://github.com/Expensify/Expensify/issues/312438
152
- setMemoryOnlyKeys: () => tryOrDegradePerformance(() => provider.setMemoryOnlyKeys()),
153
- /**
154
- * Returns all available keys
155
- */
156
- getAllKeys: () => tryOrDegradePerformance(() => provider.getAllKeys()),
157
- /**
158
- * Gets the total bytes of the store
159
- */
160
- getDatabaseSize: () => tryOrDegradePerformance(() => provider.getDatabaseSize()),
161
- /**
162
- * @param onStorageKeyChanged - Storage synchronization mechanism keeping all opened tabs in sync (web only)
163
- */
164
- keepInstancesSync(onStorageKeyChanged) {
165
- // If InstanceSync is null, it means we're on a native platform and we don't need to keep instances in sync
166
- if (InstanceSync_1.default === null)
167
- return;
168
- shouldKeepInstancesSync = true;
169
- InstanceSync_1.default.init(onStorageKeyChanged);
170
- },
171
- };
172
- exports.default = Storage;
6
+ const WebStorage_1 = __importDefault(require("./WebStorage"));
7
+ exports.default = WebStorage_1.default;
@@ -0,0 +1,2 @@
1
+ import NativeStorage from './NativeStorage';
2
+ export default NativeStorage;
@@ -3,5 +3,5 @@ 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 SQLiteProvider_1 = __importDefault(require("../providers/SQLiteProvider"));
7
- exports.default = SQLiteProvider_1.default;
6
+ const NativeStorage_1 = __importDefault(require("./NativeStorage"));
7
+ exports.default = NativeStorage_1.default;
@@ -7,24 +7,17 @@ const idb_keyval_1 = require("idb-keyval");
7
7
  const utils_1 = __importDefault(require("../../utils"));
8
8
  // We don't want to initialize the store while the JS bundle loads as idb-keyval will try to use global.indexedDB
9
9
  // which might not be available in certain environments that load the bundle (e.g. electron main process).
10
- let idbKeyValStore;
10
+ let customStoreInstance;
11
+ function getCustomStore() {
12
+ if (!customStoreInstance) {
13
+ customStoreInstance = (0, idb_keyval_1.createStore)('OnyxDB', 'keyvaluepairs');
14
+ }
15
+ return customStoreInstance;
16
+ }
11
17
  const provider = {
12
- /**
13
- * The name of the provider that can be printed to the logs
14
- */
15
- name: 'IDBKeyValProvider',
16
- /**
17
- * Initializes the storage provider
18
- */
19
- init() {
20
- const newIdbKeyValStore = (0, idb_keyval_1.createStore)('OnyxDB', 'keyvaluepairs');
21
- if (newIdbKeyValStore == null)
22
- throw Error('IDBKeyVal store could not be created');
23
- idbKeyValStore = newIdbKeyValStore;
24
- },
25
- setItem: (key, value) => (0, idb_keyval_1.set)(key, value, idbKeyValStore),
26
- multiGet: (keysParam) => (0, idb_keyval_1.getMany)(keysParam, idbKeyValStore).then((values) => values.map((value, index) => [keysParam[index], value])),
27
- multiMerge: (pairs) => idbKeyValStore('readwrite', (store) => {
18
+ setItem: (key, value) => (0, idb_keyval_1.set)(key, value, getCustomStore()),
19
+ multiGet: (keysParam) => (0, idb_keyval_1.getMany)(keysParam, getCustomStore()).then((values) => values.map((value, index) => [keysParam[index], value])),
20
+ multiMerge: (pairs) => getCustomStore()('readwrite', (store) => {
28
21
  // Note: we are using the manual store transaction here, to fit the read and update
29
22
  // of the items in one transaction to achieve best performance.
30
23
  const getValues = Promise.all(pairs.map(([key]) => (0, idb_keyval_1.promisifyRequest)(store.get(key))));
@@ -42,16 +35,16 @@ const provider = {
42
35
  // Since Onyx also merged the existing value with the changes, we can just set the value directly
43
36
  return provider.setItem(key, modifiedData);
44
37
  },
45
- multiSet: (pairs) => (0, idb_keyval_1.setMany)(pairs, idbKeyValStore),
46
- clear: () => (0, idb_keyval_1.clear)(idbKeyValStore),
38
+ multiSet: (pairs) => (0, idb_keyval_1.setMany)(pairs, getCustomStore()),
39
+ clear: () => (0, idb_keyval_1.clear)(getCustomStore()),
47
40
  // eslint-disable-next-line @typescript-eslint/no-empty-function
48
41
  setMemoryOnlyKeys: () => { },
49
- getAllKeys: () => (0, idb_keyval_1.keys)(idbKeyValStore),
50
- getItem: (key) => (0, idb_keyval_1.get)(key, idbKeyValStore)
42
+ getAllKeys: () => (0, idb_keyval_1.keys)(getCustomStore()),
43
+ getItem: (key) => (0, idb_keyval_1.get)(key, getCustomStore())
51
44
  // idb-keyval returns undefined for missing items, but this needs to return null so that idb-keyval does the same thing as SQLiteStorage.
52
45
  .then((val) => (val === undefined ? null : val)),
53
- removeItem: (key) => (0, idb_keyval_1.del)(key, idbKeyValStore),
54
- removeItems: (keysParam) => (0, idb_keyval_1.delMany)(keysParam, idbKeyValStore),
46
+ removeItem: (key) => (0, idb_keyval_1.del)(key, getCustomStore()),
47
+ removeItems: (keysParam) => (0, idb_keyval_1.delMany)(keysParam, getCustomStore()),
55
48
  getDatabaseSize() {
56
49
  if (!window.navigator || !window.navigator.storage) {
57
50
  throw new Error('StorageManager browser API unavailable');
@@ -7,24 +7,14 @@ const react_native_quick_sqlite_1 = require("react-native-quick-sqlite");
7
7
  const react_native_device_info_1 = require("react-native-device-info");
8
8
  const utils_1 = __importDefault(require("../../utils"));
9
9
  const DB_NAME = 'OnyxDB';
10
- let db;
10
+ const db = (0, react_native_quick_sqlite_1.open)({ name: DB_NAME });
11
+ db.execute('CREATE TABLE IF NOT EXISTS keyvaluepairs (record_key TEXT NOT NULL PRIMARY KEY , valueJSON JSON NOT NULL) WITHOUT ROWID;');
12
+ // All of the 3 pragmas below were suggested by SQLite team.
13
+ // You can find more info about them here: https://www.sqlite.org/pragma.html
14
+ db.execute('PRAGMA CACHE_SIZE=-20000;');
15
+ db.execute('PRAGMA synchronous=NORMAL;');
16
+ db.execute('PRAGMA journal_mode=WAL;');
11
17
  const provider = {
12
- /**
13
- * The name of the provider that can be printed to the logs
14
- */
15
- name: 'SQLiteProvider',
16
- /**
17
- * Initializes the storage provider
18
- */
19
- init() {
20
- db = (0, react_native_quick_sqlite_1.open)({ name: DB_NAME });
21
- db.execute('CREATE TABLE IF NOT EXISTS keyvaluepairs (record_key TEXT NOT NULL PRIMARY KEY , valueJSON JSON NOT NULL) WITHOUT ROWID;');
22
- // All of the 3 pragmas below were suggested by SQLite team.
23
- // You can find more info about them here: https://www.sqlite.org/pragma.html
24
- db.execute('PRAGMA CACHE_SIZE=-20000;');
25
- db.execute('PRAGMA synchronous=NORMAL;');
26
- db.execute('PRAGMA journal_mode=WAL;');
27
- },
28
18
  getItem(key) {
29
19
  return db.executeAsync('SELECT record_key, valueJSON FROM keyvaluepairs WHERE record_key = ?;', [key]).then(({ rows }) => {
30
20
  if (!rows || (rows === null || rows === void 0 ? void 0 : rows.length) === 0) {
@@ -96,5 +86,7 @@ const provider = {
96
86
  },
97
87
  // eslint-disable-next-line @typescript-eslint/no-empty-function
98
88
  setMemoryOnlyKeys: () => { },
89
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
90
+ keepInstancesSync: () => { },
99
91
  };
100
92
  exports.default = provider;
@@ -6,14 +6,6 @@ type KeyList = Key[];
6
6
  type KeyValuePairList = KeyValuePair[];
7
7
  type OnStorageKeyChanged = (key: Key, value: Value | null) => void;
8
8
  type StorageProvider = {
9
- /**
10
- * The name of the provider that can be printed to the logs
11
- */
12
- name: string;
13
- /**
14
- * Initializes the storage provider
15
- */
16
- init: () => void;
17
9
  /**
18
10
  * Gets the value of a given key or return `null` if it's not available in storage
19
11
  */
@@ -73,4 +65,4 @@ type StorageProvider = {
73
65
  keepInstancesSync?: (onStorageKeyChanged: OnStorageKeyChanged) => void;
74
66
  };
75
67
  export default StorageProvider;
76
- export type { Value, Key, KeyList, KeyValuePair, KeyValuePairList, OnStorageKeyChanged };
68
+ export type { Value, Key, KeyList, KeyValuePairList };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -1,13 +0,0 @@
1
- /**
2
- * This is used to keep multiple browser tabs in sync, therefore only needed on web
3
- * On native platforms, we omit this syncing logic by setting this to mock implementation.
4
- */
5
- declare const InstanceSync: {
6
- init: (...args: any[]) => void;
7
- setItem: (...args: any[]) => void;
8
- removeItem: (...args: any[]) => void;
9
- removeItems: (...args: any[]) => void;
10
- mergeItem: (...args: any[]) => void;
11
- clear: <T extends () => void>(callback: T) => Promise<void>;
12
- };
13
- export default InstanceSync;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const noop_1 = __importDefault(require("lodash/noop"));
7
- /**
8
- * This is used to keep multiple browser tabs in sync, therefore only needed on web
9
- * On native platforms, we omit this syncing logic by setting this to mock implementation.
10
- */
11
- const InstanceSync = {
12
- init: noop_1.default,
13
- setItem: noop_1.default,
14
- removeItem: noop_1.default,
15
- removeItems: noop_1.default,
16
- mergeItem: noop_1.default,
17
- clear: (callback) => Promise.resolve(callback()),
18
- };
19
- exports.default = InstanceSync;
@@ -1,24 +0,0 @@
1
- /**
2
- * The InstancesSync object provides data-changed events like the ones that exist
3
- * when using LocalStorage APIs in the browser. These events are great because multiple tabs can listen for when
4
- * data changes and then stay up-to-date with everything happening in Onyx.
5
- */
6
- import type { KeyList, Key, OnStorageKeyChanged } from '../providers/types';
7
- /**
8
- * Raise an event through `localStorage` to let other tabs know a value changed
9
- * @param {String} onyxKey
10
- */
11
- declare function raiseStorageSyncEvent(onyxKey: Key): void;
12
- declare function raiseStorageSyncManyKeysEvent(onyxKeys: KeyList): void;
13
- declare const InstanceSync: {
14
- /**
15
- * @param {Function} onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
16
- */
17
- init: (onStorageKeyChanged: OnStorageKeyChanged) => void;
18
- setItem: typeof raiseStorageSyncEvent;
19
- removeItem: typeof raiseStorageSyncEvent;
20
- removeItems: typeof raiseStorageSyncManyKeysEvent;
21
- mergeItem: typeof raiseStorageSyncEvent;
22
- clear: (clearImplementation: () => void) => any;
23
- };
24
- export default InstanceSync;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const SYNC_ONYX = 'SYNC_ONYX';
4
- /**
5
- * Raise an event through `localStorage` to let other tabs know a value changed
6
- * @param {String} onyxKey
7
- */
8
- function raiseStorageSyncEvent(onyxKey) {
9
- global.localStorage.setItem(SYNC_ONYX, onyxKey);
10
- global.localStorage.removeItem(SYNC_ONYX);
11
- }
12
- function raiseStorageSyncManyKeysEvent(onyxKeys) {
13
- onyxKeys.forEach((onyxKey) => {
14
- raiseStorageSyncEvent(onyxKey);
15
- });
16
- }
17
- const InstanceSync = {
18
- /**
19
- * @param {Function} onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
20
- */
21
- init: (onStorageKeyChanged) => {
22
- // This listener will only be triggered by events coming from other tabs
23
- global.addEventListener('storage', (event) => {
24
- // Ignore events that don't originate from the SYNC_ONYX logic
25
- if (event.key !== SYNC_ONYX || !event.newValue) {
26
- return;
27
- }
28
- const onyxKey = event.newValue;
29
- // @ts-expect-error `this` will be substituted later in actual function call
30
- this.getItem(onyxKey).then((value) => onStorageKeyChanged(onyxKey, value));
31
- });
32
- },
33
- setItem: raiseStorageSyncEvent,
34
- removeItem: raiseStorageSyncEvent,
35
- removeItems: raiseStorageSyncManyKeysEvent,
36
- mergeItem: raiseStorageSyncEvent,
37
- clear: (clearImplementation) => {
38
- let allKeys;
39
- // The keys must be retrieved before storage is cleared or else the list of keys would be empty
40
- // @ts-expect-error `this` will be substituted later in actual function call
41
- return this.getAllKeys()
42
- .then((keys) => {
43
- allKeys = keys;
44
- })
45
- .then(() => clearImplementation())
46
- .then(() => {
47
- // Now that storage is cleared, the storage sync event can happen which is a more atomic action
48
- // for other browser tabs
49
- raiseStorageSyncManyKeysEvent(allKeys);
50
- });
51
- },
52
- };
53
- exports.default = InstanceSync;
@@ -1,2 +0,0 @@
1
- import WebStorage from '../providers/IDBKeyValProvider';
2
- export default WebStorage;
@@ -1,2 +0,0 @@
1
- import NativeStorage from '../providers/SQLiteProvider';
2
- export default NativeStorage;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const provider = {
4
- /**
5
- * The name of the provider that can be printed to the logs
6
- */
7
- name: 'NoopProvider',
8
- /**
9
- * Initializes the storage provider
10
- */
11
- init() {
12
- // do nothing
13
- },
14
- /**
15
- * Get the value of a given key or return `null` if it's not available in memory
16
- * @param {String} key
17
- * @return {Promise<*>}
18
- */
19
- getItem() {
20
- return Promise.resolve(null);
21
- },
22
- /**
23
- * Get multiple key-value pairs for the give array of keys in a batch.
24
- */
25
- multiGet() {
26
- return Promise.resolve([]);
27
- },
28
- /**
29
- * Sets the value for a given key. The only requirement is that the value should be serializable to JSON string
30
- */
31
- setItem() {
32
- return Promise.resolve();
33
- },
34
- /**
35
- * Stores multiple key-value pairs in a batch
36
- */
37
- multiSet() {
38
- return Promise.resolve();
39
- },
40
- /**
41
- * Merging an existing value with a new one
42
- */
43
- mergeItem() {
44
- return Promise.resolve();
45
- },
46
- /**
47
- * Multiple merging of existing and new values in a batch
48
- * This function also removes all nested null values from an object.
49
- */
50
- multiMerge() {
51
- return Promise.resolve([]);
52
- },
53
- /**
54
- * Remove given key and it's value from memory
55
- */
56
- removeItem() {
57
- return Promise.resolve();
58
- },
59
- /**
60
- * Remove given keys and their values from memory
61
- */
62
- removeItems() {
63
- return Promise.resolve();
64
- },
65
- /**
66
- * Clear everything from memory
67
- */
68
- clear() {
69
- return Promise.resolve();
70
- },
71
- // This is a noop for now in order to keep clients from crashing see https://github.com/Expensify/Expensify/issues/312438
72
- setMemoryOnlyKeys() {
73
- // do nothing
74
- },
75
- /**
76
- * Returns all keys available in memory
77
- */
78
- getAllKeys() {
79
- return Promise.resolve([]);
80
- },
81
- /**
82
- * Gets the total bytes of the store.
83
- * `bytesRemaining` will always be `Number.POSITIVE_INFINITY` since we don't have a hard limit on memory.
84
- */
85
- getDatabaseSize() {
86
- return Promise.resolve({ bytesRemaining: Number.POSITIVE_INFINITY, bytesUsed: 0 });
87
- },
88
- };
89
- exports.default = provider;
@@ -1,3 +0,0 @@
1
- import type StorageProvider from './types';
2
- declare const provider: StorageProvider;
3
- export default provider;