react-native-onyx 2.0.20 → 2.0.22
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/API.md +0 -14
- package/dist/Onyx.d.ts +0 -6
- package/dist/Onyx.js +29 -20
- package/dist/OnyxCache.d.ts +1 -1
- package/dist/OnyxCache.js +1 -1
- package/dist/storage/__mocks__/index.d.ts +0 -1
- package/dist/storage/__mocks__/index.js +0 -3
- package/dist/storage/providers/IDBKeyVal.js +0 -2
- package/dist/storage/providers/SQLiteStorage.js +0 -2
- package/dist/storage/providers/types.d.ts +0 -4
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -94,9 +94,6 @@ value will be saved to storage after the default value.</p>
|
|
|
94
94
|
<dt><a href="#update">update(data)</a> ⇒ <code>Promise</code></dt>
|
|
95
95
|
<dd><p>Insert API responses and lifecycle data into Onyx</p>
|
|
96
96
|
</dd>
|
|
97
|
-
<dt><a href="#setMemoryOnlyKeys">setMemoryOnlyKeys(keyList)</a></dt>
|
|
98
|
-
<dd><p>When set these keys will not be persisted to storage</p>
|
|
99
|
-
</dd>
|
|
100
97
|
<dt><a href="#init">init([options])</a></dt>
|
|
101
98
|
<dd><p>Initialize the store with actions and listening for storage events</p>
|
|
102
99
|
</dd>
|
|
@@ -424,17 +421,6 @@ Insert API responses and lifecycle data into Onyx
|
|
|
424
421
|
| --- | --- | --- |
|
|
425
422
|
| data | <code>Array</code> | An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection', 'multiSet', 'clear'), key: string, value: *} |
|
|
426
423
|
|
|
427
|
-
<a name="setMemoryOnlyKeys"></a>
|
|
428
|
-
|
|
429
|
-
## setMemoryOnlyKeys(keyList)
|
|
430
|
-
When set these keys will not be persisted to storage
|
|
431
|
-
|
|
432
|
-
**Kind**: global function
|
|
433
|
-
|
|
434
|
-
| Param | Type |
|
|
435
|
-
| --- | --- |
|
|
436
|
-
| keyList | <code>Array.<string></code> |
|
|
437
|
-
|
|
438
424
|
<a name="init"></a>
|
|
439
425
|
|
|
440
426
|
## init([options])
|
package/dist/Onyx.d.ts
CHANGED
|
@@ -304,11 +304,6 @@ declare function init(config?: InitOptions): void;
|
|
|
304
304
|
*/
|
|
305
305
|
declare function hasPendingMergeForKey(key: OnyxKey): boolean;
|
|
306
306
|
|
|
307
|
-
/**
|
|
308
|
-
* When set these keys will not be persisted to storage
|
|
309
|
-
*/
|
|
310
|
-
declare function setMemoryOnlyKeys(keyList: OnyxKey[]): void;
|
|
311
|
-
|
|
312
307
|
/**
|
|
313
308
|
* Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
|
|
314
309
|
* If the requested key is a collection, it will return an object with all the collection members.
|
|
@@ -335,7 +330,6 @@ declare const Onyx: {
|
|
|
335
330
|
removeFromEvictionBlockList: typeof removeFromEvictionBlockList;
|
|
336
331
|
isSafeEvictionKey: typeof isSafeEvictionKey;
|
|
337
332
|
METHOD: typeof METHOD;
|
|
338
|
-
setMemoryOnlyKeys: typeof setMemoryOnlyKeys;
|
|
339
333
|
tryGetCachedValue: typeof tryGetCachedValue;
|
|
340
334
|
isCollectionKey: typeof isCollectionKey;
|
|
341
335
|
isCollectionMemberKey: typeof isCollectionMemberKey;
|
package/dist/Onyx.js
CHANGED
|
@@ -165,12 +165,12 @@ function get(key) {
|
|
|
165
165
|
/**
|
|
166
166
|
* Returns current key names stored in persisted storage
|
|
167
167
|
* @private
|
|
168
|
-
* @returns {Promise<
|
|
168
|
+
* @returns {Promise<Set<Key>>}
|
|
169
169
|
*/
|
|
170
170
|
function getAllKeys() {
|
|
171
171
|
// When we've already read stored keys, resolve right away
|
|
172
172
|
const storedKeys = OnyxCache_1.default.getAllKeys();
|
|
173
|
-
if (storedKeys.
|
|
173
|
+
if (storedKeys.size > 0) {
|
|
174
174
|
return Promise.resolve(storedKeys);
|
|
175
175
|
}
|
|
176
176
|
const taskName = 'getAllKeys';
|
|
@@ -181,7 +181,8 @@ function getAllKeys() {
|
|
|
181
181
|
// Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
|
|
182
182
|
const promise = storage_1.default.getAllKeys().then((keys) => {
|
|
183
183
|
OnyxCache_1.default.setAllKeys(keys);
|
|
184
|
-
return keys
|
|
184
|
+
// return the updated set of keys
|
|
185
|
+
return OnyxCache_1.default.getAllKeys();
|
|
185
186
|
});
|
|
186
187
|
return OnyxCache_1.default.captureTask(taskName, promise);
|
|
187
188
|
}
|
|
@@ -252,10 +253,16 @@ function tryGetCachedValue(key, mapping = {}) {
|
|
|
252
253
|
const allCacheKeys = OnyxCache_1.default.getAllKeys();
|
|
253
254
|
// It is possible we haven't loaded all keys yet so we do not know if the
|
|
254
255
|
// collection actually exists.
|
|
255
|
-
if (allCacheKeys.
|
|
256
|
+
if (allCacheKeys.size === 0) {
|
|
256
257
|
return;
|
|
257
258
|
}
|
|
258
|
-
const matchingKeys =
|
|
259
|
+
const matchingKeys = [];
|
|
260
|
+
allCacheKeys.forEach((k) => {
|
|
261
|
+
if (!k.startsWith(key)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
matchingKeys.push(k);
|
|
265
|
+
});
|
|
259
266
|
const values = underscore_1.default.reduce(matchingKeys, (finalObject, matchedKey) => {
|
|
260
267
|
const cachedValue = OnyxCache_1.default.getValue(matchedKey);
|
|
261
268
|
if (cachedValue) {
|
|
@@ -342,7 +349,7 @@ function addToEvictionBlockList(key, connectionID) {
|
|
|
342
349
|
function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
343
350
|
return getAllKeys().then((keys) => {
|
|
344
351
|
underscore_1.default.each(evictionAllowList, (safeEvictionKey) => {
|
|
345
|
-
|
|
352
|
+
keys.forEach((key) => {
|
|
346
353
|
if (!isKeyMatch(safeEvictionKey, key)) {
|
|
347
354
|
return;
|
|
348
355
|
}
|
|
@@ -357,7 +364,13 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
357
364
|
* @returns {Object}
|
|
358
365
|
*/
|
|
359
366
|
function getCachedCollection(collectionKey) {
|
|
360
|
-
const collectionMemberKeys =
|
|
367
|
+
const collectionMemberKeys = [];
|
|
368
|
+
OnyxCache_1.default.getAllKeys().forEach((storedKey) => {
|
|
369
|
+
if (!isCollectionMemberKey(collectionKey, storedKey)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
collectionMemberKeys.push(storedKey);
|
|
373
|
+
});
|
|
361
374
|
return underscore_1.default.reduce(collectionMemberKeys, (prev, curr) => {
|
|
362
375
|
const cachedValue = OnyxCache_1.default.getValue(curr);
|
|
363
376
|
if (!cachedValue) {
|
|
@@ -821,7 +834,13 @@ function connect(mapping) {
|
|
|
821
834
|
// We search all the keys in storage to see if any are a "match" for the subscriber we are connecting so that we
|
|
822
835
|
// can send data back to the subscriber. Note that multiple keys can match as a subscriber could either be
|
|
823
836
|
// subscribed to a "collection key" or a single key.
|
|
824
|
-
const matchingKeys =
|
|
837
|
+
const matchingKeys = [];
|
|
838
|
+
keys.forEach((key) => {
|
|
839
|
+
if (!isKeyMatch(mapping.key, key)) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
matchingKeys.push(key);
|
|
843
|
+
});
|
|
825
844
|
// If the key being connected to does not exist we initialize the value with null. For subscribers that connected
|
|
826
845
|
// directly via connect() they will simply get a null value sent to them without any information about which key matched
|
|
827
846
|
// since there are none matched. In withOnyx() we wait for all connected keys to return a value before rendering the child
|
|
@@ -1241,7 +1260,7 @@ function clear(keysToPreserve = []) {
|
|
|
1241
1260
|
// status, or activeClients need to remain in Onyx even when signed out)
|
|
1242
1261
|
// 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them
|
|
1243
1262
|
// to null would cause unknown behavior)
|
|
1244
|
-
|
|
1263
|
+
keys.forEach((key) => {
|
|
1245
1264
|
const isKeyToPreserve = underscore_1.default.contains(keysToPreserve, key);
|
|
1246
1265
|
const isDefaultKey = underscore_1.default.has(defaultKeyStates, key);
|
|
1247
1266
|
// If the key is being removed or reset to default:
|
|
@@ -1336,7 +1355,7 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1336
1355
|
return true;
|
|
1337
1356
|
})
|
|
1338
1357
|
.keys()
|
|
1339
|
-
.partition((key) => persistedKeys.
|
|
1358
|
+
.partition((key) => persistedKeys.has(key))
|
|
1340
1359
|
.value();
|
|
1341
1360
|
const existingKeyCollection = underscore_1.default.pick(collection, existingKeys);
|
|
1342
1361
|
const newCollection = underscore_1.default.pick(collection, newKeys);
|
|
@@ -1412,15 +1431,6 @@ function update(data) {
|
|
|
1412
1431
|
});
|
|
1413
1432
|
return clearPromise.then(() => Promise.all(underscore_1.default.map(promises, (p) => p())));
|
|
1414
1433
|
}
|
|
1415
|
-
/**
|
|
1416
|
-
* When set these keys will not be persisted to storage
|
|
1417
|
-
* @param {string[]} keyList
|
|
1418
|
-
*/
|
|
1419
|
-
function setMemoryOnlyKeys(keyList) {
|
|
1420
|
-
storage_1.default.setMemoryOnlyKeys(keyList);
|
|
1421
|
-
// When in memory only mode for certain keys we do not want to ever drop items from the cache as the user will have no way to recover them again via storage.
|
|
1422
|
-
OnyxCache_1.default.setRecentKeysLimit(Infinity);
|
|
1423
|
-
}
|
|
1424
1434
|
/**
|
|
1425
1435
|
* Initialize the store with actions and listening for storage events
|
|
1426
1436
|
*
|
|
@@ -1491,7 +1501,6 @@ const Onyx = {
|
|
|
1491
1501
|
removeFromEvictionBlockList,
|
|
1492
1502
|
isSafeEvictionKey,
|
|
1493
1503
|
METHOD,
|
|
1494
|
-
setMemoryOnlyKeys,
|
|
1495
1504
|
tryGetCachedValue,
|
|
1496
1505
|
hasPendingMergeForKey,
|
|
1497
1506
|
isCollectionKey,
|
package/dist/OnyxCache.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class OnyxCache {
|
|
|
20
20
|
private maxRecentKeysSize;
|
|
21
21
|
constructor();
|
|
22
22
|
/** Get all the storage keys */
|
|
23
|
-
getAllKeys(): Key
|
|
23
|
+
getAllKeys(): Set<Key>;
|
|
24
24
|
/**
|
|
25
25
|
* Get a cached value from storage
|
|
26
26
|
* @param [shouldReindexCache] – This is an LRU cache, and by default accessing a value will make it become last in line to be evicted. This flag can be used to skip that and just access the value directly without side-effects.
|
package/dist/OnyxCache.js
CHANGED
|
@@ -60,8 +60,6 @@ const idbKeyvalMock = {
|
|
|
60
60
|
getDatabaseSize() {
|
|
61
61
|
return Promise.resolve({ bytesRemaining: 0, bytesUsed: 99999 });
|
|
62
62
|
},
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
64
|
-
setMemoryOnlyKeys() { },
|
|
65
63
|
};
|
|
66
64
|
const idbKeyvalMockSpy = {
|
|
67
65
|
idbKeyvalSet: set,
|
|
@@ -80,6 +78,5 @@ const idbKeyvalMockSpy = {
|
|
|
80
78
|
storageMapInternal = data;
|
|
81
79
|
}),
|
|
82
80
|
getDatabaseSize: jest.fn(idbKeyvalMock.getDatabaseSize),
|
|
83
|
-
setMemoryOnlyKeys: jest.fn(idbKeyvalMock.setMemoryOnlyKeys),
|
|
84
81
|
};
|
|
85
82
|
exports.default = idbKeyvalMockSpy;
|
|
@@ -37,8 +37,6 @@ const provider = {
|
|
|
37
37
|
},
|
|
38
38
|
multiSet: (pairs) => (0, idb_keyval_1.setMany)(pairs, getCustomStore()),
|
|
39
39
|
clear: () => (0, idb_keyval_1.clear)(getCustomStore()),
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
41
|
-
setMemoryOnlyKeys: () => { },
|
|
42
40
|
getAllKeys: () => (0, idb_keyval_1.keys)(getCustomStore()),
|
|
43
41
|
getItem: (key) => (0, idb_keyval_1.get)(key, getCustomStore())
|
|
44
42
|
// idb-keyval returns undefined for missing items, but this needs to return null so that idb-keyval does the same thing as SQLiteStorage.
|
|
@@ -85,8 +85,6 @@ const provider = {
|
|
|
85
85
|
});
|
|
86
86
|
},
|
|
87
87
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
88
|
-
setMemoryOnlyKeys: () => { },
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
90
88
|
keepInstancesSync: () => { },
|
|
91
89
|
};
|
|
92
90
|
exports.default = provider;
|
|
@@ -48,10 +48,6 @@ type StorageProvider = {
|
|
|
48
48
|
* Clears absolutely everything from storage
|
|
49
49
|
*/
|
|
50
50
|
clear: () => Promise<QueryResult | void>;
|
|
51
|
-
/**
|
|
52
|
-
* Sets memory only keys
|
|
53
|
-
*/
|
|
54
|
-
setMemoryOnlyKeys: () => void;
|
|
55
51
|
/**
|
|
56
52
|
* Gets the total bytes of the database file
|
|
57
53
|
*/
|