@onekeyfe/react-native-async-storage 3.0.76 → 3.0.78
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/android/src/main/java/com/asyncstorage/RNCAsyncStorageModule.kt +4 -0
- package/ios/AsyncStorage.h +3 -0
- package/ios/AsyncStorage.mm +16 -0
- package/lib/module/NativeAsyncStorage.web.js +2 -1
- package/lib/module/index.js +51 -17
- package/lib/module/runtimeConfig.js +10 -4
- package/lib/typescript/src/NativeAsyncStorage.d.ts +1 -0
- package/lib/typescript/src/NativeAsyncStorage.web.d.ts +4 -1
- package/lib/typescript/src/runtimeConfig.d.ts +2 -0
- package/package.json +1 -1
- package/src/NativeAsyncStorage.ts +1 -0
- package/src/NativeAsyncStorage.web.ts +6 -1
- package/src/index.tsx +95 -17
- package/src/runtimeConfig.ts +16 -6
|
@@ -292,6 +292,10 @@ class RNCAsyncStorageModule(reactContext: ReactApplicationContext) :
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
override fun reloadManifest(promise: Promise) {
|
|
296
|
+
promise.resolve(null)
|
|
297
|
+
}
|
|
298
|
+
|
|
295
299
|
// --- Private helpers (ported from AsyncLocalStorageUtil.java) ---
|
|
296
300
|
|
|
297
301
|
private fun ensureDatabase(): Boolean {
|
package/ios/AsyncStorage.h
CHANGED
package/ios/AsyncStorage.mm
CHANGED
|
@@ -711,4 +711,20 @@ static void RCTStorageDirectoryMigrationCheck(NSString *fromStorageDirectory,
|
|
|
711
711
|
});
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
+
- (void)reloadManifest:(RCTPromiseResolveBlock)resolve
|
|
715
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
716
|
+
{
|
|
717
|
+
dispatch_async(RCTGetMethodQueue(), ^{
|
|
718
|
+
self->_haveSetup = NO;
|
|
719
|
+
NSDictionary *ensureSetupError = [self _ensureSetup];
|
|
720
|
+
if (ensureSetupError) {
|
|
721
|
+
reject(@"ASYNC_STORAGE_ERROR",
|
|
722
|
+
ensureSetupError[@"message"] ?: @"Storage setup failed",
|
|
723
|
+
nil);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
resolve(nil);
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
714
730
|
@end
|
|
@@ -135,7 +135,8 @@ const AsyncStorage = {
|
|
|
135
135
|
multiMerge: (keyValuePairs, callback) => {
|
|
136
136
|
const promises = keyValuePairs.map(item => AsyncStorage.mergeItem(item[0], item[1]));
|
|
137
137
|
return createPromiseAll(promises, callback);
|
|
138
|
-
}
|
|
138
|
+
},
|
|
139
|
+
reloadManifest: () => Promise.resolve()
|
|
139
140
|
};
|
|
140
141
|
export default AsyncStorage;
|
|
141
142
|
//# sourceMappingURL=NativeAsyncStorage.web.js.map
|
package/lib/module/index.js
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import NativeModule from './NativeAsyncStorage';
|
|
4
|
-
import { forwardAsyncStorageWriteIfNeeded } from "./runtimeConfig.js";
|
|
4
|
+
import { forwardAsyncStorageWrite, forwardAsyncStorageWriteIfNeeded, shouldForwardAsyncStorageWrite } from "./runtimeConfig.js";
|
|
5
|
+
async function forwardWriteAndReloadManifestIfNeeded(method, args) {
|
|
6
|
+
if (!(await forwardAsyncStorageWriteIfNeeded(method, args))) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
await NativeModule.reloadManifest();
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
async function runLocalWriteWithFreshManifest(write) {
|
|
13
|
+
// This narrows the local-write stale manifest window, but it does not make
|
|
14
|
+
// uninjected writes cross-runtime serialized. Writes that already completed
|
|
15
|
+
// before forwarder installation keep the legacy local-write semantics.
|
|
16
|
+
await NativeModule.reloadManifest();
|
|
17
|
+
await write();
|
|
18
|
+
}
|
|
19
|
+
async function runReadWithFreshManifest(read) {
|
|
20
|
+
// iOS keeps one manifest cache per runtime/module instance while the files on
|
|
21
|
+
// disk are shared. Refresh before reads so main can observe bg-origin writes
|
|
22
|
+
// without routing reads through the bg runtime. Android/web implementations
|
|
23
|
+
// expose reloadManifest as a no-op.
|
|
24
|
+
await NativeModule.reloadManifest();
|
|
25
|
+
return read();
|
|
26
|
+
}
|
|
27
|
+
async function forwardClearAsMultiRemoveIfNeeded() {
|
|
28
|
+
if (!shouldForwardAsyncStorageWrite()) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
await NativeModule.reloadManifest();
|
|
32
|
+
const keys = [...(await NativeModule.getAllKeys())];
|
|
33
|
+
// Use the fresh main-runtime key list; bg clear may enumerate from a stale
|
|
34
|
+
// manifest.
|
|
35
|
+
await forwardAsyncStorageWrite('multiRemove', [keys]);
|
|
36
|
+
await NativeModule.reloadManifest();
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
5
39
|
function createAsyncStorage() {
|
|
6
40
|
const getItem = async (key, callback) => {
|
|
7
41
|
try {
|
|
8
|
-
const result = await NativeModule.multiGet([key]);
|
|
42
|
+
const result = await runReadWithFreshManifest(() => NativeModule.multiGet([key]));
|
|
9
43
|
const value = result?.[0]?.[1] ?? null;
|
|
10
44
|
callback?.(null, value);
|
|
11
45
|
return value;
|
|
@@ -17,8 +51,8 @@ function createAsyncStorage() {
|
|
|
17
51
|
};
|
|
18
52
|
const setItem = async (key, value, callback) => {
|
|
19
53
|
try {
|
|
20
|
-
if (!(await
|
|
21
|
-
await NativeModule.multiSet([[key, value]]);
|
|
54
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [[[key, value]]]))) {
|
|
55
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiSet([[key, value]]));
|
|
22
56
|
}
|
|
23
57
|
callback?.(null);
|
|
24
58
|
} catch (e) {
|
|
@@ -29,8 +63,8 @@ function createAsyncStorage() {
|
|
|
29
63
|
};
|
|
30
64
|
const removeItem = async (key, callback) => {
|
|
31
65
|
try {
|
|
32
|
-
if (!(await
|
|
33
|
-
await NativeModule.multiRemove([key]);
|
|
66
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [[key]]))) {
|
|
67
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiRemove([key]));
|
|
34
68
|
}
|
|
35
69
|
callback?.(null);
|
|
36
70
|
} catch (e) {
|
|
@@ -41,8 +75,8 @@ function createAsyncStorage() {
|
|
|
41
75
|
};
|
|
42
76
|
const mergeItem = async (key, value, callback) => {
|
|
43
77
|
try {
|
|
44
|
-
if (!(await
|
|
45
|
-
await NativeModule.multiMerge([[key, value]]);
|
|
78
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [[[key, value]]]))) {
|
|
79
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiMerge([[key, value]]));
|
|
46
80
|
}
|
|
47
81
|
callback?.(null);
|
|
48
82
|
} catch (e) {
|
|
@@ -53,7 +87,7 @@ function createAsyncStorage() {
|
|
|
53
87
|
};
|
|
54
88
|
const clear = async callback => {
|
|
55
89
|
try {
|
|
56
|
-
if (!(await
|
|
90
|
+
if (!(await forwardClearAsMultiRemoveIfNeeded())) {
|
|
57
91
|
await NativeModule.clear();
|
|
58
92
|
}
|
|
59
93
|
callback?.(null);
|
|
@@ -65,7 +99,7 @@ function createAsyncStorage() {
|
|
|
65
99
|
};
|
|
66
100
|
const getAllKeys = async callback => {
|
|
67
101
|
try {
|
|
68
|
-
const keys = await NativeModule.getAllKeys();
|
|
102
|
+
const keys = await runReadWithFreshManifest(() => NativeModule.getAllKeys());
|
|
69
103
|
callback?.(null, keys);
|
|
70
104
|
return keys;
|
|
71
105
|
} catch (e) {
|
|
@@ -79,7 +113,7 @@ function createAsyncStorage() {
|
|
|
79
113
|
};
|
|
80
114
|
const multiGet = async (keys, callback) => {
|
|
81
115
|
try {
|
|
82
|
-
const result = await NativeModule.multiGet([...keys]);
|
|
116
|
+
const result = await runReadWithFreshManifest(() => NativeModule.multiGet([...keys]));
|
|
83
117
|
callback?.(null, result);
|
|
84
118
|
return result;
|
|
85
119
|
} catch (e) {
|
|
@@ -91,8 +125,8 @@ function createAsyncStorage() {
|
|
|
91
125
|
const multiSet = async (keyValuePairs, callback) => {
|
|
92
126
|
try {
|
|
93
127
|
const mutablePairs = keyValuePairs.map(([k, v]) => [k, v]);
|
|
94
|
-
if (!(await
|
|
95
|
-
await NativeModule.multiSet(mutablePairs);
|
|
128
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [mutablePairs]))) {
|
|
129
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiSet(mutablePairs));
|
|
96
130
|
}
|
|
97
131
|
callback?.(null);
|
|
98
132
|
} catch (e) {
|
|
@@ -104,8 +138,8 @@ function createAsyncStorage() {
|
|
|
104
138
|
const multiRemove = async (keys, callback) => {
|
|
105
139
|
try {
|
|
106
140
|
const mutableKeys = [...keys];
|
|
107
|
-
if (!(await
|
|
108
|
-
await NativeModule.multiRemove(mutableKeys);
|
|
141
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [mutableKeys]))) {
|
|
142
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiRemove(mutableKeys));
|
|
109
143
|
}
|
|
110
144
|
callback?.(null);
|
|
111
145
|
} catch (e) {
|
|
@@ -116,8 +150,8 @@ function createAsyncStorage() {
|
|
|
116
150
|
};
|
|
117
151
|
const multiMerge = async (keyValuePairs, callback) => {
|
|
118
152
|
try {
|
|
119
|
-
if (!(await
|
|
120
|
-
await NativeModule.multiMerge(keyValuePairs);
|
|
153
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [keyValuePairs]))) {
|
|
154
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiMerge(keyValuePairs));
|
|
121
155
|
}
|
|
122
156
|
callback?.(null);
|
|
123
157
|
} catch (e) {
|
|
@@ -20,15 +20,21 @@ function getWriteForwarder() {
|
|
|
20
20
|
function shouldForwardWriteToBackground() {
|
|
21
21
|
return getShouldForwardWriteGetter()?.() ?? false;
|
|
22
22
|
}
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export function shouldForwardAsyncStorageWrite() {
|
|
24
|
+
return shouldForwardWriteToBackground();
|
|
25
|
+
}
|
|
26
|
+
export async function forwardAsyncStorageWrite(method, args) {
|
|
27
27
|
const forwarder = getWriteForwarder();
|
|
28
28
|
if (!forwarder) {
|
|
29
29
|
throw new Error('AsyncStorage write forwarder is not configured.');
|
|
30
30
|
}
|
|
31
31
|
await forwarder(method, args);
|
|
32
|
+
}
|
|
33
|
+
export async function forwardAsyncStorageWriteIfNeeded(method, args) {
|
|
34
|
+
if (!shouldForwardAsyncStorageWrite()) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
await forwardAsyncStorageWrite(method, args);
|
|
32
38
|
return true;
|
|
33
39
|
}
|
|
34
40
|
//# sourceMappingURL=runtimeConfig.js.map
|
|
@@ -6,6 +6,7 @@ export interface Spec extends TurboModule {
|
|
|
6
6
|
multiMerge(keyValuePairs: [string, string][]): Promise<void>;
|
|
7
7
|
getAllKeys(): Promise<string[]>;
|
|
8
8
|
clear(): Promise<void>;
|
|
9
|
+
reloadManifest(): Promise<void>;
|
|
9
10
|
}
|
|
10
11
|
declare const _default: Spec;
|
|
11
12
|
export default _default;
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import type { AsyncStorageStatic } from './types';
|
|
9
|
-
|
|
9
|
+
type AsyncStorageWebStatic = AsyncStorageStatic & {
|
|
10
|
+
reloadManifest: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
declare const AsyncStorage: AsyncStorageWebStatic;
|
|
10
13
|
export default AsyncStorage;
|
|
11
14
|
//# sourceMappingURL=NativeAsyncStorage.web.d.ts.map
|
|
@@ -10,5 +10,7 @@ export type AsyncStorageShouldForwardWriteGetter = () => boolean;
|
|
|
10
10
|
export type AsyncStorageWriteForwarder = <T extends AsyncStorageWriteMethod>(method: T, args: AsyncStorageWriteArgs<T>) => Promise<void>;
|
|
11
11
|
export declare function setAsyncStorageShouldForwardWriteGetter(getter: AsyncStorageShouldForwardWriteGetter): void;
|
|
12
12
|
export declare function setAsyncStorageWriteForwarder(forwarder: AsyncStorageWriteForwarder): void;
|
|
13
|
+
export declare function shouldForwardAsyncStorageWrite(): boolean;
|
|
14
|
+
export declare function forwardAsyncStorageWrite<T extends AsyncStorageWriteMethod>(method: T, args: AsyncStorageWriteArgs<T>): Promise<void>;
|
|
13
15
|
export declare function forwardAsyncStorageWriteIfNeeded<T extends AsyncStorageWriteMethod>(method: T, args: AsyncStorageWriteArgs<T>): Promise<boolean>;
|
|
14
16
|
//# sourceMappingURL=runtimeConfig.d.ts.map
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ export interface Spec extends TurboModule {
|
|
|
8
8
|
multiMerge(keyValuePairs: [string, string][]): Promise<void>;
|
|
9
9
|
getAllKeys(): Promise<string[]>;
|
|
10
10
|
clear(): Promise<void>;
|
|
11
|
+
reloadManifest(): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export default TurboModuleRegistry.getEnforcing<Spec>('RNCAsyncStorage');
|
|
@@ -17,6 +17,9 @@ import type {
|
|
|
17
17
|
type OnMultiResult = Function;
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
19
19
|
type OnResult = Function;
|
|
20
|
+
type AsyncStorageWebStatic = AsyncStorageStatic & {
|
|
21
|
+
reloadManifest: () => Promise<void>;
|
|
22
|
+
};
|
|
20
23
|
|
|
21
24
|
const merge = mergeOptions.bind({
|
|
22
25
|
concatArrays: true,
|
|
@@ -73,7 +76,7 @@ function createPromiseAll<
|
|
|
73
76
|
);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
const AsyncStorage:
|
|
79
|
+
const AsyncStorage: AsyncStorageWebStatic = {
|
|
77
80
|
/**
|
|
78
81
|
* Fetches `key` value.
|
|
79
82
|
*/
|
|
@@ -176,6 +179,8 @@ const AsyncStorage: AsyncStorageStatic = {
|
|
|
176
179
|
);
|
|
177
180
|
return createPromiseAll(promises, callback);
|
|
178
181
|
},
|
|
182
|
+
|
|
183
|
+
reloadManifest: () => Promise.resolve(),
|
|
179
184
|
};
|
|
180
185
|
|
|
181
186
|
export default AsyncStorage;
|
package/src/index.tsx
CHANGED
|
@@ -1,11 +1,63 @@
|
|
|
1
1
|
import NativeModule from './NativeAsyncStorage';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
forwardAsyncStorageWrite,
|
|
4
|
+
forwardAsyncStorageWriteIfNeeded,
|
|
5
|
+
shouldForwardAsyncStorageWrite,
|
|
6
|
+
} from './runtimeConfig';
|
|
7
|
+
import type {
|
|
8
|
+
AsyncStorageWriteArgs,
|
|
9
|
+
AsyncStorageWriteMethod,
|
|
10
|
+
} from './runtimeConfig';
|
|
3
11
|
import type { AsyncStorageStatic } from './types';
|
|
4
12
|
|
|
13
|
+
async function forwardWriteAndReloadManifestIfNeeded<
|
|
14
|
+
T extends AsyncStorageWriteMethod
|
|
15
|
+
>(method: T, args: AsyncStorageWriteArgs<T>) {
|
|
16
|
+
if (!(await forwardAsyncStorageWriteIfNeeded(method, args))) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await NativeModule.reloadManifest();
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function runLocalWriteWithFreshManifest(write: () => Promise<void>) {
|
|
25
|
+
// This narrows the local-write stale manifest window, but it does not make
|
|
26
|
+
// uninjected writes cross-runtime serialized. Writes that already completed
|
|
27
|
+
// before forwarder installation keep the legacy local-write semantics.
|
|
28
|
+
await NativeModule.reloadManifest();
|
|
29
|
+
await write();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function runReadWithFreshManifest<T>(read: () => Promise<T>): Promise<T> {
|
|
33
|
+
// iOS keeps one manifest cache per runtime/module instance while the files on
|
|
34
|
+
// disk are shared. Refresh before reads so main can observe bg-origin writes
|
|
35
|
+
// without routing reads through the bg runtime. Android/web implementations
|
|
36
|
+
// expose reloadManifest as a no-op.
|
|
37
|
+
await NativeModule.reloadManifest();
|
|
38
|
+
return read();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function forwardClearAsMultiRemoveIfNeeded() {
|
|
42
|
+
if (!shouldForwardAsyncStorageWrite()) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await NativeModule.reloadManifest();
|
|
47
|
+
const keys = [...(await NativeModule.getAllKeys())];
|
|
48
|
+
// Use the fresh main-runtime key list; bg clear may enumerate from a stale
|
|
49
|
+
// manifest.
|
|
50
|
+
await forwardAsyncStorageWrite('multiRemove', [keys]);
|
|
51
|
+
await NativeModule.reloadManifest();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
5
55
|
function createAsyncStorage(): AsyncStorageStatic {
|
|
6
56
|
const getItem: AsyncStorageStatic['getItem'] = async (key, callback) => {
|
|
7
57
|
try {
|
|
8
|
-
const result = await
|
|
58
|
+
const result = await runReadWithFreshManifest(() =>
|
|
59
|
+
NativeModule.multiGet([key])
|
|
60
|
+
);
|
|
9
61
|
const value = result?.[0]?.[1] ?? null;
|
|
10
62
|
callback?.(null, value);
|
|
11
63
|
return value;
|
|
@@ -23,9 +75,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
23
75
|
) => {
|
|
24
76
|
try {
|
|
25
77
|
if (
|
|
26
|
-
!(await
|
|
78
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [
|
|
79
|
+
[[key, value]],
|
|
80
|
+
]))
|
|
27
81
|
) {
|
|
28
|
-
await
|
|
82
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
83
|
+
NativeModule.multiSet([[key, value]])
|
|
84
|
+
);
|
|
29
85
|
}
|
|
30
86
|
callback?.(null);
|
|
31
87
|
} catch (e) {
|
|
@@ -40,8 +96,12 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
40
96
|
callback
|
|
41
97
|
) => {
|
|
42
98
|
try {
|
|
43
|
-
if (
|
|
44
|
-
await
|
|
99
|
+
if (
|
|
100
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [[key]]))
|
|
101
|
+
) {
|
|
102
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
103
|
+
NativeModule.multiRemove([key])
|
|
104
|
+
);
|
|
45
105
|
}
|
|
46
106
|
callback?.(null);
|
|
47
107
|
} catch (e) {
|
|
@@ -58,11 +118,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
58
118
|
) => {
|
|
59
119
|
try {
|
|
60
120
|
if (
|
|
61
|
-
!(await
|
|
121
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [
|
|
62
122
|
[[key, value]],
|
|
63
123
|
]))
|
|
64
124
|
) {
|
|
65
|
-
await
|
|
125
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
126
|
+
NativeModule.multiMerge([[key, value]])
|
|
127
|
+
);
|
|
66
128
|
}
|
|
67
129
|
callback?.(null);
|
|
68
130
|
} catch (e) {
|
|
@@ -74,7 +136,7 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
74
136
|
|
|
75
137
|
const clear: AsyncStorageStatic['clear'] = async (callback) => {
|
|
76
138
|
try {
|
|
77
|
-
if (!(await
|
|
139
|
+
if (!(await forwardClearAsMultiRemoveIfNeeded())) {
|
|
78
140
|
await NativeModule.clear();
|
|
79
141
|
}
|
|
80
142
|
callback?.(null);
|
|
@@ -87,7 +149,9 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
87
149
|
|
|
88
150
|
const getAllKeys: AsyncStorageStatic['getAllKeys'] = async (callback) => {
|
|
89
151
|
try {
|
|
90
|
-
const keys = await
|
|
152
|
+
const keys = await runReadWithFreshManifest(() =>
|
|
153
|
+
NativeModule.getAllKeys()
|
|
154
|
+
);
|
|
91
155
|
callback?.(null, keys);
|
|
92
156
|
return keys;
|
|
93
157
|
} catch (e) {
|
|
@@ -103,7 +167,9 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
103
167
|
|
|
104
168
|
const multiGet: AsyncStorageStatic['multiGet'] = async (keys, callback) => {
|
|
105
169
|
try {
|
|
106
|
-
const result = await
|
|
170
|
+
const result = await runReadWithFreshManifest(() =>
|
|
171
|
+
NativeModule.multiGet([...keys])
|
|
172
|
+
);
|
|
107
173
|
callback?.(null, result);
|
|
108
174
|
return result;
|
|
109
175
|
} catch (e) {
|
|
@@ -122,9 +188,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
122
188
|
([k, v]) => [k, v] as [string, string]
|
|
123
189
|
);
|
|
124
190
|
if (
|
|
125
|
-
!(await
|
|
191
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [
|
|
192
|
+
mutablePairs,
|
|
193
|
+
]))
|
|
126
194
|
) {
|
|
127
|
-
await
|
|
195
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
196
|
+
NativeModule.multiSet(mutablePairs)
|
|
197
|
+
);
|
|
128
198
|
}
|
|
129
199
|
callback?.(null);
|
|
130
200
|
} catch (e) {
|
|
@@ -141,9 +211,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
141
211
|
try {
|
|
142
212
|
const mutableKeys = [...keys];
|
|
143
213
|
if (
|
|
144
|
-
!(await
|
|
214
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [
|
|
215
|
+
mutableKeys,
|
|
216
|
+
]))
|
|
145
217
|
) {
|
|
146
|
-
await
|
|
218
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
219
|
+
NativeModule.multiRemove(mutableKeys)
|
|
220
|
+
);
|
|
147
221
|
}
|
|
148
222
|
callback?.(null);
|
|
149
223
|
} catch (e) {
|
|
@@ -159,9 +233,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
159
233
|
) => {
|
|
160
234
|
try {
|
|
161
235
|
if (
|
|
162
|
-
!(await
|
|
236
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [
|
|
237
|
+
keyValuePairs,
|
|
238
|
+
]))
|
|
163
239
|
) {
|
|
164
|
-
await
|
|
240
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
241
|
+
NativeModule.multiMerge(keyValuePairs)
|
|
242
|
+
);
|
|
165
243
|
}
|
|
166
244
|
callback?.(null);
|
|
167
245
|
} catch (e) {
|
package/src/runtimeConfig.ts
CHANGED
|
@@ -59,18 +59,28 @@ function shouldForwardWriteToBackground() {
|
|
|
59
59
|
return getShouldForwardWriteGetter()?.() ?? false;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!shouldForwardWriteToBackground()) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
62
|
+
export function shouldForwardAsyncStorageWrite() {
|
|
63
|
+
return shouldForwardWriteToBackground();
|
|
64
|
+
}
|
|
68
65
|
|
|
66
|
+
export async function forwardAsyncStorageWrite<
|
|
67
|
+
T extends AsyncStorageWriteMethod
|
|
68
|
+
>(method: T, args: AsyncStorageWriteArgs<T>): Promise<void> {
|
|
69
69
|
const forwarder = getWriteForwarder();
|
|
70
70
|
if (!forwarder) {
|
|
71
71
|
throw new Error('AsyncStorage write forwarder is not configured.');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
await forwarder(method, args);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function forwardAsyncStorageWriteIfNeeded<
|
|
78
|
+
T extends AsyncStorageWriteMethod
|
|
79
|
+
>(method: T, args: AsyncStorageWriteArgs<T>): Promise<boolean> {
|
|
80
|
+
if (!shouldForwardAsyncStorageWrite()) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await forwardAsyncStorageWrite(method, args);
|
|
75
85
|
return true;
|
|
76
86
|
}
|