react-native-onyx 3.0.87 → 3.0.89
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/API.md +0 -2
- package/README.md +2 -12
- package/dist/CircuitBreaker/AbstractCircuitBreaker.d.ts +91 -0
- package/dist/CircuitBreaker/AbstractCircuitBreaker.js +166 -0
- package/dist/CircuitBreaker/types.d.ts +38 -0
- package/dist/CircuitBreaker/types.js +24 -0
- package/dist/Onyx.d.ts +0 -2
- package/dist/Onyx.js +0 -2
- package/dist/OnyxConnectionManager.js +18 -15
- package/dist/OnyxUtils.d.ts +11 -5
- package/dist/OnyxUtils.js +92 -82
- package/dist/StateMachine.d.ts +45 -0
- package/dist/StateMachine.js +37 -0
- package/dist/StorageCircuitBreaker.d.ts +66 -0
- package/dist/StorageCircuitBreaker.js +177 -0
- package/dist/storage/__mocks__/index.d.ts +10 -0
- package/dist/storage/__mocks__/index.js +15 -0
- package/dist/storage/errors.d.ts +34 -0
- package/dist/storage/errors.js +41 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/providers/IDBKeyValProvider/classifyError.d.ts +9 -0
- package/dist/storage/providers/IDBKeyValProvider/classifyError.js +37 -0
- package/dist/storage/providers/IDBKeyValProvider/createStore.js +40 -57
- package/dist/storage/providers/IDBKeyValProvider/index.js +5 -0
- package/dist/storage/providers/MemoryOnlyProvider.js +5 -0
- package/dist/storage/providers/NoopProvider.js +5 -0
- package/dist/storage/providers/SQLiteProvider.js +5 -0
- package/dist/storage/providers/classifySQLiteError.d.ts +13 -0
- package/dist/storage/providers/classifySQLiteError.js +21 -0
- package/dist/storage/providers/types.d.ts +8 -0
- package/dist/types.d.ts +11 -27
- package/dist/useOnyx.js +0 -2
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { ValueOf } from 'type-fest';
|
|
1
2
|
import type { OnyxKey, OnyxValue } from '../../types';
|
|
2
3
|
import type { FastMergeReplaceNullPatch } from '../../utils';
|
|
4
|
+
import type { StorageErrorClass } from '../errors';
|
|
3
5
|
type StorageKeyValuePair = [key: OnyxKey, value: OnyxValue<OnyxKey>, replaceNullPatches?: FastMergeReplaceNullPatch[]];
|
|
4
6
|
type StorageKeyList = OnyxKey[];
|
|
5
7
|
type DatabaseSize = {
|
|
@@ -68,6 +70,12 @@ type StorageProvider<TStore> = {
|
|
|
68
70
|
* Gets the total bytes of the database file
|
|
69
71
|
*/
|
|
70
72
|
getDatabaseSize: () => Promise<DatabaseSize>;
|
|
73
|
+
/**
|
|
74
|
+
* Classifies a write error from THIS engine into the shared {@link StorageErrorClass} taxonomy.
|
|
75
|
+
* Each provider owns its own matchers (IndexedDB DOMExceptions, SQLite messages, …) so the central
|
|
76
|
+
* taxonomy stays engine-agnostic. Anything the provider doesn't recognize must return UNKNOWN.
|
|
77
|
+
*/
|
|
78
|
+
classifyError: (error: unknown) => ValueOf<typeof StorageErrorClass>;
|
|
71
79
|
/**
|
|
72
80
|
* @param onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
|
|
73
81
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -188,36 +188,20 @@ type BaseConnectOptions = {
|
|
|
188
188
|
type DefaultConnectCallback<TKey extends OnyxKey> = (value: OnyxEntry<KeyValueMapping[TKey]>, key: TKey) => void;
|
|
189
189
|
/** Represents the callback function used in `Onyx.connect()` method with a collection key. */
|
|
190
190
|
type CollectionConnectCallback<TKey extends OnyxKey> = (value: NonUndefined<OnyxCollection<KeyValueMapping[TKey]>>, key: TKey, sourceValue?: OnyxValue<TKey>) => void;
|
|
191
|
-
/** Represents the options used in `Onyx.connect()` method with a regular key. */
|
|
192
|
-
type DefaultConnectOptions<TKey extends OnyxKey> = BaseConnectOptions & {
|
|
193
|
-
/** The Onyx key to subscribe to. */
|
|
194
|
-
key: TKey;
|
|
195
|
-
/** A function that will be called when the Onyx data we are subscribed changes. */
|
|
196
|
-
callback?: DefaultConnectCallback<TKey>;
|
|
197
|
-
/** If set to `true`, it will return the entire collection to the callback as a single object. */
|
|
198
|
-
waitForCollectionCallback?: false;
|
|
199
|
-
};
|
|
200
|
-
/** Represents the options used in `Onyx.connect()` method with a collection key. */
|
|
201
|
-
type CollectionConnectOptions<TKey extends OnyxKey> = BaseConnectOptions & {
|
|
202
|
-
/** The Onyx key to subscribe to. */
|
|
203
|
-
key: TKey extends CollectionKeyBase ? TKey : never;
|
|
204
|
-
/** A function that will be called when the Onyx data we are subscribed changes. */
|
|
205
|
-
callback?: CollectionConnectCallback<TKey>;
|
|
206
|
-
/** If set to `true`, it will return the entire collection to the callback as a single object. */
|
|
207
|
-
waitForCollectionCallback: true;
|
|
208
|
-
};
|
|
209
191
|
/**
|
|
210
192
|
* Represents the options used in `Onyx.connect()` method.
|
|
211
|
-
* The type is built from `DefaultConnectOptions`/`CollectionConnectOptions` depending on the `waitForCollectionCallback` property.
|
|
212
|
-
* It includes two different forms, depending on whether we are waiting for a collection callback or not.
|
|
213
|
-
*
|
|
214
|
-
* If `waitForCollectionCallback` is `true`, it expects `key` to be a Onyx collection key and `callback` will be triggered with the whole collection
|
|
215
|
-
* and will pass `value` as an `OnyxCollection`.
|
|
216
193
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
194
|
+
* For a collection root key (e.g. `ONYXKEYS.COLLECTION.REPORT`), the callback fires
|
|
195
|
+
* with the entire collection object whenever any member changes (signature
|
|
196
|
+
* `(collection, key, sourceValue)`). For any other key, the callback fires with the value at
|
|
197
|
+
* that key (signature `(value, key)`).
|
|
219
198
|
*/
|
|
220
|
-
type ConnectOptions<TKey extends OnyxKey> =
|
|
199
|
+
type ConnectOptions<TKey extends OnyxKey> = BaseConnectOptions & {
|
|
200
|
+
/** The Onyx key to subscribe to. */
|
|
201
|
+
key: TKey;
|
|
202
|
+
/** A function that will be called when the Onyx data we are subscribed changes. */
|
|
203
|
+
callback?: (value: TKey extends CollectionKeyBase ? NonUndefined<OnyxCollection<KeyValueMapping[TKey]>> : OnyxEntry<KeyValueMapping[TKey]>, key: TKey, sourceValue?: TKey extends CollectionKeyBase ? NonUndefined<OnyxCollection<KeyValueMapping[TKey]>> : never) => void;
|
|
204
|
+
};
|
|
221
205
|
type CallbackToStateMapping<TKey extends OnyxKey> = ConnectOptions<TKey> & {
|
|
222
206
|
subscriptionID: number;
|
|
223
207
|
};
|
|
@@ -379,4 +363,4 @@ type MixedOperationsQueue = {
|
|
|
379
363
|
mergeReplaceNullPatches: MultiMergeReplaceNullPatches;
|
|
380
364
|
set: OnyxInputKeyValueMapping;
|
|
381
365
|
};
|
|
382
|
-
export type { BaseConnectOptions, Collection, CollectionConnectCallback,
|
|
366
|
+
export type { BaseConnectOptions, Collection, CollectionConnectCallback, CollectionKey, CollectionKeyBase, ConnectOptions, CustomTypeOptions, DeepRecord, DefaultConnectCallback, ExtractOnyxCollectionValue, GenericFunction, InitOptions, Key, KeyValueMapping, CallbackToStateMapping, NonNull, NonUndefined, OnyxInputKeyValueMapping, NullishDeep, OnyxCollection, OnyxEntry, OnyxKey, OnyxInputValue, OnyxCollectionInputValue, OnyxInput, OnyxSetInput, OnyxMultiSetInput, OnyxMergeInput, OnyxMergeCollectionInput, OnyxSetCollectionInput, OnyxMethod, OnyxMethodMap, OnyxUpdate, OnyxValue, Selector, SetOptions, SetParams, SetCollectionParams, MergeCollectionWithPatchesParams, MultiMergeReplaceNullPatches, MixedOperationsQueue, RetriableOnyxOperation, };
|
package/dist/useOnyx.js
CHANGED
|
@@ -41,7 +41,6 @@ const react_1 = require("react");
|
|
|
41
41
|
const OnyxCache_1 = __importStar(require("./OnyxCache"));
|
|
42
42
|
const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
|
|
43
43
|
const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
|
|
44
|
-
const OnyxKeys_1 = __importDefault(require("./OnyxKeys"));
|
|
45
44
|
const OnyxSnapshotCache_1 = __importDefault(require("./OnyxSnapshotCache"));
|
|
46
45
|
const useLiveRef_1 = __importDefault(require("./useLiveRef"));
|
|
47
46
|
function useOnyx(key, options, dependencies = []) {
|
|
@@ -232,7 +231,6 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
232
231
|
// Finally, we signal that the store changed, making `getSnapshot()` be called again.
|
|
233
232
|
onStoreChange();
|
|
234
233
|
},
|
|
235
|
-
waitForCollectionCallback: OnyxKeys_1.default.isCollectionKey(key),
|
|
236
234
|
reuseConnection: options === null || options === void 0 ? void 0 : options.reuseConnection,
|
|
237
235
|
});
|
|
238
236
|
return () => {
|