@umituz/react-native-storage 1.3.0 → 1.5.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.3.0",
3
+ "version": "1.5.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",
@@ -34,11 +34,25 @@ export const failure = <T>(error: StorageError, fallback?: T): StorageResult<T>
34
34
  fallback,
35
35
  });
36
36
 
37
+ /**
38
+ * Type guard for success result
39
+ */
40
+ export const isSuccess = <T>(result: StorageResult<T>): result is { success: true; data: T } => {
41
+ return result.success === true;
42
+ };
43
+
44
+ /**
45
+ * Type guard for failure result
46
+ */
47
+ export const isFailure = <T>(result: StorageResult<T>): result is { success: false; error: StorageError; fallback?: T } => {
48
+ return result.success === false;
49
+ };
50
+
37
51
  /**
38
52
  * Unwrap result with default value
39
53
  */
40
54
  export const unwrap = <T>(result: StorageResult<T>, defaultValue: T): T => {
41
- if (result.success) {
55
+ if (isSuccess(result)) {
42
56
  return result.data;
43
57
  }
44
58
  return result.fallback !== undefined ? result.fallback : defaultValue;
@@ -51,7 +65,7 @@ export const map = <T, U>(
51
65
  result: StorageResult<T>,
52
66
  fn: (data: T) => U
53
67
  ): StorageResult<U> => {
54
- if (result.success) {
68
+ if (isSuccess(result)) {
55
69
  return success(fn(result.data));
56
70
  }
57
71
  return failure(result.error, result.fallback !== undefined ? fn(result.fallback) : undefined);
package/src/index.ts CHANGED
@@ -44,6 +44,8 @@ export {
44
44
  failure,
45
45
  unwrap,
46
46
  map,
47
+ isSuccess,
48
+ isFailure,
47
49
  } from './domain/entities/StorageResult';
48
50
 
49
51
  // =============================================================================