react-native-onyx 3.0.143 → 3.0.145
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
|
@@ -63,12 +63,13 @@ function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], shouldSync
|
|
|
63
63
|
(_a = storage_1.default.keepInstancesSync) === null || _a === void 0 ? void 0 : _a.call(storage_1.default, (pairs) => {
|
|
64
64
|
const individual = [];
|
|
65
65
|
const collectionBatches = new Map();
|
|
66
|
-
for (const [key,
|
|
66
|
+
for (const [key, valueFromStorage] of pairs) {
|
|
67
67
|
// RAM-only keys should never sync from storage as they may have stale persisted data
|
|
68
68
|
// from before the key was migrated to RAM-only.
|
|
69
69
|
if (OnyxKeys_1.default.isRamOnlyKey(key)) {
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
|
+
const value = utils_1.default.needsNormalization(valueFromStorage) ? utils_1.default.removeNestedNullValues(valueFromStorage) : valueFromStorage;
|
|
72
73
|
const collectionKey = OnyxKeys_1.default.getCollectionKey(key);
|
|
73
74
|
const isCollectionMember = !!collectionKey && OnyxKeys_1.default.isCollectionMemberKey(collectionKey, key);
|
|
74
75
|
// Capture the previous cached value before cache.set() so notifyCollection() can diff old vs new per member.
|
|
@@ -399,7 +400,6 @@ function clear(keysToPreserve = []) {
|
|
|
399
400
|
const initialKeys = Object.keys(defaultKeyStates);
|
|
400
401
|
const promise = OnyxUtils_1.default.getAllKeys()
|
|
401
402
|
.then((cachedKeys) => {
|
|
402
|
-
var _a;
|
|
403
403
|
OnyxCache_1.default.clearNullishStorageKeys();
|
|
404
404
|
const keysToBeClearedFromStorage = [];
|
|
405
405
|
const keyValuesToResetIndividually = {};
|
|
@@ -433,7 +433,7 @@ function clear(keysToPreserve = []) {
|
|
|
433
433
|
// since collection key subscribers need to be updated differently
|
|
434
434
|
if (!isKeyToPreserve) {
|
|
435
435
|
const oldValue = OnyxCache_1.default.get(key);
|
|
436
|
-
const newValue = (
|
|
436
|
+
const newValue = OnyxUtils_1.default.getNullFreeDefaultKeyState(key);
|
|
437
437
|
valuesSetByClear[key] = newValue;
|
|
438
438
|
if (newValue !== oldValue) {
|
|
439
439
|
OnyxCache_1.default.set(key, newValue);
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ declare function getMergeQueuePromise(): Record<OnyxKey, Promise<void>>;
|
|
|
33
33
|
* Getter - returns the default key states.
|
|
34
34
|
*/
|
|
35
35
|
declare function getDefaultKeyStates(): Record<OnyxKey, OnyxValue<OnyxKey>>;
|
|
36
|
+
/** Getter - returns the default key state without nested nulls, cached so clear() reuses the same references. */
|
|
37
|
+
declare function getNullFreeDefaultKeyState(key: OnyxKey): OnyxValue<OnyxKey>;
|
|
36
38
|
/**
|
|
37
39
|
* Getter - returns the deffered init task.
|
|
38
40
|
*/
|
|
@@ -260,6 +262,7 @@ declare const OnyxUtils: {
|
|
|
260
262
|
getMergeQueue: typeof getMergeQueue;
|
|
261
263
|
getMergeQueuePromise: typeof getMergeQueuePromise;
|
|
262
264
|
getDefaultKeyStates: typeof getDefaultKeyStates;
|
|
265
|
+
getNullFreeDefaultKeyState: typeof getNullFreeDefaultKeyState;
|
|
263
266
|
getDeferredInitTask: typeof getDeferredInitTask;
|
|
264
267
|
afterInit: typeof afterInit;
|
|
265
268
|
initStoreValues: typeof initStoreValues;
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -76,6 +76,8 @@ let mergeQueuePromise = {};
|
|
|
76
76
|
const mergeQueuesWithStaleRead = new WeakSet();
|
|
77
77
|
// Optional user-provided key value states set when Onyx initializes or clears
|
|
78
78
|
let defaultKeyStates = {};
|
|
79
|
+
// Cache for getNullFreeDefaultKeyState()
|
|
80
|
+
let nullFreeDefaultKeyStates = {};
|
|
79
81
|
let snapshotKey = null;
|
|
80
82
|
// Connections can be made before `Onyx.init`. They would wait for this task before resolving.
|
|
81
83
|
let deferredInitTask = (0, createDeferredTask_1.default)();
|
|
@@ -115,6 +117,14 @@ function getMergeQueuePromise() {
|
|
|
115
117
|
function getDefaultKeyStates() {
|
|
116
118
|
return defaultKeyStates;
|
|
117
119
|
}
|
|
120
|
+
/** Getter - returns the default key state without nested nulls, cached so clear() reuses the same references. */
|
|
121
|
+
function getNullFreeDefaultKeyState(key) {
|
|
122
|
+
var _a;
|
|
123
|
+
if (!(key in nullFreeDefaultKeyStates)) {
|
|
124
|
+
nullFreeDefaultKeyStates[key] = utils_1.default.removeNestedNullValues((_a = defaultKeyStates[key]) !== null && _a !== void 0 ? _a : null);
|
|
125
|
+
}
|
|
126
|
+
return nullFreeDefaultKeyStates[key];
|
|
127
|
+
}
|
|
118
128
|
/**
|
|
119
129
|
* Getter - returns the deffered init task.
|
|
120
130
|
*/
|
|
@@ -177,6 +187,7 @@ function initStoreValues(keys, initialKeyStates, evictableKeys) {
|
|
|
177
187
|
}, new Set());
|
|
178
188
|
// Set our default key states to use when initializing and clearing Onyx data
|
|
179
189
|
defaultKeyStates = initialKeyStates;
|
|
190
|
+
nullFreeDefaultKeyStates = {};
|
|
180
191
|
DevTools_1.default.initState(initialKeyStates);
|
|
181
192
|
// Let Onyx know about which keys are safe to evict
|
|
182
193
|
OnyxCache_1.default.setEvictionAllowList(evictableKeys);
|
|
@@ -642,7 +653,7 @@ function prepareKeyValuePairsForStorage(data, shouldRemoveNestedNulls, replaceNu
|
|
|
642
653
|
keysToRemove.push(key);
|
|
643
654
|
continue;
|
|
644
655
|
}
|
|
645
|
-
const valueWithoutNestedNullValues = (shouldRemoveNestedNulls !== null && shouldRemoveNestedNulls !== void 0 ? shouldRemoveNestedNulls : true) ? utils_1.default.removeNestedNullValues(value) : value;
|
|
656
|
+
const valueWithoutNestedNullValues = (shouldRemoveNestedNulls !== null && shouldRemoveNestedNulls !== void 0 ? shouldRemoveNestedNulls : true) ? utils_1.default.removeNestedNullValues(value, OnyxCache_1.default.get(key)) : value;
|
|
646
657
|
if (valueWithoutNestedNullValues !== undefined) {
|
|
647
658
|
pairs.push([key, valueWithoutNestedNullValues, replaceNullPatches === null || replaceNullPatches === void 0 ? void 0 : replaceNullPatches[key]]);
|
|
648
659
|
}
|
|
@@ -916,7 +927,7 @@ function setWithRetry({ key, value, options }, retryAttempt) {
|
|
|
916
927
|
OnyxUtils.logKeyRemoved(OnyxUtils.METHOD.SET, key);
|
|
917
928
|
return Promise.resolve();
|
|
918
929
|
}
|
|
919
|
-
const valueWithoutNestedNullValues = utils_1.default.removeNestedNullValues(value);
|
|
930
|
+
const valueWithoutNestedNullValues = utils_1.default.removeNestedNullValues(value, existingValue);
|
|
920
931
|
const hasChanged = (options === null || options === void 0 ? void 0 : options.skipCacheCheck) ? true : OnyxCache_1.default.hasValueChanged(key, valueWithoutNestedNullValues);
|
|
921
932
|
OnyxUtils.logKeyChanged(OnyxUtils.METHOD.SET, key, value, hasChanged);
|
|
922
933
|
// This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
|
|
@@ -1400,6 +1411,7 @@ const OnyxUtils = {
|
|
|
1400
1411
|
getMergeQueue,
|
|
1401
1412
|
getMergeQueuePromise,
|
|
1402
1413
|
getDefaultKeyStates,
|
|
1414
|
+
getNullFreeDefaultKeyState,
|
|
1403
1415
|
getDeferredInitTask,
|
|
1404
1416
|
afterInit,
|
|
1405
1417
|
initStoreValues,
|
|
@@ -170,7 +170,13 @@ const provider = {
|
|
|
170
170
|
}
|
|
171
171
|
return (IDB.get(key, provider.store)
|
|
172
172
|
// idb-keyval returns undefined for missing items, but this needs to return null so that idb-keyval does the same thing as SQLiteStorage.
|
|
173
|
-
.then((val) =>
|
|
173
|
+
.then((val) => {
|
|
174
|
+
if (val === undefined) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
// Stored values can hold nested nulls, but values handed to the cache must not.
|
|
178
|
+
return utils_1.default.needsNormalization(val) ? utils_1.default.removeNestedNullValues(val) : val;
|
|
179
|
+
}));
|
|
174
180
|
},
|
|
175
181
|
removeItem(key) {
|
|
176
182
|
if (!provider.store) {
|
|
@@ -185,7 +185,9 @@ const provider = {
|
|
|
185
185
|
if (result == null) {
|
|
186
186
|
return null;
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
const value = JSON.parse(result.valueJSON);
|
|
189
|
+
// valueJSON is a number for numeric values, so the type is checked before includes().
|
|
190
|
+
return typeof value === 'object' && value !== null && result.valueJSON.includes('null') ? utils_1.default.removeNestedNullValues(value) : value;
|
|
189
191
|
});
|
|
190
192
|
},
|
|
191
193
|
multiGet(keys) {
|
package/dist/utils.d.ts
CHANGED
|
@@ -47,8 +47,13 @@ declare function isEmptyObject<T>(obj: T | EmptyValue): obj is EmptyValue;
|
|
|
47
47
|
* safe to store by reference. Read-only, non-allocating.
|
|
48
48
|
*/
|
|
49
49
|
declare function needsNormalization(value: unknown): boolean;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Deep removes nested null values from the given value, leaving arrays as they are. Returns the original reference if no nulls were found.
|
|
52
|
+
*
|
|
53
|
+
* Objects that are the same reference as the object at the same path in `nullFreeReference` are returned without being traversed,
|
|
54
|
+
* so `nullFreeReference` must hold no nested nulls outside arrays (pass the live cache value).
|
|
55
|
+
*/
|
|
56
|
+
declare function removeNestedNullValues<TValue extends OnyxInput<OnyxKey> | null>(value: TValue, nullFreeReference?: unknown): TValue;
|
|
52
57
|
/** Formats the action name by uppercasing and adding the key if provided. */
|
|
53
58
|
declare function formatActionName(method: string, key?: OnyxKey): string;
|
|
54
59
|
/** validate that the update and the existing value are compatible */
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
const fast_equals_1 = require("fast-equals");
|
|
37
|
+
const Logger = __importStar(require("./Logger"));
|
|
4
38
|
const ONYX_INTERNALS__REPLACE_OBJECT_MARK = 'ONYX_INTERNALS__REPLACE_OBJECT_MARK';
|
|
5
39
|
/**
|
|
6
40
|
* Merges two objects and removes null values if "shouldRemoveNestedNulls" is set to true
|
|
@@ -110,7 +144,8 @@ function mergeObject(target, source, options, metadata, basePath) {
|
|
|
110
144
|
// of the merged object only.
|
|
111
145
|
const sourcePropertyWithoutMark = Object.assign({}, sourceProperty);
|
|
112
146
|
delete sourcePropertyWithoutMark.ONYX_INTERNALS__REPLACE_OBJECT_MARK;
|
|
113
|
-
|
|
147
|
+
// Built in "mark" mode, so it can still hold nested nulls.
|
|
148
|
+
destination[key] = options.shouldRemoveNestedNulls ? removeNestedNullValues(sourcePropertyWithoutMark) : sourcePropertyWithoutMark;
|
|
114
149
|
continue;
|
|
115
150
|
}
|
|
116
151
|
const merged = fastMerge(targetProperty, sourceProperty, options, metadata, [...basePath, key]).result;
|
|
@@ -182,11 +217,23 @@ function needsNormalization(value) {
|
|
|
182
217
|
}
|
|
183
218
|
return false;
|
|
184
219
|
}
|
|
185
|
-
/**
|
|
186
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Deep removes nested null values from the given value, leaving arrays as they are. Returns the original reference if no nulls were found.
|
|
222
|
+
*
|
|
223
|
+
* Objects that are the same reference as the object at the same path in `nullFreeReference` are returned without being traversed,
|
|
224
|
+
* so `nullFreeReference` must hold no nested nulls outside arrays (pass the live cache value).
|
|
225
|
+
*/
|
|
226
|
+
function removeNestedNullValues(value, nullFreeReference) {
|
|
187
227
|
if (value === null || value === undefined || typeof value !== 'object' || Array.isArray(value)) {
|
|
188
228
|
return value;
|
|
189
229
|
}
|
|
230
|
+
if (value === nullFreeReference) {
|
|
231
|
+
if (process.env.NODE_ENV === 'development' && needsNormalization(value)) {
|
|
232
|
+
Logger.logAlert('removeNestedNullValues skipped a cached subtree that holds nested null values. Onyx values must not be mutated in place.');
|
|
233
|
+
}
|
|
234
|
+
return value;
|
|
235
|
+
}
|
|
236
|
+
const reference = nullFreeReference !== null && typeof nullFreeReference === 'object' && !Array.isArray(nullFreeReference) ? nullFreeReference : undefined;
|
|
190
237
|
let hasChanged = false;
|
|
191
238
|
const result = {};
|
|
192
239
|
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
@@ -197,7 +244,7 @@ function removeNestedNullValues(value) {
|
|
|
197
244
|
continue;
|
|
198
245
|
}
|
|
199
246
|
if (typeof propertyValue === 'object' && !Array.isArray(propertyValue)) {
|
|
200
|
-
const cleaned = removeNestedNullValues(propertyValue);
|
|
247
|
+
const cleaned = removeNestedNullValues(propertyValue, reference === null || reference === void 0 ? void 0 : reference[key]);
|
|
201
248
|
if (cleaned !== propertyValue) {
|
|
202
249
|
hasChanged = true;
|
|
203
250
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-onyx",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.145",
|
|
4
4
|
"author": "Expensify, Inc.",
|
|
5
5
|
"homepage": "https://expensify.com",
|
|
6
6
|
"description": "State management for React Native",
|
|
@@ -126,7 +126,8 @@
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"overrides": {
|
|
129
|
-
"simple-git": "^4.0.2"
|
|
129
|
+
"simple-git": "^4.0.2",
|
|
130
|
+
"undici": "^6.29.1"
|
|
130
131
|
},
|
|
131
132
|
"engines": {
|
|
132
133
|
"node": ">=20.19.5",
|