import type { ValueOf } from 'type-fest'; import type Onyx from './Onyx'; import type { CollectionKey, CollectionKeyBase, ConnectOptions, DeepRecord, KeyValueMapping, Mapping, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxMergeCollectionInput, OnyxValue } from './types'; import type { DeferredTask } from './createDeferredTask'; declare const METHOD: { readonly SET: "set"; readonly MERGE: "merge"; readonly MERGE_COLLECTION: "mergecollection"; readonly SET_COLLECTION: "setcollection"; readonly MULTI_SET: "multiset"; readonly CLEAR: "clear"; }; type OnyxMethod = ValueOf; declare function getSnapshotKey(): OnyxKey | null; /** * Getter - returns the merge queue. */ declare function getMergeQueue(): Record>>; /** * Getter - returns the merge queue promise. */ declare function getMergeQueuePromise(): Record>; /** * Getter - returns the default key states. */ declare function getDefaultKeyStates(): Record>; /** * Getter - returns the deffered init task. */ declare function getDeferredInitTask(): DeferredTask; /** * Getter - returns the eviction block list. */ declare function getEvictionBlocklist(): Record; /** * Sets the initial values for the Onyx store * * @param keys - `ONYXKEYS` constants object from Onyx.init() * @param initialKeyStates - initial data to set when `init()` and `clear()` are called * @param safeEvictionKeys - This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal. */ declare function initStoreValues(keys: DeepRecord, initialKeyStates: Partial, safeEvictionKeys: OnyxKey[]): void; /** * Sends an action to DevTools extension * * @param method - Onyx method from METHOD * @param key - Onyx key that was changed * @param value - contains the change that was made by the method * @param mergedValue - (optional) value that was written in the storage after a merge method was executed. */ declare function sendActionToDevTools(method: typeof METHOD.MERGE_COLLECTION | typeof METHOD.MULTI_SET, key: undefined, value: OnyxCollection, mergedValue?: undefined): void; declare function sendActionToDevTools(method: Exclude, key: OnyxKey, value: OnyxEntry, mergedValue?: OnyxEntry): void; /** * We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other. * This happens for example in the Onyx.update function, where we process API responses that might contain a lot of * update operations. Instead of calling the subscribers for each update operation, we batch them together which will * cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization. */ declare function maybeFlushBatchUpdates(): Promise; declare function batchUpdates(updates: () => void): Promise; /** Get some data from the store */ declare function get>(key: TKey): Promise; declare function multiGet(keys: CollectionKeyBase[]): Promise>>; /** Returns current key names stored in persisted storage */ declare function getAllKeys(): Promise>; /** * Returns set of all registered collection keys */ declare function getCollectionKeys(): Set; /** * Checks to see if the subscriber's supplied key * is associated with a collection of keys. */ declare function isCollectionKey(key: OnyxKey): key is CollectionKeyBase; declare function isCollectionMemberKey(collectionKey: TCollectionKey, key: string, collectionKeyLength: number): key is `${TCollectionKey}${string}`; /** * Splits a collection member key into the collection key part and the ID part. * @param key - The collection member key to split. * @returns A tuple where the first element is the collection part and the second element is the ID part, * or throws an Error if the key is not a collection one. */ declare function splitCollectionMemberKey(key: TKey): [CollectionKeyType, string]; /** * Checks to see if a provided key is the exact configured key of our connected subscriber * or if the provided key is a collection member key (in case our configured key is a "collection key") */ declare function isKeyMatch(configKey: OnyxKey, key: OnyxKey): boolean; /** Checks to see if this key has been flagged as safe for removal. */ declare function isSafeEvictionKey(testKey: OnyxKey): boolean; /** * Extracts the collection identifier of a given collection member key. * * For example: * - `getCollectionKey("report_123")` would return "report_" * - `getCollectionKey("report_")` would return "report_" * - `getCollectionKey("report_-1_something")` would return "report_" * - `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_" * * @param key - The collection key to process. * @returns The plain collection key or throws an Error if the key is not a collection one. */ declare function getCollectionKey(key: CollectionKey): string; /** * Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined. * If the requested key is a collection, it will return an object with all the collection members. */ declare function tryGetCachedValue(key: TKey, mapping?: Partial>): OnyxValue; /** * Remove a key from the recently accessed key list. */ declare function removeLastAccessedKey(key: OnyxKey): void; /** * Add a key to the list of recently accessed keys. The least * recently accessed key should be at the head and the most * recently accessed key at the tail. */ declare function addLastAccessedKey(key: OnyxKey): void; /** * Take all the keys that are safe to evict and add them to * the recently accessed list when initializing the app. This * enables keys that have not recently been accessed to be * removed. */ declare function addAllSafeEvictionKeysToRecentlyAccessedList(): Promise; declare function getCachedCollection(collectionKey: TKey, collectionMemberKeys?: string[]): NonNullable>; /** * When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks */ declare function keysChanged(collectionKey: TKey, partialCollection: OnyxCollection, partialPreviousCollection: OnyxCollection | undefined, notifyRegularSubscibers?: boolean, notifyWithOnyxSubscibers?: boolean): void; /** * When a key change happens, search for any callbacks matching the key or collection key and trigger those callbacks * * @example * keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false) */ declare function keyChanged(key: TKey, value: OnyxValue, previousValue: OnyxValue, canUpdateSubscriber?: (subscriber?: Mapping) => boolean, notifyConnectSubscribers?: boolean, notifyWithOnyxSubscribers?: boolean): void; /** * Sends the data obtained from the keys to the connection. It either: * - sets state on the withOnyxInstances * - triggers the callback function */ declare function sendDataToConnection(mapping: Mapping, value: OnyxValue | null, matchedKey: TKey | undefined, isBatched: boolean): void; /** * Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber. */ declare function getCollectionDataAndSendAsObject(matchingKeys: CollectionKeyBase[], mapping: Mapping): void; /** * Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately). * * @example * scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false) */ declare function scheduleSubscriberUpdate(key: TKey, value: OnyxValue, previousValue: OnyxValue, canUpdateSubscriber?: (subscriber?: Mapping) => boolean): Promise; /** * This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections * so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the * subscriber callbacks receive the data in a different format than they normally expect and it breaks code. */ declare function scheduleNotifyCollectionSubscribers(key: TKey, value: OnyxCollection, previousValue?: OnyxCollection): Promise; /** * Remove a key from Onyx and update the subscribers */ declare function remove(key: TKey): Promise; declare function reportStorageQuota(): Promise; /** * If we fail to set or merge we must handle this by * evicting some data from Onyx and then retrying to do * whatever it is we attempted to do. */ declare function evictStorageAndRetry(error: Error, onyxMethod: TMethod, ...args: Parameters): Promise; /** * Notifies subscribers and writes current value to cache */ declare function broadcastUpdate(key: TKey, value: OnyxValue, hasChanged?: boolean): Promise; declare function hasPendingMergeForKey(key: OnyxKey): boolean; type RemoveNullValuesOutput | undefined> = { value: Value; wasRemoved: boolean; }; /** * Removes a key from storage if the value is null. * Otherwise removes all nested null values in objects, * if shouldRemoveNestedNulls is true and returns the object. * * @returns The value without null values and a boolean "wasRemoved", which indicates if the key got removed completely */ declare function removeNullValues | undefined>(key: OnyxKey, value: Value, shouldRemoveNestedNulls?: boolean): RemoveNullValuesOutput; /** * Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]] * This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue} * to an array of key-value pairs in the above format and removes key-value pairs that are being set to null * @return an array of key - value pairs <[key, value]> */ declare function prepareKeyValuePairsForStorage(data: Record>, shouldRemoveNestedNulls: boolean): Array<[OnyxKey, OnyxInput]>; /** * Merges an array of changes with an existing value * * @param changes Array of changes that should be applied to the existing value */ declare function applyMerge | undefined, TChange extends OnyxInput | undefined>(existingValue: TValue, changes: TChange[], shouldRemoveNestedNulls: boolean): TChange; /** * Merge user provided default key value pairs. */ declare function initializeWithDefaultKeyStates(): Promise; /** * Validate the collection is not empty and has a correct type before applying mergeCollection() */ declare function isValidNonEmptyCollectionForMerge(collection: OnyxMergeCollectionInput): boolean; /** * Verify if all the collection keys belong to the same parent */ declare function doAllCollectionItemsBelongToSameParent(collectionKey: TKey, collectionKeys: string[]): boolean; /** * Subscribes to an Onyx key and listens to its changes. * * @param connectOptions The options object that will define the behavior of the connection. * @returns The subscription ID to use when calling `OnyxUtils.unsubscribeFromKey()`. */ declare function subscribeToKey(connectOptions: ConnectOptions): number; /** * Disconnects and removes the listener from the Onyx key. * * @param subscriptionID Subscription ID returned by calling `OnyxUtils.subscribeToKey()`. */ declare function unsubscribeFromKey(subscriptionID: number): void; declare const OnyxUtils: { METHOD: { readonly SET: "set"; readonly MERGE: "merge"; readonly MERGE_COLLECTION: "mergecollection"; readonly SET_COLLECTION: "setcollection"; readonly MULTI_SET: "multiset"; readonly CLEAR: "clear"; }; getMergeQueue: typeof getMergeQueue; getMergeQueuePromise: typeof getMergeQueuePromise; getDefaultKeyStates: typeof getDefaultKeyStates; getDeferredInitTask: typeof getDeferredInitTask; initStoreValues: typeof initStoreValues; sendActionToDevTools: typeof sendActionToDevTools; maybeFlushBatchUpdates: typeof maybeFlushBatchUpdates; batchUpdates: typeof batchUpdates; get: typeof get; getAllKeys: typeof getAllKeys; getCollectionKeys: typeof getCollectionKeys; isCollectionKey: typeof isCollectionKey; isCollectionMemberKey: typeof isCollectionMemberKey; splitCollectionMemberKey: typeof splitCollectionMemberKey; isKeyMatch: typeof isKeyMatch; isSafeEvictionKey: typeof isSafeEvictionKey; tryGetCachedValue: typeof tryGetCachedValue; removeLastAccessedKey: typeof removeLastAccessedKey; addLastAccessedKey: typeof addLastAccessedKey; addAllSafeEvictionKeysToRecentlyAccessedList: typeof addAllSafeEvictionKeysToRecentlyAccessedList; getCachedCollection: typeof getCachedCollection; keysChanged: typeof keysChanged; keyChanged: typeof keyChanged; sendDataToConnection: typeof sendDataToConnection; getCollectionKey: typeof getCollectionKey; getCollectionDataAndSendAsObject: typeof getCollectionDataAndSendAsObject; scheduleSubscriberUpdate: typeof scheduleSubscriberUpdate; scheduleNotifyCollectionSubscribers: typeof scheduleNotifyCollectionSubscribers; remove: typeof remove; reportStorageQuota: typeof reportStorageQuota; evictStorageAndRetry: typeof evictStorageAndRetry; broadcastUpdate: typeof broadcastUpdate; hasPendingMergeForKey: typeof hasPendingMergeForKey; removeNullValues: typeof removeNullValues; prepareKeyValuePairsForStorage: typeof prepareKeyValuePairsForStorage; applyMerge: typeof applyMerge; initializeWithDefaultKeyStates: typeof initializeWithDefaultKeyStates; getSnapshotKey: typeof getSnapshotKey; multiGet: typeof multiGet; isValidNonEmptyCollectionForMerge: typeof isValidNonEmptyCollectionForMerge; doAllCollectionItemsBelongToSameParent: typeof doAllCollectionItemsBelongToSameParent; subscribeToKey: typeof subscribeToKey; unsubscribeFromKey: typeof unsubscribeFromKey; getEvictionBlocklist: typeof getEvictionBlocklist; }; export type { OnyxMethod }; export default OnyxUtils;