@idealyst/storage 1.0.50 → 1.0.51
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/package.json +7 -6
- package/src/storage.native.ts +23 -18
- package/src/async-storage.d.ts +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/storage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "Cross-platform storage abstraction for React and React Native",
|
|
5
5
|
"documentation": "https://github.com/your-username/idealyst-framework/tree/main/packages/storage#readme",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,20 +31,21 @@
|
|
|
31
31
|
"publish:npm": "npm publish"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@react-native-async-storage/async-storage": ">=1.0.0",
|
|
35
34
|
"react": ">=16.8.0",
|
|
36
|
-
"react-native": ">=0.60.0"
|
|
35
|
+
"react-native": ">=0.60.0",
|
|
36
|
+
"react-native-mmkv": ">=2.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
|
-
"
|
|
39
|
+
"react-native": {
|
|
40
40
|
"optional": true
|
|
41
41
|
},
|
|
42
|
-
"react-native": {
|
|
42
|
+
"react-native-mmkv": {
|
|
43
43
|
"optional": true
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/react": "^19.1.0",
|
|
48
|
+
"react-native-mmkv": "^3.3.1",
|
|
48
49
|
"typescript": "^5.0.0"
|
|
49
50
|
},
|
|
50
51
|
"files": [
|
|
@@ -57,6 +58,6 @@
|
|
|
57
58
|
"storage",
|
|
58
59
|
"cross-platform",
|
|
59
60
|
"localStorage",
|
|
60
|
-
"
|
|
61
|
+
"MMKV"
|
|
61
62
|
]
|
|
62
63
|
}
|
package/src/storage.native.ts
CHANGED
|
@@ -1,76 +1,81 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MMKV } from 'react-native-mmkv';
|
|
2
2
|
import { IStorage } from './types';
|
|
3
3
|
|
|
4
4
|
class NativeStorage implements IStorage {
|
|
5
|
+
private storage = new MMKV();
|
|
6
|
+
|
|
5
7
|
async getItem(key: string): Promise<string | null> {
|
|
6
8
|
try {
|
|
7
|
-
return
|
|
9
|
+
return this.storage.getString(key) || null;
|
|
8
10
|
} catch (error) {
|
|
9
|
-
console.error('Error getting item from
|
|
11
|
+
console.error('Error getting item from MMKV:', error);
|
|
10
12
|
return null;
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
async setItem(key: string, value: string): Promise<void> {
|
|
15
17
|
try {
|
|
16
|
-
|
|
18
|
+
this.storage.set(key, value);
|
|
17
19
|
} catch (error) {
|
|
18
|
-
console.error('Error setting item in
|
|
20
|
+
console.error('Error setting item in MMKV:', error);
|
|
19
21
|
throw error;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
async removeItem(key: string): Promise<void> {
|
|
24
26
|
try {
|
|
25
|
-
|
|
27
|
+
this.storage.delete(key);
|
|
26
28
|
} catch (error) {
|
|
27
|
-
console.error('Error removing item from
|
|
29
|
+
console.error('Error removing item from MMKV:', error);
|
|
28
30
|
throw error;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
async clear(): Promise<void> {
|
|
33
35
|
try {
|
|
34
|
-
|
|
36
|
+
this.storage.clearAll();
|
|
35
37
|
} catch (error) {
|
|
36
|
-
console.error('Error clearing
|
|
38
|
+
console.error('Error clearing MMKV:', error);
|
|
37
39
|
throw error;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
async getAllKeys(): Promise<string[]> {
|
|
42
44
|
try {
|
|
43
|
-
return
|
|
45
|
+
return this.storage.getAllKeys();
|
|
44
46
|
} catch (error) {
|
|
45
|
-
console.error('Error getting all keys from
|
|
47
|
+
console.error('Error getting all keys from MMKV:', error);
|
|
46
48
|
return [];
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
async multiGet(keys: string[]): Promise<Array<[string, string | null]>> {
|
|
51
53
|
try {
|
|
52
|
-
|
|
53
|
-
return results as Array<[string, string | null]>;
|
|
54
|
+
return keys.map(key => [key, this.storage.getString(key) || null]);
|
|
54
55
|
} catch (error) {
|
|
55
|
-
console.error('Error in multiGet from
|
|
56
|
+
console.error('Error in multiGet from MMKV:', error);
|
|
56
57
|
return keys.map(key => [key, null]);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
async multiSet(keyValuePairs: Array<[string, string]>): Promise<void> {
|
|
61
62
|
try {
|
|
62
|
-
|
|
63
|
+
keyValuePairs.forEach(([key, value]) => {
|
|
64
|
+
this.storage.set(key, value);
|
|
65
|
+
});
|
|
63
66
|
} catch (error) {
|
|
64
|
-
console.error('Error in multiSet to
|
|
67
|
+
console.error('Error in multiSet to MMKV:', error);
|
|
65
68
|
throw error;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
async multiRemove(keys: string[]): Promise<void> {
|
|
70
73
|
try {
|
|
71
|
-
|
|
74
|
+
keys.forEach(key => {
|
|
75
|
+
this.storage.delete(key);
|
|
76
|
+
});
|
|
72
77
|
} catch (error) {
|
|
73
|
-
console.error('Error in multiRemove from
|
|
78
|
+
console.error('Error in multiRemove from MMKV:', error);
|
|
74
79
|
throw error;
|
|
75
80
|
}
|
|
76
81
|
}
|
package/src/async-storage.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare module '@react-native-async-storage/async-storage' {
|
|
2
|
-
export interface AsyncStorageStatic {
|
|
3
|
-
getItem(key: string): Promise<string | null>;
|
|
4
|
-
setItem(key: string, value: string): Promise<void>;
|
|
5
|
-
removeItem(key: string): Promise<void>;
|
|
6
|
-
clear(): Promise<void>;
|
|
7
|
-
getAllKeys(): Promise<string[]>;
|
|
8
|
-
multiGet(keys: string[]): Promise<Array<[string, string | null]>>;
|
|
9
|
-
multiSet(keyValuePairs: Array<[string, string]>): Promise<void>;
|
|
10
|
-
multiRemove(keys: string[]): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const AsyncStorage: AsyncStorageStatic;
|
|
14
|
-
export default AsyncStorage;
|
|
15
|
-
}
|