@umituz/react-native-storage 1.0.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.
Files changed (43) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +102 -0
  3. package/lib/application/ports/IStorageRepository.d.ts +48 -0
  4. package/lib/application/ports/IStorageRepository.d.ts.map +1 -0
  5. package/lib/application/ports/IStorageRepository.js +10 -0
  6. package/lib/application/ports/IStorageRepository.js.map +1 -0
  7. package/lib/domain/entities/StorageResult.d.ts +38 -0
  8. package/lib/domain/entities/StorageResult.d.ts.map +1 -0
  9. package/lib/domain/entities/StorageResult.js +42 -0
  10. package/lib/domain/entities/StorageResult.js.map +1 -0
  11. package/lib/domain/errors/StorageError.d.ts +51 -0
  12. package/lib/domain/errors/StorageError.d.ts.map +1 -0
  13. package/lib/domain/errors/StorageError.js +69 -0
  14. package/lib/domain/errors/StorageError.js.map +1 -0
  15. package/lib/domain/value-objects/StorageKey.d.ts +43 -0
  16. package/lib/domain/value-objects/StorageKey.d.ts.map +1 -0
  17. package/lib/domain/value-objects/StorageKey.js +46 -0
  18. package/lib/domain/value-objects/StorageKey.js.map +1 -0
  19. package/lib/index.d.ts +27 -0
  20. package/lib/index.d.ts.map +1 -0
  21. package/lib/index.js +33 -0
  22. package/lib/index.js.map +1 -0
  23. package/lib/infrastructure/repositories/AsyncStorageRepository.d.ts +50 -0
  24. package/lib/infrastructure/repositories/AsyncStorageRepository.d.ts.map +1 -0
  25. package/lib/infrastructure/repositories/AsyncStorageRepository.js +137 -0
  26. package/lib/infrastructure/repositories/AsyncStorageRepository.js.map +1 -0
  27. package/lib/presentation/hooks/useStorage.d.ts +23 -0
  28. package/lib/presentation/hooks/useStorage.d.ts.map +1 -0
  29. package/lib/presentation/hooks/useStorage.js +87 -0
  30. package/lib/presentation/hooks/useStorage.js.map +1 -0
  31. package/lib/presentation/hooks/useStorageState.d.ts +21 -0
  32. package/lib/presentation/hooks/useStorageState.d.ts.map +1 -0
  33. package/lib/presentation/hooks/useStorageState.js +43 -0
  34. package/lib/presentation/hooks/useStorageState.js.map +1 -0
  35. package/package.json +55 -0
  36. package/src/application/ports/IStorageRepository.ts +56 -0
  37. package/src/domain/entities/StorageResult.ts +58 -0
  38. package/src/domain/errors/StorageError.ts +83 -0
  39. package/src/domain/value-objects/StorageKey.ts +59 -0
  40. package/src/index.ts +69 -0
  41. package/src/infrastructure/repositories/AsyncStorageRepository.ts +151 -0
  42. package/src/presentation/hooks/useStorage.ts +101 -0
  43. package/src/presentation/hooks/useStorageState.ts +55 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ümit UZ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,102 @@
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
+
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Storage Repository Interface (Port)
3
+ *
4
+ * Domain-Driven Design: Application port for storage operations
5
+ * Infrastructure layer implements this interface
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ import type { StorageResult } from '../../domain/entities/StorageResult';
10
+ /**
11
+ * Storage Repository Interface
12
+ * Defines contract for storage operations
13
+ */
14
+ export interface IStorageRepository {
15
+ /**
16
+ * Get item from storage with JSON parsing
17
+ */
18
+ getItem<T>(key: string, defaultValue: T): Promise<StorageResult<T>>;
19
+ /**
20
+ * Set item in storage with JSON serialization
21
+ */
22
+ setItem<T>(key: string, value: T): Promise<StorageResult<T>>;
23
+ /**
24
+ * Get string value (no JSON parsing)
25
+ */
26
+ getString(key: string, defaultValue: string): Promise<StorageResult<string>>;
27
+ /**
28
+ * Set string value (no JSON serialization)
29
+ */
30
+ setString(key: string, value: string): Promise<StorageResult<string>>;
31
+ /**
32
+ * Remove item from storage
33
+ */
34
+ removeItem(key: string): Promise<StorageResult<void>>;
35
+ /**
36
+ * Check if key exists in storage
37
+ */
38
+ hasItem(key: string): Promise<boolean>;
39
+ /**
40
+ * Clear all storage data
41
+ */
42
+ clearAll(): Promise<StorageResult<void>>;
43
+ /**
44
+ * Get multiple items at once
45
+ */
46
+ getMultiple(keys: string[]): Promise<StorageResult<Record<string, string | null>>>;
47
+ }
48
+ //# sourceMappingURL=IStorageRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStorageRepository.d.ts","sourceRoot":"","sources":["../../../src/application/ports/IStorageRepository.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpE;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7D;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7E;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtE;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtD;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAEzC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;CACpF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Storage Repository Interface (Port)
3
+ *
4
+ * Domain-Driven Design: Application port for storage operations
5
+ * Infrastructure layer implements this interface
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=IStorageRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStorageRepository.js","sourceRoot":"","sources":["../../../src/application/ports/IStorageRepository.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Storage Result Entity
3
+ *
4
+ * Domain-Driven Design: Entity representing storage operation result
5
+ * Functional programming pattern for error handling (Result type)
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ import type { StorageError } from '../errors/StorageError';
10
+ /**
11
+ * Storage Operation Result
12
+ * Success/Failure pattern for type-safe error handling
13
+ */
14
+ export type StorageResult<T> = {
15
+ success: true;
16
+ data: T;
17
+ } | {
18
+ success: false;
19
+ error: StorageError;
20
+ fallback?: T;
21
+ };
22
+ /**
23
+ * Create success result
24
+ */
25
+ export declare const success: <T>(data: T) => StorageResult<T>;
26
+ /**
27
+ * Create failure result
28
+ */
29
+ export declare const failure: <T>(error: StorageError, fallback?: T) => StorageResult<T>;
30
+ /**
31
+ * Unwrap result with default value
32
+ */
33
+ export declare const unwrap: <T>(result: StorageResult<T>, defaultValue: T) => T;
34
+ /**
35
+ * Map result data
36
+ */
37
+ export declare const map: <T, U>(result: StorageResult<T>, fn: (data: T) => U) => StorageResult<U>;
38
+ //# sourceMappingURL=StorageResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageResult.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/StorageResult.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IACvB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,MAAM,CAAC,KAAG,aAAa,CAAC,CAAC,CAGlD,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,YAAY,EAAE,WAAW,CAAC,KAAG,aAAa,CAAC,CAAC,CAI5E,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,QAAQ,aAAa,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,KAAG,CAKrE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EACtB,QAAQ,aAAa,CAAC,CAAC,CAAC,EACxB,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KACjB,aAAa,CAAC,CAAC,CAKjB,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Storage Result Entity
3
+ *
4
+ * Domain-Driven Design: Entity representing storage operation result
5
+ * Functional programming pattern for error handling (Result type)
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ /**
10
+ * Create success result
11
+ */
12
+ export const success = (data) => ({
13
+ success: true,
14
+ data,
15
+ });
16
+ /**
17
+ * Create failure result
18
+ */
19
+ export const failure = (error, fallback) => ({
20
+ success: false,
21
+ error,
22
+ fallback,
23
+ });
24
+ /**
25
+ * Unwrap result with default value
26
+ */
27
+ export const unwrap = (result, defaultValue) => {
28
+ if (result.success) {
29
+ return result.data;
30
+ }
31
+ return result.fallback ?? defaultValue;
32
+ };
33
+ /**
34
+ * Map result data
35
+ */
36
+ export const map = (result, fn) => {
37
+ if (result.success) {
38
+ return success(fn(result.data));
39
+ }
40
+ return result;
41
+ };
42
+ //# sourceMappingURL=StorageResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageResult.js","sourceRoot":"","sources":["../../../src/domain/entities/StorageResult.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,IAAO,EAAoB,EAAE,CAAC,CAAC;IACxD,OAAO,EAAE,IAAI;IACb,IAAI;CACL,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,KAAmB,EAAE,QAAY,EAAoB,EAAE,CAAC,CAAC;IAClF,OAAO,EAAE,KAAK;IACd,KAAK;IACL,QAAQ;CACT,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,MAAwB,EAAE,YAAe,EAAK,EAAE;IACxE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,IAAI,YAAY,CAAC;AACzC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,MAAwB,EACxB,EAAkB,EACA,EAAE;IACpB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAA0B,CAAC;AACpC,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Storage Error Types
3
+ *
4
+ * Domain-Driven Design: Domain errors for storage operations
5
+ * Typed errors for better error handling and debugging
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ /**
10
+ * Base Storage Error
11
+ */
12
+ export declare class StorageError extends Error {
13
+ readonly key?: string | undefined;
14
+ constructor(message: string, key?: string | undefined);
15
+ }
16
+ /**
17
+ * Storage Read Error
18
+ */
19
+ export declare class StorageReadError extends StorageError {
20
+ readonly cause?: unknown;
21
+ constructor(key: string, cause?: unknown);
22
+ }
23
+ /**
24
+ * Storage Write Error
25
+ */
26
+ export declare class StorageWriteError extends StorageError {
27
+ readonly cause?: unknown;
28
+ constructor(key: string, cause?: unknown);
29
+ }
30
+ /**
31
+ * Storage Delete Error
32
+ */
33
+ export declare class StorageDeleteError extends StorageError {
34
+ readonly cause?: unknown;
35
+ constructor(key: string, cause?: unknown);
36
+ }
37
+ /**
38
+ * Storage Serialization Error
39
+ */
40
+ export declare class StorageSerializationError extends StorageError {
41
+ readonly cause?: unknown;
42
+ constructor(key: string, cause?: unknown);
43
+ }
44
+ /**
45
+ * Storage Deserialization Error
46
+ */
47
+ export declare class StorageDeserializationError extends StorageError {
48
+ readonly cause?: unknown;
49
+ constructor(key: string, cause?: unknown);
50
+ }
51
+ //# sourceMappingURL=StorageError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageError.d.ts","sourceRoot":"","sources":["../../../src/domain/errors/StorageError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aACQ,GAAG,CAAC,EAAE,MAAM;gBAA7C,OAAO,EAAE,MAAM,EAAkB,GAAG,CAAC,EAAE,MAAM,YAAA;CAI1D;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKzC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKzC;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKzC;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,YAAY;IACzD,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKzC;AAED;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,YAAY;IAC3D,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKzC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Storage Error Types
3
+ *
4
+ * Domain-Driven Design: Domain errors for storage operations
5
+ * Typed errors for better error handling and debugging
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ /**
10
+ * Base Storage Error
11
+ */
12
+ export class StorageError extends Error {
13
+ constructor(message, key) {
14
+ super(message);
15
+ this.key = key;
16
+ this.name = 'StorageError';
17
+ }
18
+ }
19
+ /**
20
+ * Storage Read Error
21
+ */
22
+ export class StorageReadError extends StorageError {
23
+ constructor(key, cause) {
24
+ super(`Failed to read from storage: ${key}`, key);
25
+ this.name = 'StorageReadError';
26
+ this.cause = cause;
27
+ }
28
+ }
29
+ /**
30
+ * Storage Write Error
31
+ */
32
+ export class StorageWriteError extends StorageError {
33
+ constructor(key, cause) {
34
+ super(`Failed to write to storage: ${key}`, key);
35
+ this.name = 'StorageWriteError';
36
+ this.cause = cause;
37
+ }
38
+ }
39
+ /**
40
+ * Storage Delete Error
41
+ */
42
+ export class StorageDeleteError extends StorageError {
43
+ constructor(key, cause) {
44
+ super(`Failed to delete from storage: ${key}`, key);
45
+ this.name = 'StorageDeleteError';
46
+ this.cause = cause;
47
+ }
48
+ }
49
+ /**
50
+ * Storage Serialization Error
51
+ */
52
+ export class StorageSerializationError extends StorageError {
53
+ constructor(key, cause) {
54
+ super(`Failed to serialize data for key: ${key}`, key);
55
+ this.name = 'StorageSerializationError';
56
+ this.cause = cause;
57
+ }
58
+ }
59
+ /**
60
+ * Storage Deserialization Error
61
+ */
62
+ export class StorageDeserializationError extends StorageError {
63
+ constructor(key, cause) {
64
+ super(`Failed to deserialize data for key: ${key}`, key);
65
+ this.name = 'StorageDeserializationError';
66
+ this.cause = cause;
67
+ }
68
+ }
69
+ //# sourceMappingURL=StorageError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageError.js","sourceRoot":"","sources":["../../../src/domain/errors/StorageError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAkB,GAAY;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,QAAG,GAAH,GAAG,CAAS;QAEvD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAGhD,YAAY,GAAW,EAAE,KAAe;QACtC,KAAK,CAAC,gCAAgC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAGjD,YAAY,GAAW,EAAE,KAAe;QACtC,KAAK,CAAC,+BAA+B,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAGlD,YAAY,GAAW,EAAE,KAAe;QACtC,KAAK,CAAC,kCAAkC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,YAAY;IAGzD,YAAY,GAAW,EAAE,KAAe;QACtC,KAAK,CAAC,qCAAqC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,YAAY;IAG3D,YAAY,GAAW,EAAE,KAAe;QACtC,KAAK,CAAC,uCAAuC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Storage Key Value Object
3
+ *
4
+ * Domain-Driven Design: Value Object for storage keys
5
+ * Ensures type safety and prevents invalid key usage
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ /**
10
+ * Storage Key Type
11
+ * All valid storage keys must be defined here
12
+ */
13
+ export declare enum StorageKey {
14
+ ONBOARDING_COMPLETED = "@onboarding_completed",
15
+ LANGUAGE = "@app_language",
16
+ THEME_MODE = "@app_theme_mode",
17
+ SETTINGS = "app_settings",
18
+ QUERY_CACHE = "{{APP_NAME}}_query_cache"
19
+ }
20
+ /**
21
+ * Storage key with dynamic suffix
22
+ */
23
+ export type DynamicStorageKey = {
24
+ base: StorageKey;
25
+ suffix: string;
26
+ };
27
+ /**
28
+ * Helper to create user-specific storage key
29
+ *
30
+ * @param baseKey Base storage key
31
+ * @param userId User identifier
32
+ * @returns User-specific key
33
+ */
34
+ export declare const createUserKey: (baseKey: StorageKey, userId: string) => string;
35
+ /**
36
+ * Helper to create app-specific storage key
37
+ *
38
+ * @param baseKey Base storage key
39
+ * @param appName App identifier
40
+ * @returns App-specific key
41
+ */
42
+ export declare const createAppKey: (baseKey: StorageKey, appName: string) => string;
43
+ //# sourceMappingURL=StorageKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageKey.d.ts","sourceRoot":"","sources":["../../../src/domain/value-objects/StorageKey.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,oBAAY,UAAU;IAEpB,oBAAoB,0BAA0B;IAG9C,QAAQ,kBAAkB;IAG1B,UAAU,oBAAoB;IAG9B,QAAQ,iBAAiB;IAGzB,WAAW,6BAA6B;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,UAAU,EAAE,QAAQ,MAAM,KAAG,MAEnE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,UAAU,EAAE,SAAS,MAAM,KAAG,MAEnE,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Storage Key Value Object
3
+ *
4
+ * Domain-Driven Design: Value Object for storage keys
5
+ * Ensures type safety and prevents invalid key usage
6
+ *
7
+ * Theme: {{THEME_NAME}} ({{CATEGORY}} category)
8
+ */
9
+ /**
10
+ * Storage Key Type
11
+ * All valid storage keys must be defined here
12
+ */
13
+ export var StorageKey;
14
+ (function (StorageKey) {
15
+ // Onboarding
16
+ StorageKey["ONBOARDING_COMPLETED"] = "@onboarding_completed";
17
+ // Localization
18
+ StorageKey["LANGUAGE"] = "@app_language";
19
+ // Theme
20
+ StorageKey["THEME_MODE"] = "@app_theme_mode";
21
+ // Settings (requires userId suffix)
22
+ StorageKey["SETTINGS"] = "app_settings";
23
+ // Query Cache (requires app name prefix)
24
+ StorageKey["QUERY_CACHE"] = "{{APP_NAME}}_query_cache";
25
+ })(StorageKey || (StorageKey = {}));
26
+ /**
27
+ * Helper to create user-specific storage key
28
+ *
29
+ * @param baseKey Base storage key
30
+ * @param userId User identifier
31
+ * @returns User-specific key
32
+ */
33
+ export const createUserKey = (baseKey, userId) => {
34
+ return `${baseKey}_${userId}`;
35
+ };
36
+ /**
37
+ * Helper to create app-specific storage key
38
+ *
39
+ * @param baseKey Base storage key
40
+ * @param appName App identifier
41
+ * @returns App-specific key
42
+ */
43
+ export const createAppKey = (baseKey, appName) => {
44
+ return `${appName}_${baseKey}`;
45
+ };
46
+ //# sourceMappingURL=StorageKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageKey.js","sourceRoot":"","sources":["../../../src/domain/value-objects/StorageKey.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,UAeX;AAfD,WAAY,UAAU;IACpB,aAAa;IACb,4DAA8C,CAAA;IAE9C,eAAe;IACf,wCAA0B,CAAA;IAE1B,QAAQ;IACR,4CAA8B,CAAA;IAE9B,oCAAoC;IACpC,uCAAyB,CAAA;IAEzB,yCAAyC;IACzC,sDAAwC,CAAA;AAC1C,CAAC,EAfW,UAAU,KAAV,UAAU,QAerB;AAUD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAmB,EAAE,MAAc,EAAU,EAAE;IAC3E,OAAO,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC;AAChC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAmB,EAAE,OAAe,EAAU,EAAE;IAC3E,OAAO,GAAG,OAAO,IAAI,OAAO,EAAE,CAAC;AACjC,CAAC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Storage Domain - Public API
3
+ *
4
+ * Domain-Driven Design (DDD) Architecture
5
+ *
6
+ * This is the SINGLE SOURCE OF TRUTH for all storage operations.
7
+ * ALL imports from the storage domain MUST go through this file.
8
+ *
9
+ * Architecture:
10
+ * - domain: Entities, value objects, errors (business logic)
11
+ * - application: Ports (interfaces), use cases (not needed for simple CRUD)
12
+ * - infrastructure: Repository implementation (AsyncStorage adapter)
13
+ * - presentation: Hooks (React integration)
14
+ *
15
+ * Usage:
16
+ * import { useStorage, useStorageState, StorageKey } from '@umituz/react-native-storage';
17
+ */
18
+ export { StorageKey, createUserKey, createAppKey, } from './domain/value-objects/StorageKey';
19
+ export type { DynamicStorageKey } from './domain/value-objects/StorageKey';
20
+ export { StorageError, StorageReadError, StorageWriteError, StorageDeleteError, StorageSerializationError, StorageDeserializationError, } from './domain/errors/StorageError';
21
+ export type { StorageResult } from './domain/entities/StorageResult';
22
+ export { success, failure, unwrap, map, } from './domain/entities/StorageResult';
23
+ export type { IStorageRepository } from './application/ports/IStorageRepository';
24
+ export { AsyncStorageRepository, storageRepository, } from './infrastructure/repositories/AsyncStorageRepository';
25
+ export { useStorage } from './presentation/hooks/useStorage';
26
+ export { useStorageState } from './presentation/hooks/useStorageState';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,EACL,UAAU,EACV,aAAa,EACb,YAAY,GACb,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,GAAG,GACJ,MAAM,iCAAiC,CAAC;AAMzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAMjF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sDAAsD,CAAC;AAM9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Storage Domain - Public API
3
+ *
4
+ * Domain-Driven Design (DDD) Architecture
5
+ *
6
+ * This is the SINGLE SOURCE OF TRUTH for all storage operations.
7
+ * ALL imports from the storage domain MUST go through this file.
8
+ *
9
+ * Architecture:
10
+ * - domain: Entities, value objects, errors (business logic)
11
+ * - application: Ports (interfaces), use cases (not needed for simple CRUD)
12
+ * - infrastructure: Repository implementation (AsyncStorage adapter)
13
+ * - presentation: Hooks (React integration)
14
+ *
15
+ * Usage:
16
+ * import { useStorage, useStorageState, StorageKey } from '@umituz/react-native-storage';
17
+ */
18
+ // =============================================================================
19
+ // DOMAIN LAYER - Business Logic
20
+ // =============================================================================
21
+ export { StorageKey, createUserKey, createAppKey, } from './domain/value-objects/StorageKey';
22
+ export { StorageError, StorageReadError, StorageWriteError, StorageDeleteError, StorageSerializationError, StorageDeserializationError, } from './domain/errors/StorageError';
23
+ export { success, failure, unwrap, map, } from './domain/entities/StorageResult';
24
+ // =============================================================================
25
+ // INFRASTRUCTURE LAYER - Implementation
26
+ // =============================================================================
27
+ export { AsyncStorageRepository, storageRepository, } from './infrastructure/repositories/AsyncStorageRepository';
28
+ // =============================================================================
29
+ // PRESENTATION LAYER - Hooks
30
+ // =============================================================================
31
+ export { useStorage } from './presentation/hooks/useStorage';
32
+ export { useStorageState } from './presentation/hooks/useStorageState';
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF,OAAO,EACL,UAAU,EACV,aAAa,EACb,YAAY,GACb,MAAM,mCAAmC,CAAC;AAI3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,GAAG,GACJ,MAAM,iCAAiC,CAAC;AAQzC,gFAAgF;AAChF,wCAAwC;AACxC,gFAAgF;AAEhF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sDAAsD,CAAC;AAE9D,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * AsyncStorage Repository
3
+ *
4
+ * Domain-Driven Design: Infrastructure implementation of IStorageRepository
5
+ * Adapts React Native AsyncStorage to domain interface
6
+ */
7
+ import type { IStorageRepository } from '../../application/ports/IStorageRepository';
8
+ import type { StorageResult } from '../../domain/entities/StorageResult';
9
+ /**
10
+ * AsyncStorage Repository Implementation
11
+ */
12
+ export declare class AsyncStorageRepository implements IStorageRepository {
13
+ /**
14
+ * Get item from AsyncStorage with type safety
15
+ */
16
+ getItem<T>(key: string, defaultValue: T): Promise<StorageResult<T>>;
17
+ /**
18
+ * Set item in AsyncStorage with automatic JSON serialization
19
+ */
20
+ setItem<T>(key: string, value: T): Promise<StorageResult<T>>;
21
+ /**
22
+ * Get string value (no JSON parsing)
23
+ */
24
+ getString(key: string, defaultValue: string): Promise<StorageResult<string>>;
25
+ /**
26
+ * Set string value (no JSON serialization)
27
+ */
28
+ setString(key: string, value: string): Promise<StorageResult<string>>;
29
+ /**
30
+ * Remove item from AsyncStorage
31
+ */
32
+ removeItem(key: string): Promise<StorageResult<void>>;
33
+ /**
34
+ * Check if key exists in storage
35
+ */
36
+ hasItem(key: string): Promise<boolean>;
37
+ /**
38
+ * Clear all AsyncStorage data (use with caution!)
39
+ */
40
+ clearAll(): Promise<StorageResult<void>>;
41
+ /**
42
+ * Get multiple items at once (more efficient than multiple getItem calls)
43
+ */
44
+ getMultiple(keys: string[]): Promise<StorageResult<Record<string, string | null>>>;
45
+ }
46
+ /**
47
+ * Singleton instance
48
+ */
49
+ export declare const storageRepository: AsyncStorageRepository;
50
+ //# sourceMappingURL=AsyncStorageRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncStorageRepository.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/repositories/AsyncStorageRepository.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAUzE;;GAEG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAoBzE;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAgBlE;;OAEG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAelF;;OAEG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAS3E;;OAEG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAS3D;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAS9C;;OAEG;IACG,WAAW,CACf,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CASzD;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,wBAA+B,CAAC"}