@onekeyfe/react-native-async-storage 3.0.76 → 3.0.77
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/index.js +24 -13
- package/lib/typescript/src/NativeAsyncStorage.d.ts +1 -0
- package/package.json +1 -1
- package/src/NativeAsyncStorage.ts +1 -0
- package/src/index.tsx +55 -13
|
@@ -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
|
package/lib/module/index.js
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
import NativeModule from './NativeAsyncStorage';
|
|
4
4
|
import { forwardAsyncStorageWriteIfNeeded } 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
|
+
await NativeModule.reloadManifest();
|
|
14
|
+
await write();
|
|
15
|
+
}
|
|
5
16
|
function createAsyncStorage() {
|
|
6
17
|
const getItem = async (key, callback) => {
|
|
7
18
|
try {
|
|
@@ -17,8 +28,8 @@ function createAsyncStorage() {
|
|
|
17
28
|
};
|
|
18
29
|
const setItem = async (key, value, callback) => {
|
|
19
30
|
try {
|
|
20
|
-
if (!(await
|
|
21
|
-
await NativeModule.multiSet([[key, value]]);
|
|
31
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [[[key, value]]]))) {
|
|
32
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiSet([[key, value]]));
|
|
22
33
|
}
|
|
23
34
|
callback?.(null);
|
|
24
35
|
} catch (e) {
|
|
@@ -29,8 +40,8 @@ function createAsyncStorage() {
|
|
|
29
40
|
};
|
|
30
41
|
const removeItem = async (key, callback) => {
|
|
31
42
|
try {
|
|
32
|
-
if (!(await
|
|
33
|
-
await NativeModule.multiRemove([key]);
|
|
43
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [[key]]))) {
|
|
44
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiRemove([key]));
|
|
34
45
|
}
|
|
35
46
|
callback?.(null);
|
|
36
47
|
} catch (e) {
|
|
@@ -41,8 +52,8 @@ function createAsyncStorage() {
|
|
|
41
52
|
};
|
|
42
53
|
const mergeItem = async (key, value, callback) => {
|
|
43
54
|
try {
|
|
44
|
-
if (!(await
|
|
45
|
-
await NativeModule.multiMerge([[key, value]]);
|
|
55
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [[[key, value]]]))) {
|
|
56
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiMerge([[key, value]]));
|
|
46
57
|
}
|
|
47
58
|
callback?.(null);
|
|
48
59
|
} catch (e) {
|
|
@@ -53,7 +64,7 @@ function createAsyncStorage() {
|
|
|
53
64
|
};
|
|
54
65
|
const clear = async callback => {
|
|
55
66
|
try {
|
|
56
|
-
if (!(await
|
|
67
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('clear', []))) {
|
|
57
68
|
await NativeModule.clear();
|
|
58
69
|
}
|
|
59
70
|
callback?.(null);
|
|
@@ -91,8 +102,8 @@ function createAsyncStorage() {
|
|
|
91
102
|
const multiSet = async (keyValuePairs, callback) => {
|
|
92
103
|
try {
|
|
93
104
|
const mutablePairs = keyValuePairs.map(([k, v]) => [k, v]);
|
|
94
|
-
if (!(await
|
|
95
|
-
await NativeModule.multiSet(mutablePairs);
|
|
105
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [mutablePairs]))) {
|
|
106
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiSet(mutablePairs));
|
|
96
107
|
}
|
|
97
108
|
callback?.(null);
|
|
98
109
|
} catch (e) {
|
|
@@ -104,8 +115,8 @@ function createAsyncStorage() {
|
|
|
104
115
|
const multiRemove = async (keys, callback) => {
|
|
105
116
|
try {
|
|
106
117
|
const mutableKeys = [...keys];
|
|
107
|
-
if (!(await
|
|
108
|
-
await NativeModule.multiRemove(mutableKeys);
|
|
118
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [mutableKeys]))) {
|
|
119
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiRemove(mutableKeys));
|
|
109
120
|
}
|
|
110
121
|
callback?.(null);
|
|
111
122
|
} catch (e) {
|
|
@@ -116,8 +127,8 @@ function createAsyncStorage() {
|
|
|
116
127
|
};
|
|
117
128
|
const multiMerge = async (keyValuePairs, callback) => {
|
|
118
129
|
try {
|
|
119
|
-
if (!(await
|
|
120
|
-
await NativeModule.multiMerge(keyValuePairs);
|
|
130
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [keyValuePairs]))) {
|
|
131
|
+
await runLocalWriteWithFreshManifest(() => NativeModule.multiMerge(keyValuePairs));
|
|
121
132
|
}
|
|
122
133
|
callback?.(null);
|
|
123
134
|
} catch (e) {
|
|
@@ -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;
|
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');
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import NativeModule from './NativeAsyncStorage';
|
|
2
2
|
import { forwardAsyncStorageWriteIfNeeded } from './runtimeConfig';
|
|
3
|
+
import type {
|
|
4
|
+
AsyncStorageWriteArgs,
|
|
5
|
+
AsyncStorageWriteMethod,
|
|
6
|
+
} from './runtimeConfig';
|
|
3
7
|
import type { AsyncStorageStatic } from './types';
|
|
4
8
|
|
|
9
|
+
async function forwardWriteAndReloadManifestIfNeeded<
|
|
10
|
+
T extends AsyncStorageWriteMethod
|
|
11
|
+
>(method: T, args: AsyncStorageWriteArgs<T>) {
|
|
12
|
+
if (!(await forwardAsyncStorageWriteIfNeeded(method, args))) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await NativeModule.reloadManifest();
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function runLocalWriteWithFreshManifest(write: () => Promise<void>) {
|
|
21
|
+
await NativeModule.reloadManifest();
|
|
22
|
+
await write();
|
|
23
|
+
}
|
|
24
|
+
|
|
5
25
|
function createAsyncStorage(): AsyncStorageStatic {
|
|
6
26
|
const getItem: AsyncStorageStatic['getItem'] = async (key, callback) => {
|
|
7
27
|
try {
|
|
@@ -23,9 +43,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
23
43
|
) => {
|
|
24
44
|
try {
|
|
25
45
|
if (
|
|
26
|
-
!(await
|
|
46
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [
|
|
47
|
+
[[key, value]],
|
|
48
|
+
]))
|
|
27
49
|
) {
|
|
28
|
-
await
|
|
50
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
51
|
+
NativeModule.multiSet([[key, value]])
|
|
52
|
+
);
|
|
29
53
|
}
|
|
30
54
|
callback?.(null);
|
|
31
55
|
} catch (e) {
|
|
@@ -40,8 +64,12 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
40
64
|
callback
|
|
41
65
|
) => {
|
|
42
66
|
try {
|
|
43
|
-
if (
|
|
44
|
-
await
|
|
67
|
+
if (
|
|
68
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [[key]]))
|
|
69
|
+
) {
|
|
70
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
71
|
+
NativeModule.multiRemove([key])
|
|
72
|
+
);
|
|
45
73
|
}
|
|
46
74
|
callback?.(null);
|
|
47
75
|
} catch (e) {
|
|
@@ -58,11 +86,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
58
86
|
) => {
|
|
59
87
|
try {
|
|
60
88
|
if (
|
|
61
|
-
!(await
|
|
89
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [
|
|
62
90
|
[[key, value]],
|
|
63
91
|
]))
|
|
64
92
|
) {
|
|
65
|
-
await
|
|
93
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
94
|
+
NativeModule.multiMerge([[key, value]])
|
|
95
|
+
);
|
|
66
96
|
}
|
|
67
97
|
callback?.(null);
|
|
68
98
|
} catch (e) {
|
|
@@ -74,7 +104,7 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
74
104
|
|
|
75
105
|
const clear: AsyncStorageStatic['clear'] = async (callback) => {
|
|
76
106
|
try {
|
|
77
|
-
if (!(await
|
|
107
|
+
if (!(await forwardWriteAndReloadManifestIfNeeded('clear', []))) {
|
|
78
108
|
await NativeModule.clear();
|
|
79
109
|
}
|
|
80
110
|
callback?.(null);
|
|
@@ -122,9 +152,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
122
152
|
([k, v]) => [k, v] as [string, string]
|
|
123
153
|
);
|
|
124
154
|
if (
|
|
125
|
-
!(await
|
|
155
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiSet', [
|
|
156
|
+
mutablePairs,
|
|
157
|
+
]))
|
|
126
158
|
) {
|
|
127
|
-
await
|
|
159
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
160
|
+
NativeModule.multiSet(mutablePairs)
|
|
161
|
+
);
|
|
128
162
|
}
|
|
129
163
|
callback?.(null);
|
|
130
164
|
} catch (e) {
|
|
@@ -141,9 +175,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
141
175
|
try {
|
|
142
176
|
const mutableKeys = [...keys];
|
|
143
177
|
if (
|
|
144
|
-
!(await
|
|
178
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiRemove', [
|
|
179
|
+
mutableKeys,
|
|
180
|
+
]))
|
|
145
181
|
) {
|
|
146
|
-
await
|
|
182
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
183
|
+
NativeModule.multiRemove(mutableKeys)
|
|
184
|
+
);
|
|
147
185
|
}
|
|
148
186
|
callback?.(null);
|
|
149
187
|
} catch (e) {
|
|
@@ -159,9 +197,13 @@ function createAsyncStorage(): AsyncStorageStatic {
|
|
|
159
197
|
) => {
|
|
160
198
|
try {
|
|
161
199
|
if (
|
|
162
|
-
!(await
|
|
200
|
+
!(await forwardWriteAndReloadManifestIfNeeded('multiMerge', [
|
|
201
|
+
keyValuePairs,
|
|
202
|
+
]))
|
|
163
203
|
) {
|
|
164
|
-
await
|
|
204
|
+
await runLocalWriteWithFreshManifest(() =>
|
|
205
|
+
NativeModule.multiMerge(keyValuePairs)
|
|
206
|
+
);
|
|
165
207
|
}
|
|
166
208
|
callback?.(null);
|
|
167
209
|
} catch (e) {
|