From b4257baa60503af7ca89e5f5c369acfbade3e870 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 18 Sep 2026 12:36:58 +0200 Subject: [PATCH 1/7] feat: export persisted Onyx state through active provider --- README.md | 4 ++++ lib/Onyx.ts | 9 +++++++++ tests/unit/onyxTest.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/README.md b/README.md index 56820a456..1635c677f 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,10 @@ function signOut() { } ``` +## Export persisted state + +`Onyx.exportState()` returns a plain object containing every persisted key and value from the active storage provider. It works on native and web without opening another database connection. RAM-only values and writes still in progress are not included. The result can contain sensitive data; callers should redact it before sharing. + ## Storage Providers `Onyx.get`, `Onyx.set`, and the rest of the API accesses the underlying storage differently depending on the platform diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 29a1d20ab..d660463b0 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -611,6 +611,14 @@ function setCollection(collectionKey: TKey, coll return OnyxUtils.afterInit(() => OnyxUtils.setCollectionWithRetry({collectionKey, collection})); } +/** + * Returns all persisted Onyx key-value pairs as a plain object. + * RAM-only values and writes that have not reached storage are not included. + */ +function exportState(): Promise> { + return OnyxUtils.afterInit(() => Storage.getAll().then((entries) => Object.fromEntries(entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key))))); +} + const Onyx = { METHOD: OnyxUtils.METHOD, connect, @@ -623,6 +631,7 @@ const Onyx = { setCollection, update, clear, + exportState, init, registerLogger: Logger.registerLogger, }; diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index 69f47c6b2..238b7bcdf 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -66,6 +66,36 @@ describe('Onyx', () => { return Onyx.clear(); }); + describe('exportState', () => { + it('exports persisted values without RAM-only values', async () => { + await Onyx.set(ONYX_KEYS.TEST_KEY, {nested: 'value'}); + await Onyx.set(ONYX_KEYS.RAM_ONLY_TEST_KEY, 'not persisted'); + + const state = await Onyx.exportState(); + + expect(state[ONYX_KEYS.TEST_KEY]).toEqual({nested: 'value'}); + expect(state).not.toHaveProperty(ONYX_KEYS.RAM_ONLY_TEST_KEY); + }); + + it('propagates storage read failures', async () => { + const error = new Error('Storage read failed'); + const getAll = jest.spyOn(StorageMock, 'getAll').mockRejectedValueOnce(error); + + await expect(Onyx.exportState()).rejects.toBe(error); + getAll.mockRestore(); + }); + + it('excludes stale persisted values for keys now configured as RAM-only', async () => { + const getAll = jest.spyOn(StorageMock, 'getAll').mockResolvedValueOnce([ + [ONYX_KEYS.TEST_KEY, 'persisted'], + [ONYX_KEYS.RAM_ONLY_TEST_KEY, 'stale'], + ]); + + await expect(Onyx.exportState()).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted'}); + getAll.mockRestore(); + }); + }); + it('should remove key value from OnyxCache/Storage when set is called with null value', () => Onyx.set(ONYX_KEYS.OTHER_TEST, 42) .then(() => OnyxUtils.getAllKeys()) From f84fdb9e6f7245d04c25bf4b3698b69a9f3525f7 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 18 Sep 2026 12:40:28 +0200 Subject: [PATCH 2/7] docs: include Onyx state export in API reference --- API.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/API.md b/API.md index e766e551f..b5d412539 100644 --- a/API.md +++ b/API.md @@ -58,6 +58,10 @@ value will be saved to storage after the default value.

Sets a collection by replacing all existing collection members with new values. Any existing collection members not included in the new data will be removed.

+
exportState()
+

Returns all persisted Onyx key-value pairs as a plain object. +RAM-only values and writes that have not reached storage are not included.

+
@@ -257,3 +261,10 @@ Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, { [`${ONYXKEYS.COLLECTION.REPORT}2`]: report2, }); ``` + + +## exportState() +Returns all persisted Onyx key-value pairs as a plain object. +RAM-only values and writes that have not reached storage are not included. + +**Kind**: global function From e1aeb98f31bec149e58d741ad123c93453ed65b6 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 18 Sep 2026 15:40:43 +0200 Subject: [PATCH 3/7] test: preserve storage mock after Onyx export tests StorageMock.getAll is already a Jest mock, so mockRestore clears its default implementation and breaks later Onyx.init tests. Use one-shot mock values without restoring the shared mock. --- tests/unit/onyxTest.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index 238b7bcdf..25918e360 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -79,20 +79,18 @@ describe('Onyx', () => { it('propagates storage read failures', async () => { const error = new Error('Storage read failed'); - const getAll = jest.spyOn(StorageMock, 'getAll').mockRejectedValueOnce(error); + jest.mocked(StorageMock.getAll).mockRejectedValueOnce(error); await expect(Onyx.exportState()).rejects.toBe(error); - getAll.mockRestore(); }); it('excludes stale persisted values for keys now configured as RAM-only', async () => { - const getAll = jest.spyOn(StorageMock, 'getAll').mockResolvedValueOnce([ + jest.mocked(StorageMock.getAll).mockResolvedValueOnce([ [ONYX_KEYS.TEST_KEY, 'persisted'], [ONYX_KEYS.RAM_ONLY_TEST_KEY, 'stale'], ]); await expect(Onyx.exportState()).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted'}); - getAll.mockRestore(); }); }); From 9fbd90ce919db81343aca2f353055473c8636ef4 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 18 Sep 2026 19:41:02 +0200 Subject: [PATCH 4/7] feat: configure stale RAM-only keys in state export --- API.md | 18 ++++++++++++------ README.md | 2 +- lib/Onyx.ts | 17 +++++++++++++---- tests/unit/onyxTest.ts | 16 ++++++++++++++-- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/API.md b/API.md index b5d412539..9dfbd31d3 100644 --- a/API.md +++ b/API.md @@ -58,9 +58,9 @@ value will be saved to storage after the default value.

Sets a collection by replacing all existing collection members with new values. Any existing collection members not included in the new data will be removed.

-
exportState()
-

Returns all persisted Onyx key-value pairs as a plain object. -RAM-only values and writes that have not reached storage are not included.

+
exportState([options])
+

Returns persisted Onyx key-value pairs as a plain object. +Live RAM-only values and writes that have not reached storage are not included.

@@ -263,8 +263,14 @@ Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, { ``` -## exportState() -Returns all persisted Onyx key-value pairs as a plain object. -RAM-only values and writes that have not reached storage are not included. +## exportState([options]) +Returns persisted Onyx key-value pairs as a plain object. +Live RAM-only values and writes that have not reached storage are not included. **Kind**: global function + +| Param | Default | Description | +| --- | --- | --- | +| [options] | | Export options. | +| [options.includeStaleRamOnlyKeys] | false | Include persisted rows for keys that are now RAM-only. | + diff --git a/README.md b/README.md index 1635c677f..262e99d1a 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ function signOut() { ## Export persisted state -`Onyx.exportState()` returns a plain object containing every persisted key and value from the active storage provider. It works on native and web without opening another database connection. RAM-only values and writes still in progress are not included. The result can contain sensitive data; callers should redact it before sharing. +`Onyx.exportState()` returns a plain object containing persisted keys and values from the active storage provider. It works on native and web without opening another database connection. By default, it excludes stale persisted rows for keys that are now RAM-only. Pass `{includeStaleRamOnlyKeys: true}` to include those rows and match a raw storage export. Current RAM-only values and writes still in progress are never included. The result can contain sensitive data; callers should redact it before sharing. ## Storage Providers `Onyx.get`, `Onyx.set`, and the rest of the API accesses the underlying storage diff --git a/lib/Onyx.ts b/lib/Onyx.ts index d660463b0..97ad7fbf0 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -611,12 +611,21 @@ function setCollection(collectionKey: TKey, coll return OnyxUtils.afterInit(() => OnyxUtils.setCollectionWithRetry({collectionKey, collection})); } +type ExportStateOptions = { + /** Include persisted rows for keys that are now RAM-only. Defaults to false. */ + includeStaleRamOnlyKeys?: boolean; +}; + /** - * Returns all persisted Onyx key-value pairs as a plain object. - * RAM-only values and writes that have not reached storage are not included. + * Returns persisted Onyx key-value pairs as a plain object. + * Live RAM-only values and writes that have not reached storage are not included. + * @param [options] Export options. + * @param [options.includeStaleRamOnlyKeys=false] Include persisted rows for keys that are now RAM-only. */ -function exportState(): Promise> { - return OnyxUtils.afterInit(() => Storage.getAll().then((entries) => Object.fromEntries(entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key))))); +function exportState({includeStaleRamOnlyKeys = false}: ExportStateOptions = {}): Promise> { + return OnyxUtils.afterInit(() => + Storage.getAll().then((entries) => Object.fromEntries(includeStaleRamOnlyKeys ? entries : entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key)))), + ); } const Onyx = { diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index 25918e360..d083e7d62 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -67,7 +67,7 @@ describe('Onyx', () => { }); describe('exportState', () => { - it('exports persisted values without RAM-only values', async () => { + it('exports persisted values without current RAM-only values', async () => { await Onyx.set(ONYX_KEYS.TEST_KEY, {nested: 'value'}); await Onyx.set(ONYX_KEYS.RAM_ONLY_TEST_KEY, 'not persisted'); @@ -84,12 +84,24 @@ describe('Onyx', () => { await expect(Onyx.exportState()).rejects.toBe(error); }); - it('excludes stale persisted values for keys now configured as RAM-only', async () => { + it('includes stale persisted RAM-only values when requested without using current RAM-only values', async () => { + await Onyx.set(ONYX_KEYS.RAM_ONLY_TEST_KEY, 'current'); jest.mocked(StorageMock.getAll).mockResolvedValueOnce([ [ONYX_KEYS.TEST_KEY, 'persisted'], [ONYX_KEYS.RAM_ONLY_TEST_KEY, 'stale'], ]); + await expect(Onyx.exportState({includeStaleRamOnlyKeys: true})).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted', [ONYX_KEYS.RAM_ONLY_TEST_KEY]: 'stale'}); + }); + + it('excludes stale persisted RAM-only values by default', async () => { + const staleCollectionMember = `${ONYX_KEYS.COLLECTION.RAM_ONLY_COLLECTION}1`; + jest.mocked(StorageMock.getAll).mockResolvedValueOnce([ + [ONYX_KEYS.TEST_KEY, 'persisted'], + [ONYX_KEYS.RAM_ONLY_TEST_KEY, 'stale'], + [staleCollectionMember, 'stale collection member'], + ]); + await expect(Onyx.exportState()).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted'}); }); }); From ef2f5900b1073c19e8aa1f31c715b551a9c6a82b Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 18 Sep 2026 19:50:13 +0200 Subject: [PATCH 5/7] style: format Onyx state export option --- lib/Onyx.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 97ad7fbf0..09fa7766c 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -623,9 +623,7 @@ type ExportStateOptions = { * @param [options.includeStaleRamOnlyKeys=false] Include persisted rows for keys that are now RAM-only. */ function exportState({includeStaleRamOnlyKeys = false}: ExportStateOptions = {}): Promise> { - return OnyxUtils.afterInit(() => - Storage.getAll().then((entries) => Object.fromEntries(includeStaleRamOnlyKeys ? entries : entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key)))), - ); + return OnyxUtils.afterInit(() => Storage.getAll().then((entries) => Object.fromEntries(includeStaleRamOnlyKeys ? entries : entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key))))); } const Onyx = { From 87f814743104a6680f4f6333e138ad65e47ea60b Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sat, 19 Sep 2026 13:45:22 +0200 Subject: [PATCH 6/7] fix: strengthen Onyx state export contracts --- API.md | 4 +++- README.md | 2 +- lib/Onyx.ts | 26 ++++++++++++++++++-------- lib/index.ts | 3 ++- lib/types.ts | 9 +++++++++ tests/unit/onyxTest.ts | 23 +++++++++++++++++++++++ 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/API.md b/API.md index 9dfbd31d3..8bc4cb445 100644 --- a/API.md +++ b/API.md @@ -60,7 +60,8 @@ Any existing collection members not included in the new data will be removed.

exportState([options])

Returns persisted Onyx key-value pairs as a plain object. -Live RAM-only values and writes that have not reached storage are not included.

+Live RAM-only values and writes that have not reached storage are not included. +Treat the returned object and its nested values as read-only.

@@ -266,6 +267,7 @@ Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, { ## exportState([options]) Returns persisted Onyx key-value pairs as a plain object. Live RAM-only values and writes that have not reached storage are not included. +Treat the returned object and its nested values as read-only. **Kind**: global function diff --git a/README.md b/README.md index 262e99d1a..399fe8d8d 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ function signOut() { ## Export persisted state -`Onyx.exportState()` returns a plain object containing persisted keys and values from the active storage provider. It works on native and web without opening another database connection. By default, it excludes stale persisted rows for keys that are now RAM-only. Pass `{includeStaleRamOnlyKeys: true}` to include those rows and match a raw storage export. Current RAM-only values and writes still in progress are never included. The result can contain sensitive data; callers should redact it before sharing. +`Onyx.exportState()` returns a plain object containing persisted keys and values from the active storage provider. It works on native and web without opening another database connection. By default, it excludes stale persisted rows for keys that are now RAM-only. Pass `{includeStaleRamOnlyKeys: true}` only when a diagnostic export must retain legacy rows from before a key became RAM-only, such as when matching a raw storage export. Current RAM-only values and writes still in progress are never included. Treat the returned object and its nested values as read-only because some providers return references to their stored values. The result can contain sensitive data; callers should redact it before sharing. ## Storage Providers `Onyx.get`, `Onyx.set`, and the rest of the API accesses the underlying storage diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 09fa7766c..81de47d34 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -6,6 +6,7 @@ import DevTools, {initDevTools} from './DevTools'; import type { CollectionKeyBase, ConnectOptions, + ExportStateOptions, InitOptions, KeyValueMapping, MixedOperationsQueue, @@ -611,19 +612,28 @@ function setCollection(collectionKey: TKey, coll return OnyxUtils.afterInit(() => OnyxUtils.setCollectionWithRetry({collectionKey, collection})); } -type ExportStateOptions = { - /** Include persisted rows for keys that are now RAM-only. Defaults to false. */ - includeStaleRamOnlyKeys?: boolean; -}; - /** * Returns persisted Onyx key-value pairs as a plain object. * Live RAM-only values and writes that have not reached storage are not included. + * Treat the returned object and its nested values as read-only. * @param [options] Export options. * @param [options.includeStaleRamOnlyKeys=false] Include persisted rows for keys that are now RAM-only. */ -function exportState({includeStaleRamOnlyKeys = false}: ExportStateOptions = {}): Promise> { - return OnyxUtils.afterInit(() => Storage.getAll().then((entries) => Object.fromEntries(includeStaleRamOnlyKeys ? entries : entries.filter(([key]) => !OnyxKeys.isRamOnlyKey(key))))); +function exportState({includeStaleRamOnlyKeys = false}: ExportStateOptions = {}): Promise>> { + return OnyxUtils.afterInit(() => + Storage.getAll().then((entries) => { + const state: Record> = {}; + + for (const [key, value] of entries) { + if (!includeStaleRamOnlyKeys && OnyxKeys.isRamOnlyKey(key)) { + continue; + } + state[key] = value; + } + + return state; + }), + ); } const Onyx = { @@ -644,4 +654,4 @@ const Onyx = { }; export default Onyx; -export type {OnyxUpdate, ConnectOptions, SetOptions}; +export type {OnyxUpdate, ConnectOptions, ExportStateOptions, SetOptions}; diff --git a/lib/index.ts b/lib/index.ts index bb6df0e0c..5c3d1073c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -import type {ConnectOptions, OnyxUpdate} from './Onyx'; +import type {ConnectOptions, ExportStateOptions, OnyxUpdate} from './Onyx'; import Onyx from './Onyx'; import type { CustomTypeOptions, @@ -28,6 +28,7 @@ export {useOnyx}; export type { ConnectOptions, CustomTypeOptions, + ExportStateOptions, FetchStatus, KeyValueMapping, NullishDeep, diff --git a/lib/types.ts b/lib/types.ts index 96f130813..93a2cee96 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -327,6 +327,14 @@ type SetOptions = { skipCacheCheck?: boolean; }; +/** + * Represents the options used in `Onyx.exportState()` method. + */ +type ExportStateOptions = { + /** Include persisted rows for keys that are now RAM-only. Defaults to false. */ + includeStaleRamOnlyKeys?: boolean; +}; + type SetParams = { key: TKey; value: OnyxSetInput; @@ -431,6 +439,7 @@ export type { DeepRecord, DefaultConnectCallback, ExtractOnyxCollectionValue, + ExportStateOptions, GenericFunction, InitOptions, Key, diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index d083e7d62..00e902642 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -77,6 +77,15 @@ describe('Onyx', () => { expect(state).not.toHaveProperty(ONYX_KEYS.RAM_ONLY_TEST_KEY); }); + it('exports persisted collection members', async () => { + const collectionMemberKey = `${ONYX_KEYS.COLLECTION.TEST_KEY}1`; + await Onyx.set(collectionMemberKey, {nested: 'value'}); + + const state = await Onyx.exportState(); + + expect(state[collectionMemberKey]).toEqual({nested: 'value'}); + }); + it('propagates storage read failures', async () => { const error = new Error('Storage read failed'); jest.mocked(StorageMock.getAll).mockRejectedValueOnce(error); @@ -3382,6 +3391,20 @@ describe('Onyx.init', () => { expect(cache.get(`${ONYX_KEYS.COLLECTION.TEST_KEY}entry1`)).toEqual('test_1'); }); + + it('exportState', async () => { + await StorageMock.setItem(ONYX_KEYS.TEST_KEY, 'persisted'); + jest.mocked(StorageMock.getAll).mockClear(); + + const exportPromise = Onyx.exportState(); + await act(async () => waitForPromisesToResolve()); + + expect(StorageMock.getAll).not.toHaveBeenCalled(); + + Onyx.init({keys: ONYX_KEYS}); + + await expect(exportPromise).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted'}); + }); }); }); From a9da3cebefefaeb3f3fe0381cd2bf92a5fbd33c2 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sat, 19 Sep 2026 14:02:01 +0200 Subject: [PATCH 7/7] refactor: always exclude RAM-only keys from state export --- API.md | 10 ++-------- README.md | 2 +- lib/Onyx.ts | 9 +++------ lib/index.ts | 3 +-- lib/types.ts | 9 --------- tests/unit/onyxTest.ts | 12 +----------- 6 files changed, 8 insertions(+), 37 deletions(-) diff --git a/API.md b/API.md index 8bc4cb445..234d7ceed 100644 --- a/API.md +++ b/API.md @@ -58,7 +58,7 @@ value will be saved to storage after the default value.

Sets a collection by replacing all existing collection members with new values. Any existing collection members not included in the new data will be removed.

-
exportState([options])
+
exportState()

Returns persisted Onyx key-value pairs as a plain object. Live RAM-only values and writes that have not reached storage are not included. Treat the returned object and its nested values as read-only.

@@ -264,15 +264,9 @@ Onyx.setCollection(ONYXKEYS.COLLECTION.REPORT, { ``` -## exportState([options]) +## exportState() Returns persisted Onyx key-value pairs as a plain object. Live RAM-only values and writes that have not reached storage are not included. Treat the returned object and its nested values as read-only. **Kind**: global function - -| Param | Default | Description | -| --- | --- | --- | -| [options] | | Export options. | -| [options.includeStaleRamOnlyKeys] | false | Include persisted rows for keys that are now RAM-only. | - diff --git a/README.md b/README.md index 399fe8d8d..d65563cf1 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ function signOut() { ## Export persisted state -`Onyx.exportState()` returns a plain object containing persisted keys and values from the active storage provider. It works on native and web without opening another database connection. By default, it excludes stale persisted rows for keys that are now RAM-only. Pass `{includeStaleRamOnlyKeys: true}` only when a diagnostic export must retain legacy rows from before a key became RAM-only, such as when matching a raw storage export. Current RAM-only values and writes still in progress are never included. Treat the returned object and its nested values as read-only because some providers return references to their stored values. The result can contain sensitive data; callers should redact it before sharing. +`Onyx.exportState()` returns a plain object containing persisted keys and values from the active storage provider. It works on native and web without opening another database connection. The export excludes stale persisted rows for keys that are now RAM-only. Current RAM-only values and writes still in progress are never included. Treat the returned object and its nested values as read-only because some providers return references to their stored values. The result can contain sensitive data; callers should redact it before sharing. ## Storage Providers `Onyx.get`, `Onyx.set`, and the rest of the API accesses the underlying storage diff --git a/lib/Onyx.ts b/lib/Onyx.ts index 81de47d34..aeeabb214 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -6,7 +6,6 @@ import DevTools, {initDevTools} from './DevTools'; import type { CollectionKeyBase, ConnectOptions, - ExportStateOptions, InitOptions, KeyValueMapping, MixedOperationsQueue, @@ -616,16 +615,14 @@ function setCollection(collectionKey: TKey, coll * Returns persisted Onyx key-value pairs as a plain object. * Live RAM-only values and writes that have not reached storage are not included. * Treat the returned object and its nested values as read-only. - * @param [options] Export options. - * @param [options.includeStaleRamOnlyKeys=false] Include persisted rows for keys that are now RAM-only. */ -function exportState({includeStaleRamOnlyKeys = false}: ExportStateOptions = {}): Promise>> { +function exportState(): Promise>> { return OnyxUtils.afterInit(() => Storage.getAll().then((entries) => { const state: Record> = {}; for (const [key, value] of entries) { - if (!includeStaleRamOnlyKeys && OnyxKeys.isRamOnlyKey(key)) { + if (OnyxKeys.isRamOnlyKey(key)) { continue; } state[key] = value; @@ -654,4 +651,4 @@ const Onyx = { }; export default Onyx; -export type {OnyxUpdate, ConnectOptions, ExportStateOptions, SetOptions}; +export type {OnyxUpdate, ConnectOptions, SetOptions}; diff --git a/lib/index.ts b/lib/index.ts index 5c3d1073c..bb6df0e0c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -import type {ConnectOptions, ExportStateOptions, OnyxUpdate} from './Onyx'; +import type {ConnectOptions, OnyxUpdate} from './Onyx'; import Onyx from './Onyx'; import type { CustomTypeOptions, @@ -28,7 +28,6 @@ export {useOnyx}; export type { ConnectOptions, CustomTypeOptions, - ExportStateOptions, FetchStatus, KeyValueMapping, NullishDeep, diff --git a/lib/types.ts b/lib/types.ts index 93a2cee96..96f130813 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -327,14 +327,6 @@ type SetOptions = { skipCacheCheck?: boolean; }; -/** - * Represents the options used in `Onyx.exportState()` method. - */ -type ExportStateOptions = { - /** Include persisted rows for keys that are now RAM-only. Defaults to false. */ - includeStaleRamOnlyKeys?: boolean; -}; - type SetParams = { key: TKey; value: OnyxSetInput; @@ -439,7 +431,6 @@ export type { DeepRecord, DefaultConnectCallback, ExtractOnyxCollectionValue, - ExportStateOptions, GenericFunction, InitOptions, Key, diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index 00e902642..a80d28420 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -93,17 +93,7 @@ describe('Onyx', () => { await expect(Onyx.exportState()).rejects.toBe(error); }); - it('includes stale persisted RAM-only values when requested without using current RAM-only values', async () => { - await Onyx.set(ONYX_KEYS.RAM_ONLY_TEST_KEY, 'current'); - jest.mocked(StorageMock.getAll).mockResolvedValueOnce([ - [ONYX_KEYS.TEST_KEY, 'persisted'], - [ONYX_KEYS.RAM_ONLY_TEST_KEY, 'stale'], - ]); - - await expect(Onyx.exportState({includeStaleRamOnlyKeys: true})).resolves.toEqual({[ONYX_KEYS.TEST_KEY]: 'persisted', [ONYX_KEYS.RAM_ONLY_TEST_KEY]: 'stale'}); - }); - - it('excludes stale persisted RAM-only values by default', async () => { + it('excludes stale persisted RAM-only values', async () => { const staleCollectionMember = `${ONYX_KEYS.COLLECTION.RAM_ONLY_COLLECTION}1`; jest.mocked(StorageMock.getAll).mockResolvedValueOnce([ [ONYX_KEYS.TEST_KEY, 'persisted'],