@umituz/react-native-storage 1.1.1 → 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.1",
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",
@@ -54,6 +54,11 @@ export interface IStorageRepository {
54
54
  */
55
55
  getMultiple(keys: string[]): Promise<StorageResult<Record<string, string | null>>>;
56
56
 
57
+ /**
58
+ * Get all keys from storage
59
+ */
60
+ getAllKeys(): Promise<StorageResult<string[]>>;
61
+
57
62
  /**
58
63
  * Get object from storage (alias for getItem for backward compatibility)
59
64
  * @deprecated Use getItem instead
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
+ };
@@ -144,6 +144,18 @@ export class AsyncStorageRepository implements IStorageRepository {
144
144
  }
145
145
  }
146
146
 
147
+ /**
148
+ * Get all keys from storage
149
+ */
150
+ async getAllKeys(): Promise<StorageResult<string[]>> {
151
+ try {
152
+ const keys = await AsyncStorage.getAllKeys();
153
+ return success([...keys]);
154
+ } catch (error) {
155
+ return failure(new StorageReadError('ALL_KEYS', error));
156
+ }
157
+ }
158
+
147
159
  /**
148
160
  * Get object from storage (alias for getItem for backward compatibility)
149
161
  * @deprecated Use getItem instead