react-native-onyx 3.0.115 → 3.0.117

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.
@@ -1,6 +1,6 @@
1
1
  import type { ValueOf } from 'type-fest';
2
2
  import type Onyx from './Onyx';
3
- import type { CollectionKeyBase, ConnectOptions, DeepRecord, KeyValueMapping, CallbackToStateMapping, MultiMergeReplaceNullPatches, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, MergeCollectionWithPatchesParams, SetCollectionParams, SetParams, OnyxMultiSetInput, RetriableOnyxOperation } from './types';
3
+ import type { CollectionKeyBase, DeepRecord, KeyValueMapping, MultiMergeReplaceNullPatches, OnyxCollection, OnyxEntry, OnyxInput, OnyxKey, OnyxMergeCollectionInput, OnyxUpdate, OnyxValue, Selector, MergeCollectionWithPatchesParams, SetCollectionParams, SetParams, OnyxMultiSetInput, RetriableOnyxOperation } from './types';
4
4
  import type { FastMergeResult } from './utils';
5
5
  import type { DeferredTask } from './createDeferredTask';
6
6
  import type { StorageKeyValuePair } from './storage/providers/types';
@@ -98,45 +98,22 @@ declare function multiGet<TKey extends OnyxKey>(keys: CollectionKeyBase[]): Prom
98
98
  declare function tupleGet<Keys extends readonly OnyxKey[]>(keys: Keys): Promise<{
99
99
  [Index in keyof Keys]: OnyxValue<Keys[Index]>;
100
100
  }>;
101
- /**
102
- * Stores a subscription ID associated with a given key.
103
- *
104
- * @param subscriptionID - A subscription ID of the subscriber.
105
- * @param key - A key that the subscriber is subscribed to.
106
- */
107
- declare function storeKeyBySubscriptions(key: OnyxKey, subscriptionID: number): void;
108
- /**
109
- * Deletes a subscription ID associated with its corresponding key.
110
- *
111
- * @param subscriptionID - The subscription ID to be deleted.
112
- */
113
- declare function deleteKeyBySubscriptions(subscriptionID: number): void;
114
101
  /** Returns current key names stored in persisted storage */
115
102
  declare function getAllKeys(): Promise<Set<OnyxKey>>;
116
- /**
117
- * Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
118
- * If the requested key is a collection, it will return an object with all the collection members.
119
- */
120
- declare function tryGetCachedValue<TKey extends OnyxKey>(key: TKey): OnyxValue<OnyxKey>;
121
103
  declare function getCachedCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, collectionMemberKeys?: string[]): NonNullable<OnyxCollection<KeyValueMapping[TKey]>>;
122
104
  /**
123
- * When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks
124
- */
125
- declare function keysChanged<TKey extends CollectionKeyBase>(collectionKey: TKey, partialCollection: OnyxCollection<KeyValueMapping[TKey]>, partialPreviousCollection: OnyxCollection<KeyValueMapping[TKey]> | undefined): void;
126
- /**
127
- * When a key change happens, search for any callbacks matching the key or collection key and trigger those callbacks
105
+ * Notify subscribers of a single-key write. Wrapper over `onyxSubscriptionManager.notifyKey()`
106
+ * that also performs LRU bookkeeping for eviction.
128
107
  */
129
- declare function keyChanged<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: CallbackToStateMapping<OnyxKey>) => boolean): void;
108
+ declare function notifyKey<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>): void;
130
109
  /**
131
- * Sends the data obtained from the keys to the connection.
110
+ * Notify subscribers of a batch collection update. Wrapper over
111
+ * `onyxSubscriptionManager.notifyCollection()` that also performs LRU bookkeeping per
112
+ * changed member.
132
113
  */
133
- declare function sendDataToConnection<TKey extends OnyxKey>(mapping: CallbackToStateMapping<TKey>, matchedKey: TKey | undefined): void;
114
+ declare function notifyCollection<TKey extends CollectionKeyBase>(collectionKey: TKey, partialCollection: OnyxCollection<KeyValueMapping[TKey]>, partialPreviousCollection?: OnyxCollection<KeyValueMapping[TKey]>): void;
134
115
  /**
135
- * Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
136
- */
137
- declare function getCollectionDataAndSendAsObject<TKey extends OnyxKey>(matchingKeys: CollectionKeyBase[], mapping: CallbackToStateMapping<TKey>): void;
138
- /**
139
- * Remove a key from Onyx and update the subscribers
116
+ * Remove a key from Onyx and update the subscribers.
140
117
  */
141
118
  declare function remove<TKey extends OnyxKey>(key: TKey): Promise<void>;
142
119
  declare function reportStorageQuota(error?: Error): Promise<void>;
@@ -164,6 +141,10 @@ declare function retryOperation<TMethod extends RetriableOnyxOperation>(error: E
164
141
  */
165
142
  declare function broadcastUpdate<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, hasChanged?: boolean): void;
166
143
  declare function hasPendingMergeForKey(key: OnyxKey): boolean;
144
+ type PendingMergeEntry = [OnyxKey, Array<OnyxValue<OnyxKey>>, number];
145
+ declare function getPendingMergeEntries(keysToPreserve: OnyxKey[]): PendingMergeEntry[];
146
+ declare function cancelPendingMerges(entries: PendingMergeEntry[]): void;
147
+ declare function hasStaleMergeRead(queuedChanges: Array<OnyxValue<OnyxKey>>): boolean;
167
148
  /**
168
149
  * Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]]
169
150
  * This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue}
@@ -198,19 +179,6 @@ declare function isValidNonEmptyCollectionForMerge<TKey extends CollectionKeyBas
198
179
  * Verify if all the collection keys belong to the same parent
199
180
  */
200
181
  declare function doAllCollectionItemsBelongToSameParent<TKey extends CollectionKeyBase>(collectionKey: TKey, collectionKeys: string[]): boolean;
201
- /**
202
- * Subscribes to an Onyx key and listens to its changes.
203
- *
204
- * @param connectOptions The options object that will define the behavior of the connection.
205
- * @returns The subscription ID to use when calling `OnyxUtils.unsubscribeFromKey()`.
206
- */
207
- declare function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKey>): number;
208
- /**
209
- * Disconnects and removes the listener from the Onyx key.
210
- *
211
- * @param subscriptionID Subscription ID returned by calling `OnyxUtils.subscribeToKey()`.
212
- */
213
- declare function unsubscribeFromKey(subscriptionID: number): void;
214
182
  declare function updateSnapshots<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>, mergeFn: typeof Onyx.merge): Array<() => Promise<void>>;
215
183
  /**
216
184
  * Writes a value to our store with the given key.
@@ -271,6 +239,10 @@ declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase>({ co
271
239
  declare function partialSetCollection<TKey extends CollectionKeyBase>({ collectionKey, collection }: SetCollectionParams<TKey>, retryAttempt?: number): Promise<void>;
272
240
  declare function logKeyChanged(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey, value: unknown, hasChanged: boolean): void;
273
241
  declare function logKeyRemoved(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey): void;
242
+ /**
243
+ * Put Onyx back to "not initialised" state, useful for tests that need a cold start.
244
+ */
245
+ declare function resetDeferredInitTask(): void;
274
246
  /**
275
247
  * Clear internal variables used in this file, useful in test environments.
276
248
  */
@@ -284,6 +256,7 @@ declare const OnyxUtils: {
284
256
  readonly MULTI_SET: "multiset";
285
257
  readonly CLEAR: "clear";
286
258
  };
259
+ NOT_DELIVERED: symbol;
287
260
  getMergeQueue: typeof getMergeQueue;
288
261
  getMergeQueuePromise: typeof getMergeQueuePromise;
289
262
  getDefaultKeyStates: typeof getDefaultKeyStates;
@@ -293,18 +266,18 @@ declare const OnyxUtils: {
293
266
  sendActionToDevTools: typeof sendActionToDevTools;
294
267
  get: typeof get;
295
268
  getAllKeys: typeof getAllKeys;
296
- tryGetCachedValue: typeof tryGetCachedValue;
297
269
  getCachedCollection: typeof getCachedCollection;
298
- keysChanged: typeof keysChanged;
299
- keyChanged: typeof keyChanged;
300
- sendDataToConnection: typeof sendDataToConnection;
301
- getCollectionDataAndSendAsObject: typeof getCollectionDataAndSendAsObject;
270
+ notifyKey: typeof notifyKey;
271
+ notifyCollection: typeof notifyCollection;
302
272
  remove: typeof remove;
303
273
  reportStorageQuota: typeof reportStorageQuota;
304
274
  resetDiskPressureLogThrottle: typeof resetDiskPressureLogThrottle;
305
275
  retryOperation: typeof retryOperation;
306
276
  broadcastUpdate: typeof broadcastUpdate;
307
277
  hasPendingMergeForKey: typeof hasPendingMergeForKey;
278
+ getPendingMergeEntries: typeof getPendingMergeEntries;
279
+ cancelPendingMerges: typeof cancelPendingMerges;
280
+ hasStaleMergeRead: typeof hasStaleMergeRead;
308
281
  prepareKeyValuePairsForStorage: typeof prepareKeyValuePairsForStorage;
309
282
  mergeChanges: typeof mergeChanges;
310
283
  mergeAndMarkChanges: typeof mergeAndMarkChanges;
@@ -314,14 +287,10 @@ declare const OnyxUtils: {
314
287
  tupleGet: typeof tupleGet;
315
288
  isValidNonEmptyCollectionForMerge: typeof isValidNonEmptyCollectionForMerge;
316
289
  doAllCollectionItemsBelongToSameParent: typeof doAllCollectionItemsBelongToSameParent;
317
- subscribeToKey: typeof subscribeToKey;
318
- unsubscribeFromKey: typeof unsubscribeFromKey;
319
290
  getSkippableCollectionMemberIDs: typeof getSkippableCollectionMemberIDs;
320
291
  setSkippableCollectionMemberIDs: typeof setSkippableCollectionMemberIDs;
321
292
  getSnapshotMergeKeys: typeof getSnapshotMergeKeys;
322
293
  setSnapshotMergeKeys: typeof setSnapshotMergeKeys;
323
- storeKeyBySubscriptions: typeof storeKeyBySubscriptions;
324
- deleteKeyBySubscriptions: typeof deleteKeyBySubscriptions;
325
294
  reduceCollectionWithSelector: typeof reduceCollectionWithSelector;
326
295
  updateSnapshots: typeof updateSnapshots;
327
296
  mergeCollectionWithPatches: typeof mergeCollectionWithPatches;
@@ -334,4 +303,4 @@ declare const OnyxUtils: {
334
303
  };
335
304
  export type { OnyxMethod };
336
305
  export default OnyxUtils;
337
- export { clearOnyxUtilsInternals };
306
+ export { clearOnyxUtilsInternals, resetDeferredInitTask };