@umituz/react-native-storage 2.3.3 → 2.4.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-storage",
3
- "version": "2.3.3",
3
+ "version": "2.4.1",
4
4
  "description": "Zustand state management with AsyncStorage persistence and type-safe storage operations for React Native",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -60,7 +60,6 @@
60
60
  "access": "public"
61
61
  },
62
62
  "files": [
63
- "lib",
64
63
  "src",
65
64
  "README.md",
66
65
  "LICENSE"
@@ -53,7 +53,11 @@ export const unwrap = <T>(result: StorageResult<T>, defaultValue: T): T => {
53
53
  if (isSuccess(result)) {
54
54
  return result.data;
55
55
  }
56
- return result.fallback !== undefined ? result.fallback : defaultValue;
56
+ // Type guard ensures we can access fallback
57
+ if (isFailure(result) && result.fallback !== undefined) {
58
+ return result.fallback;
59
+ }
60
+ return defaultValue;
57
61
  };
58
62
 
59
63
  /**
@@ -66,5 +70,6 @@ export const map = <T, U>(
66
70
  if (isSuccess(result)) {
67
71
  return success(fn(result.data));
68
72
  }
73
+ // For failure, we can't convert fallback type T to U, so we omit it
69
74
  return failure(result.error);
70
75
  };
@@ -47,8 +47,8 @@ export const createNamespacedKey = (namespace: string, key: string): string => {
47
47
  };
48
48
 
49
49
  /**
50
- * Legacy StorageKey enum for backward compatibility
51
- * @deprecated Use createNamespacedKey instead
50
+ * Common storage keys for cross-app usage
51
+ * Generic keys that can be used across multiple applications
52
52
  */
53
53
  export enum StorageKey {
54
54
  USER_PREFERENCES = '@user_preferences',
package/README.md DELETED
@@ -1,102 +0,0 @@
1
- # @umituz/react-native-storage
2
-
3
- Domain-Driven Design storage system for React Native apps with type-safe AsyncStorage operations.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @umituz/react-native-storage
9
- ```
10
-
11
- ## Peer Dependencies
12
-
13
- - `react` >= 18.2.0
14
- - `react-native` >= 0.74.0
15
- - `@react-native-async-storage/async-storage` >= 1.21.0
16
-
17
- ## Features
18
-
19
- - ✅ Domain-Driven Design (DDD) architecture
20
- - ✅ Type-safe storage operations
21
- - ✅ Result-based error handling
22
- - ✅ React hooks for easy integration
23
- - ✅ Storage key management utilities
24
- - ✅ Automatic serialization/deserialization
25
-
26
- ## Usage
27
-
28
- ### Basic Usage with Hook
29
-
30
- ```typescript
31
- import { useStorage, StorageKey } from '@umituz/react-native-storage';
32
-
33
- const MyComponent = () => {
34
- const storage = useStorage();
35
-
36
- // Get item
37
- const value = await storage.getItem('my-key', 'default-value');
38
-
39
- // Set item
40
- await storage.setItem('my-key', 'my-value');
41
-
42
- // Remove item
43
- await storage.removeItem('my-key');
44
-
45
- // Clear all
46
- await storage.clear();
47
- };
48
- ```
49
-
50
- ### Using Storage Keys
51
-
52
- ```typescript
53
- import { StorageKey, createUserKey, createAppKey } from '@umituz/react-native-storage';
54
-
55
- // Create typed storage keys
56
- const userKey = createUserKey('preferences');
57
- const appKey = createAppKey('settings');
58
-
59
- // Use with storage
60
- const storage = useStorage();
61
- await storage.setItem(userKey, { theme: 'dark' });
62
- ```
63
-
64
- ### Using Storage State Hook
65
-
66
- ```typescript
67
- import { useStorageState } from '@umituz/react-native-storage';
68
-
69
- const MyComponent = () => {
70
- const [value, setValue, isLoading] = useStorageState('my-key', 'default');
71
-
72
- return (
73
- <View>
74
- <Text>{value}</Text>
75
- <Button onPress={() => setValue('new-value')} />
76
- </View>
77
- );
78
- };
79
- ```
80
-
81
- ## API
82
-
83
- ### Hooks
84
-
85
- - `useStorage()`: Main storage hook for CRUD operations
86
- - `useStorageState(key, defaultValue)`: React state hook with storage persistence
87
-
88
- ### Utilities
89
-
90
- - `StorageKey`: Type-safe storage key class
91
- - `createUserKey(key)`: Create user-specific storage key
92
- - `createAppKey(key)`: Create app-wide storage key
93
-
94
- ### Repository
95
-
96
- - `storageRepository`: Direct access to storage repository
97
- - `AsyncStorageRepository`: Repository implementation class
98
-
99
- ## License
100
-
101
- MIT
102
-