react-native-onyx 3.0.84 → 3.0.85
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.
|
@@ -41,6 +41,17 @@ const utils_1 = __importDefault(require("../../../utils"));
|
|
|
41
41
|
const createStore_1 = __importDefault(require("./createStore"));
|
|
42
42
|
const DB_NAME = 'OnyxDB';
|
|
43
43
|
const STORE_NAME = 'keyvaluepairs';
|
|
44
|
+
/**
|
|
45
|
+
* Awaits an IndexedDB write transaction. idb-keyval's promisifyRequest rejects with
|
|
46
|
+
* `transaction.error`, which is `null` for an abort not caused by its own request
|
|
47
|
+
* (connection close / versionchange / a sibling transaction aborting). Normalize that
|
|
48
|
+
* `null` into a tagged AbortError.
|
|
49
|
+
*/
|
|
50
|
+
function promisifyWriteTransaction(transaction) {
|
|
51
|
+
return IDB.promisifyRequest(transaction).catch((error) => {
|
|
52
|
+
throw error !== null && error !== void 0 ? error : new DOMException('IDB write transaction aborted without an error', 'AbortError');
|
|
53
|
+
});
|
|
54
|
+
}
|
|
44
55
|
const provider = {
|
|
45
56
|
// We don't want to initialize the store while the JS bundle loads as idb-keyval will try to use global.indexedDB
|
|
46
57
|
// which might not be available in certain environments that load the bundle (e.g. electron main process).
|
|
@@ -66,7 +77,13 @@ const provider = {
|
|
|
66
77
|
if (value === null) {
|
|
67
78
|
return provider.removeItem(key);
|
|
68
79
|
}
|
|
69
|
-
|
|
80
|
+
// Drive the write through the manual store transaction so promisifyWriteTransaction can
|
|
81
|
+
// normalize a null abort error — idb-keyval's IDB.set() awaits the raw transaction and
|
|
82
|
+
// would propagate the unclassifiable "Error: null".
|
|
83
|
+
return provider.store('readwrite', (store) => {
|
|
84
|
+
store.put(value, key);
|
|
85
|
+
return promisifyWriteTransaction(store.transaction);
|
|
86
|
+
});
|
|
70
87
|
},
|
|
71
88
|
multiGet(keysParam) {
|
|
72
89
|
if (!provider.store) {
|
|
@@ -95,7 +112,7 @@ const provider = {
|
|
|
95
112
|
store.put(newValue, key);
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
|
-
return
|
|
115
|
+
return promisifyWriteTransaction(store.transaction);
|
|
99
116
|
});
|
|
100
117
|
});
|
|
101
118
|
},
|
|
@@ -116,7 +133,7 @@ const provider = {
|
|
|
116
133
|
store.put(value, key);
|
|
117
134
|
}
|
|
118
135
|
}
|
|
119
|
-
return
|
|
136
|
+
return promisifyWriteTransaction(store.transaction);
|
|
120
137
|
});
|
|
121
138
|
},
|
|
122
139
|
clear() {
|
|
@@ -149,13 +166,21 @@ const provider = {
|
|
|
149
166
|
if (!provider.store) {
|
|
150
167
|
throw new Error('Store not initialized!');
|
|
151
168
|
}
|
|
152
|
-
return
|
|
169
|
+
return provider.store('readwrite', (store) => {
|
|
170
|
+
store.delete(key);
|
|
171
|
+
return promisifyWriteTransaction(store.transaction);
|
|
172
|
+
});
|
|
153
173
|
},
|
|
154
174
|
removeItems(keysParam) {
|
|
155
175
|
if (!provider.store) {
|
|
156
176
|
throw new Error('Store not initialized!');
|
|
157
177
|
}
|
|
158
|
-
return
|
|
178
|
+
return provider.store('readwrite', (store) => {
|
|
179
|
+
for (const key of keysParam) {
|
|
180
|
+
store.delete(key);
|
|
181
|
+
}
|
|
182
|
+
return promisifyWriteTransaction(store.transaction);
|
|
183
|
+
});
|
|
159
184
|
},
|
|
160
185
|
getDatabaseSize() {
|
|
161
186
|
if (!provider.store) {
|