react-native-onyx 3.0.116 → 3.0.118

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>;
@@ -202,19 +179,6 @@ declare function isValidNonEmptyCollectionForMerge<TKey extends CollectionKeyBas
202
179
  * Verify if all the collection keys belong to the same parent
203
180
  */
204
181
  declare function doAllCollectionItemsBelongToSameParent<TKey extends CollectionKeyBase>(collectionKey: TKey, collectionKeys: string[]): boolean;
205
- /**
206
- * Subscribes to an Onyx key and listens to its changes.
207
- *
208
- * @param connectOptions The options object that will define the behavior of the connection.
209
- * @returns The subscription ID to use when calling `OnyxUtils.unsubscribeFromKey()`.
210
- */
211
- declare function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOptions<TKey>): number;
212
- /**
213
- * Disconnects and removes the listener from the Onyx key.
214
- *
215
- * @param subscriptionID Subscription ID returned by calling `OnyxUtils.subscribeToKey()`.
216
- */
217
- declare function unsubscribeFromKey(subscriptionID: number): void;
218
182
  declare function updateSnapshots<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>, mergeFn: typeof Onyx.merge): Array<() => Promise<void>>;
219
183
  /**
220
184
  * Writes a value to our store with the given key.
@@ -275,6 +239,10 @@ declare function mergeCollectionWithPatches<TKey extends CollectionKeyBase>({ co
275
239
  declare function partialSetCollection<TKey extends CollectionKeyBase>({ collectionKey, collection }: SetCollectionParams<TKey>, retryAttempt?: number): Promise<void>;
276
240
  declare function logKeyChanged(onyxMethod: Extract<OnyxMethod, 'set' | 'merge'>, key: OnyxKey, value: unknown, hasChanged: boolean): void;
277
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;
278
246
  /**
279
247
  * Clear internal variables used in this file, useful in test environments.
280
248
  */
@@ -288,6 +256,7 @@ declare const OnyxUtils: {
288
256
  readonly MULTI_SET: "multiset";
289
257
  readonly CLEAR: "clear";
290
258
  };
259
+ NOT_DELIVERED: symbol;
291
260
  getMergeQueue: typeof getMergeQueue;
292
261
  getMergeQueuePromise: typeof getMergeQueuePromise;
293
262
  getDefaultKeyStates: typeof getDefaultKeyStates;
@@ -297,12 +266,9 @@ declare const OnyxUtils: {
297
266
  sendActionToDevTools: typeof sendActionToDevTools;
298
267
  get: typeof get;
299
268
  getAllKeys: typeof getAllKeys;
300
- tryGetCachedValue: typeof tryGetCachedValue;
301
269
  getCachedCollection: typeof getCachedCollection;
302
- keysChanged: typeof keysChanged;
303
- keyChanged: typeof keyChanged;
304
- sendDataToConnection: typeof sendDataToConnection;
305
- getCollectionDataAndSendAsObject: typeof getCollectionDataAndSendAsObject;
270
+ notifyKey: typeof notifyKey;
271
+ notifyCollection: typeof notifyCollection;
306
272
  remove: typeof remove;
307
273
  reportStorageQuota: typeof reportStorageQuota;
308
274
  resetDiskPressureLogThrottle: typeof resetDiskPressureLogThrottle;
@@ -321,14 +287,10 @@ declare const OnyxUtils: {
321
287
  tupleGet: typeof tupleGet;
322
288
  isValidNonEmptyCollectionForMerge: typeof isValidNonEmptyCollectionForMerge;
323
289
  doAllCollectionItemsBelongToSameParent: typeof doAllCollectionItemsBelongToSameParent;
324
- subscribeToKey: typeof subscribeToKey;
325
- unsubscribeFromKey: typeof unsubscribeFromKey;
326
290
  getSkippableCollectionMemberIDs: typeof getSkippableCollectionMemberIDs;
327
291
  setSkippableCollectionMemberIDs: typeof setSkippableCollectionMemberIDs;
328
292
  getSnapshotMergeKeys: typeof getSnapshotMergeKeys;
329
293
  setSnapshotMergeKeys: typeof setSnapshotMergeKeys;
330
- storeKeyBySubscriptions: typeof storeKeyBySubscriptions;
331
- deleteKeyBySubscriptions: typeof deleteKeyBySubscriptions;
332
294
  reduceCollectionWithSelector: typeof reduceCollectionWithSelector;
333
295
  updateSnapshots: typeof updateSnapshots;
334
296
  mergeCollectionWithPatches: typeof mergeCollectionWithPatches;
@@ -341,4 +303,4 @@ declare const OnyxUtils: {
341
303
  };
342
304
  export type { OnyxMethod };
343
305
  export default OnyxUtils;
344
- export { clearOnyxUtilsInternals };
306
+ export { clearOnyxUtilsInternals, resetDeferredInitTask };