@umituz/react-native-storage 2.6.22 → 2.6.24

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.
@@ -0,0 +1,181 @@
1
+ # Presentation Layer
2
+
3
+ React hooks and components for UI integration with storage and cache.
4
+
5
+ ## Overview
6
+
7
+ Presentation layer containing React hooks for storage and cache operations. Located at `src/presentation/`.
8
+
9
+ ## Directory Structure
10
+
11
+ - `hooks/` - React hooks for storage and cache integration
12
+
13
+ ## Strategies
14
+
15
+ ### React Integration
16
+ - Use custom hooks for storage operations
17
+ - Use custom hooks for cache operations
18
+ - Enable reactive state management
19
+ - Support automatic re-renders on state changes
20
+
21
+ ### State Management
22
+ - Use useStorageState for persistent state
23
+ - Use useCacheState for cached state
24
+ - Enable automatic sync with storage/cache
25
+ - Support default values and initialization
26
+
27
+ ### Cache Integration
28
+ - Use useCache for cache instance access
29
+ - Use useCachedValue for single value caching
30
+ - Use usePersistentCache for hybrid cache+storage
31
+ - Enable TTL-based invalidation
32
+
33
+ ### Hook Design
34
+ - Follow React hooks rules and best practices
35
+ - Enable composition and reuse
36
+ - Support dependency arrays for optimization
37
+ - Provide cleanup functions for side effects
38
+
39
+ ## Restrictions
40
+
41
+ ### Hook Usage
42
+ - DO NOT call hooks outside React components
43
+ - DO NOT call hooks conditionally or in loops
44
+ - DO NOT mutate state directly
45
+ - DO NOT ignore loading and error states
46
+
47
+ ### State Management
48
+ - DO NOT mix storage and cache state unnecessarily
49
+ - DO NOT create redundant state for same data
50
+ - DO NOT forget to handle undefined/null states
51
+ - DO NOT use stale state in closures
52
+
53
+ ### Performance
54
+ - DO NOT create new cache instances on every render
55
+ - DO NOT skip dependency arrays in useEffect
56
+ - DO NOT cause unnecessary re-renders
57
+ - DO NOT forget cleanup in useEffect
58
+
59
+ ### Error Handling
60
+ - DO NOT ignore errors from async operations
61
+ - DO NOT expose raw error objects to UI
62
+ - DO NOT retry indefinitely on failures
63
+ - DO NOT lose error context
64
+
65
+ ## Rules
66
+
67
+ ### Hook Implementation
68
+ - MUST follow React hooks rules
69
+ - MUST use useMemo for expensive computations
70
+ - MUST use useCallback for stable function references
71
+ - MUST provide cleanup functions for effects
72
+ - MUST support dependency arrays
73
+
74
+ ### Storage Hooks
75
+ - MUST provide useStorage for low-level operations
76
+ - MUST provide useStorageState for state sync
77
+ - MUST support generic type parameters
78
+ - MUST handle loading states
79
+ - MUST handle error states
80
+ - MUST return stable references
81
+
82
+ ### Cache Hooks
83
+ - MUST provide useCache for cache instance access
84
+ - MUST provide useCachedValue for value caching
85
+ - MUST provide useCacheState for state integration
86
+ - MUST support TTL configuration
87
+ - MUST support invalidation callbacks
88
+ - MUST handle cache misses gracefully
89
+
90
+ ### Persistent Cache Hooks
91
+ - MUST provide usePersistentCache for hybrid caching
92
+ - MUST support storage fallback
93
+ - MUST handle rehydration from storage
94
+ - MUST support stale-while-revalidate strategy
95
+ - MUST provide loading, error, and data states
96
+ - MUST support refresh callbacks
97
+
98
+ ### State Synchronization
99
+ - MUST sync state changes to storage/cache
100
+ - MUST re-render on state changes
101
+ - MUST provide latest state to consumers
102
+ - MUST handle race conditions properly
103
+ - MUST support optimistic updates
104
+
105
+ ### Error Handling
106
+ - MUST expose error state from hooks
107
+ - MUST enable error callbacks
108
+ - MUST not throw exceptions from hooks
109
+ - MUST preserve error context
110
+ - MUST support error recovery
111
+
112
+ ### Loading States
113
+ - MUST expose loading state from async hooks
114
+ - MUST indicate initial load vs refresh
115
+ - MUST support loading callbacks
116
+ - MUST prevent duplicate requests
117
+ - MUST handle concurrent operations
118
+
119
+ ### Type Safety
120
+ - MUST use generic type parameters
121
+ - MUST infer types from default values
122
+ - MUST provide type-safe return values
123
+ - MUST support custom type definitions
124
+ - MUST not use type assertions
125
+
126
+ ### Performance Optimization
127
+ - MUST use useMemo for cache instances
128
+ - MUST use useCallback for event handlers
129
+ - MUST provide dependency array parameters
130
+ - MUST prevent unnecessary re-renders
131
+ - MUST enable memoization where appropriate
132
+
133
+ ### Cleanup and Lifecycle
134
+ - MUST clean up subscriptions on unmount
135
+ - MUST clear temporary cache on unmount
136
+ - MUST prevent memory leaks
137
+ - MUST handle component unmount gracefully
138
+ - MUST not update state after unmount
139
+
140
+ ### Hook Naming
141
+ - MUST use 'use' prefix for all hooks
142
+ - MUST use descriptive names for functionality
143
+ - MUST follow naming conventions
144
+ - MUST be consistent with ecosystem
145
+ - MUST indicate purpose in name
146
+
147
+ ### Cache Naming
148
+ - MUST use descriptive cache names
149
+ - MUST avoid generic cache names
150
+ - MUST enable pattern matching for invalidation
151
+ - MUST follow naming conventions
152
+ - MUST prevent naming conflicts
153
+
154
+ ### Testing Support
155
+ - MUST enable hook testing with renderHook
156
+ - MUST provide cleanup for testing
157
+ - MUST support mocking dependencies
158
+ - MUST reset state between tests
159
+ - MUST not have hidden side effects
160
+
161
+ ### Export Rules
162
+ - MUST export all hooks from presentation layer
163
+ - MUST provide TypeScript types
164
+ - MUST document hook behavior
165
+ - MUST specify hook contracts
166
+ - MUST not export internal utilities
167
+
168
+ ### Documentation
169
+ - MUST document all public hooks
170
+ - MUST specify parameter types and requirements
171
+ - MUST explain return value structure
172
+ - MUST provide usage guidance
173
+ - MUST warn about common mistakes
174
+ - MUST not include code examples
175
+
176
+ ### Best Practices Compliance
177
+ - MUST follow React hooks rules
178
+ - MUST enable proper dependency tracking
179
+ - MUST support concurrent mode
180
+ - MUST be compatible with Strict Mode
181
+ - MUST not cause memory leaks
@@ -0,0 +1,128 @@
1
+ # React Hooks
2
+
3
+ Integration layer for storage and cache functionality with React components.
4
+
5
+ ## Overview
6
+
7
+ This directory contains React hooks that integrate storage and cache functionality with React components. Located at `src/presentation/hooks/`.
8
+
9
+ ## Available Hooks
10
+
11
+ | Hook | Purpose | Use Case |
12
+ |------|---------|----------|
13
+ | `useStorage` | Low-level storage operations | Manual CRUD operations |
14
+ | `useStorageState` | State with auto-persistence | Form data, user preferences |
15
+ | `useStore` | Zustand store selector | State management |
16
+ | `usePersistentCache` | API caching with persistence | Data fetching with offline support |
17
+ | `useCacheState` | In-memory cache state | Temporary state management |
18
+ | `useCache` | In-memory cache operations | Manual cache management |
19
+ | `useCachedValue` | Single value caching | Simple value caching |
20
+
21
+ ## Strategies
22
+
23
+ ### Hook Selection
24
+ - Use `useStorageState` for form inputs and settings
25
+ - Use `useStore` for Zustand integration
26
+ - Use `usePersistentCache` for API data with offline support
27
+ - Use `useCache` for complex caching patterns
28
+ - Use `useCachedValue` for simple single-value caching
29
+
30
+ ### Performance Optimization
31
+ - Use selectors with `useStore` to prevent unnecessary re-renders
32
+ - Memoize callbacks passed to cache hooks
33
+ - Avoid inline fetcher functions
34
+ - Use appropriate TTL based on data change frequency
35
+
36
+ ### Composition Patterns
37
+ - Combine multiple hooks for complex scenarios
38
+ - Use conditional fetching with enabled flag
39
+ - Implement dependent queries with proper data flow
40
+ - Share cache instances across components
41
+
42
+ ## Restrictions
43
+
44
+ ### Hook Usage
45
+ - DO NOT call hooks outside React components or custom hooks
46
+ - DO NOT call hooks conditionally or inside loops
47
+ - DO NOT use `useStorage` when `useStorageState` is sufficient
48
+ - DO NOT use inline fetcher functions (define them first)
49
+
50
+ ### State Management
51
+ - DO NOT mix storage and cache for same data
52
+ - DO NOT use `useStorageState` for large datasets (> 1MB)
53
+ - DO NOT use `useCache` when simple state would suffice
54
+ - DO NOT create new cache instances on every render
55
+
56
+ ### Performance
57
+ - DO NOT select entire store with `useStore` (use selectors)
58
+ - DO NOT recreate fetcher functions on every render
59
+ - DO NOT use very short TTLs (< 5 seconds)
60
+ - DO NOT cache large objects (> 100KB)
61
+
62
+ ### Error Handling
63
+ - DO NOT ignore error states from cache hooks
64
+ - DO NOT silently fail storage operations
65
+ - DO NOT use try-catch inside hooks (handle errors at call site)
66
+
67
+ ## Rules
68
+
69
+ ### Hook Implementation
70
+ - MUST follow React rules of hooks
71
+ - MUST provide TypeScript types for all parameters
72
+ - MUST handle loading states appropriately
73
+ - MUST provide error state for async operations
74
+
75
+ ### Storage Hooks (`useStorage`, `useStorageState`)
76
+ - MUST use unique keys for different state
77
+ - MUST specify initial value for `useStorageState`
78
+ - MUST handle storage errors gracefully
79
+ - MUST provide type parameter for type safety
80
+
81
+ ### Cache Hooks (`useCache`, `useCacheState`, `useCachedValue`)
82
+ - MUST specify cache name when using `useCache`
83
+ - MUST provide fetcher function for `useCachedValue`
84
+ - MUST set appropriate TTL for data type
85
+ - MUST handle cache misses gracefully
86
+
87
+ ### Persistent Cache (`usePersistentCache`)
88
+ - MUST provide unique key for each query
89
+ - MUST define fetcher function that returns Promise
90
+ - MUST specify TTL based on data freshness requirements
91
+ - MUST handle loading and error states
92
+ - MUST implement refresh mechanism
93
+
94
+ ### Store Hook (`useStore`)
95
+ - MUST provide selector function for partial state
96
+ - MUST use memoized selectors to prevent re-renders
97
+ - MUST select only needed state slices
98
+ - MUST avoid selecting entire store
99
+
100
+ ### Testing
101
+ - MUST test hooks with `@testing-library/react-hooks`
102
+ - MUST test loading, success, and error states
103
+ - MUST test cleanup and unmount behavior
104
+ - MUST mock storage/cache in tests
105
+
106
+ ### Error Handling
107
+ - MUST expose error state from async hooks
108
+ - MUST allow error handling at component level
109
+ - MUST log errors in development mode
110
+ - MUST provide retry mechanisms for transient failures
111
+
112
+ ### Type Safety
113
+ - MUST provide generic type parameters
114
+ - MUST enforce types for storage keys
115
+ - MUST use TypeScript strict mode
116
+ - MUST avoid `any` types in hook implementations
117
+
118
+ ### Performance
119
+ - MUST use `useCallback` for functions passed to hooks
120
+ - MUST use `useMemo` for computed values
121
+ - MUST implement proper dependency arrays
122
+ - MUST avoid unnecessary re-renders
123
+
124
+ ### Deprecation
125
+ - MUST document deprecated hooks
126
+ - MUST provide migration path for deprecated hooks
127
+ - MUST maintain backward compatibility when possible
128
+ - MUST remove deprecated hooks after major version bump
@@ -0,0 +1,103 @@
1
+ # Shared Types
2
+
3
+ TypeScript type definitions used across the storage package.
4
+
5
+ ## Overview
6
+
7
+ This directory contains shared type definitions for storage operations, Result pattern, and utility types. Located at `src/types/`.
8
+
9
+ ## Strategies
10
+
11
+ ### Type Organization
12
+ - Define StorageResult for all storage operations
13
+ - Use DynamicStorageKey for type-safe key generation
14
+ - Create utility types for common transformations
15
+ - Export types for external package use
16
+
17
+ ### Result Pattern
18
+ - Use discriminated union for success/failure states
19
+ - Include success flag for type narrowing
20
+ - Preserve error context in failure state
21
+ - Provide type guards for type safety
22
+
23
+ ### Type Safety
24
+ - Use generic type parameters for flexibility
25
+ - Provide type inference where possible
26
+ - Use branded types for distinct primitives
27
+ - Implement conditional types for complex scenarios
28
+
29
+ ### Type Guards
30
+ - Create type guards for runtime validation
31
+ - Use predicate functions for type narrowing
32
+ - Implement instanceof checks for error types
33
+ - Validate structure before type assertions
34
+
35
+ ## Restrictions
36
+
37
+ ### Type Definitions
38
+ - DO NOT use `any` type without compelling reason
39
+ - DO NOT create circular type dependencies
40
+ - DO NOT mix success/failure in same type
41
+ - DO NOT omit error context from Result types
42
+
43
+ ### Type Safety
44
+ - DO NOT use type assertions without validation
45
+ - DO NOT assume optional properties exist
46
+ - DO NOT cast values without type guards
47
+ - DO NOT disable TypeScript rules
48
+
49
+ ### Utility Types
50
+ - DO NOT create overly complex conditional types
51
+ - DO NOT use utility types where simple types suffice
52
+ - DO NOT create recursive types without clear purpose
53
+ - DO NOT mix different type utilities unnecessarily
54
+
55
+ ## Rules
56
+
57
+ ### StorageResult Type
58
+ - MUST use discriminated union with success flag
59
+ - MUST include data in success state
60
+ - MUST include error in failure state
61
+ - MUST provide type parameter for data
62
+
63
+ ### Type Guards
64
+ - MUST return boolean for type predicates
65
+ - MUST use `is` keyword for type narrowing
66
+ - MUST validate all required properties
67
+ - MUST handle edge cases (null, undefined)
68
+
69
+ ### Generic Types
70
+ - MUST provide descriptive type parameter names
71
+ - MUST constrain generics with extends where appropriate
72
+ - MUST provide default values for common cases
73
+ - MUST document generic constraints
74
+
75
+ ### Utility Types
76
+ - MUST follow TypeScript conventions
77
+ - MUST use built-in utility types when possible
78
+ - MUST document custom utility types
79
+ - MUST test utility type behavior
80
+
81
+ ### Import/Export
82
+ - MUST export types used by external packages
83
+ - MUST use `type` keyword for type-only imports
84
+ - MUST avoid value/type ambiguity
85
+ - MUST organize exports logically
86
+
87
+ ### Type Inference
88
+ - MUST enable TypeScript strict mode
89
+ - MUST provide type annotations for public APIs
90
+ - MUST let TypeScript infer where possible
91
+ - MUST use `typeof` for capturing inferred types
92
+
93
+ ### Documentation
94
+ - MUST document complex type transformations
95
+ - MUST provide examples for non-obvious types
96
+ - MUST explain generic constraints
97
+ - MUST warn about type limitations
98
+
99
+ ### Testing
100
+ - MUST test type guards with various inputs
101
+ - MUST verify utility type behavior
102
+ - MUST test conditional type branches
103
+ - MUST validate type inference results