@umituz/react-native-storage 1.1.2 → 1.2.1
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
CHANGED
package/src/index.ts
CHANGED
|
@@ -61,6 +61,11 @@ export {
|
|
|
61
61
|
storageRepository,
|
|
62
62
|
} from './infrastructure/repositories/AsyncStorageRepository';
|
|
63
63
|
|
|
64
|
+
export {
|
|
65
|
+
storageService,
|
|
66
|
+
type StateStorage,
|
|
67
|
+
} from './infrastructure/adapters/StorageService';
|
|
68
|
+
|
|
64
69
|
// =============================================================================
|
|
65
70
|
// PRESENTATION LAYER - Hooks
|
|
66
71
|
// =============================================================================
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Service
|
|
3
|
+
*
|
|
4
|
+
* Zustand persist middleware compatible StateStorage implementation.
|
|
5
|
+
* Uses AsyncStorage under the hood for React Native persistence.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* StateStorage interface for Zustand persist middleware
|
|
12
|
+
*/
|
|
13
|
+
export interface StateStorage {
|
|
14
|
+
getItem: (name: string) => string | null | Promise<string | null>;
|
|
15
|
+
setItem: (name: string, value: string) => void | Promise<void>;
|
|
16
|
+
removeItem: (name: string) => void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Storage service for Zustand persist middleware
|
|
21
|
+
* Direct AsyncStorage implementation
|
|
22
|
+
*/
|
|
23
|
+
export const storageService: StateStorage = {
|
|
24
|
+
getItem: async (name: string): Promise<string | null> => {
|
|
25
|
+
try {
|
|
26
|
+
return await AsyncStorage.getItem(name);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
setItem: async (name: string, value: string): Promise<void> => {
|
|
33
|
+
try {
|
|
34
|
+
await AsyncStorage.setItem(name, value);
|
|
35
|
+
} catch {
|
|
36
|
+
// Silent fail
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
removeItem: async (name: string): Promise<void> => {
|
|
41
|
+
try {
|
|
42
|
+
await AsyncStorage.removeItem(name);
|
|
43
|
+
} catch {
|
|
44
|
+
// Silent fail
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|