@umituz/react-native-storage 1.1.2 → 1.2.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-storage",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Domain-Driven Design storage system for React Native apps with type-safe AsyncStorage operations",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -61,6 +61,11 @@ export {
61
61
  storageRepository,
62
62
  } from './infrastructure/repositories/AsyncStorageRepository';
63
63
 
64
+ export {
65
+ zustandStorage,
66
+ type StateStorage,
67
+ } from './infrastructure/adapters/ZustandAdapter';
68
+
64
69
  // =============================================================================
65
70
  // PRESENTATION LAYER - Hooks
66
71
  // =============================================================================
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Zustand Storage Adapter
3
+ *
4
+ * Provides Zustand persist middleware compatible StateStorage interface.
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
+ * Zustand StateStorage interface
12
+ * Compatible with zustand/middleware persist
13
+ */
14
+ export interface StateStorage {
15
+ getItem: (name: string) => string | null | Promise<string | null>;
16
+ setItem: (name: string, value: string) => void | Promise<void>;
17
+ removeItem: (name: string) => void | Promise<void>;
18
+ }
19
+
20
+ /**
21
+ * Zustand-compatible storage adapter
22
+ * Direct AsyncStorage implementation for Zustand persist middleware
23
+ */
24
+ export const zustandStorage: StateStorage = {
25
+ getItem: async (name: string): Promise<string | null> => {
26
+ try {
27
+ return await AsyncStorage.getItem(name);
28
+ } catch {
29
+ return null;
30
+ }
31
+ },
32
+
33
+ setItem: async (name: string, value: string): Promise<void> => {
34
+ try {
35
+ await AsyncStorage.setItem(name, value);
36
+ } catch {
37
+ // Silent fail - Zustand handles retry
38
+ }
39
+ },
40
+
41
+ removeItem: async (name: string): Promise<void> => {
42
+ try {
43
+ await AsyncStorage.removeItem(name);
44
+ } catch {
45
+ // Silent fail
46
+ }
47
+ },
48
+ };