@umituz/react-native-storage 2.6.4 → 2.6.6

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.6.4",
3
+ "version": "2.6.6",
4
4
  "description": "Unified storage solution with AsyncStorage persistence, Zustand state management, and in-memory caching for React Native",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -1,23 +1,10 @@
1
1
  /**
2
2
  * Store Factory
3
3
  * Create Zustand stores with AsyncStorage persistence and actions
4
- *
5
- * @example
6
- * ```typescript
7
- * const useCounterStore = createStore({
8
- * name: 'counter',
9
- * initialState: { count: 0 },
10
- * actions: (set, get) => ({
11
- * increment: () => set({ count: get().count + 1 }),
12
- * reset: () => set({ count: 0 }),
13
- * }),
14
- * persist: true,
15
- * });
16
- * ```
17
4
  */
18
5
 
19
- import { create } from 'zustand';
20
- import { persist, createJSONStorage } from 'zustand/middleware';
6
+ import { create, type StateCreator } from 'zustand';
7
+ import { persist, createJSONStorage, type PersistOptions } from 'zustand/middleware';
21
8
  import type { StoreConfig } from '../types/Store';
22
9
  import { storageService } from '../../infrastructure/adapters/StorageService';
23
10
 
@@ -30,42 +17,43 @@ export function createStore<
30
17
  >(config: StoreConfig<TState, TActions>) {
31
18
  type Store = TState & TActions;
32
19
 
33
- const stateCreator = (
34
- set: (partial: Partial<Store>) => void,
35
- get: () => Store
36
- ): Store => {
37
- const state = config.initialState as Store;
38
- const actions = config.actions ? config.actions(set as any, get as any) : ({} as TActions);
39
- return { ...state, ...actions };
20
+ const stateCreator: StateCreator<Store> = (set, get) => {
21
+ const state = config.initialState as TState;
22
+ const actions = config.actions
23
+ ? config.actions(
24
+ (partial: Partial<TState>) => set(partial as Partial<Store>),
25
+ get as () => TState
26
+ )
27
+ : ({} as TActions);
28
+ return { ...state, ...actions } as Store;
40
29
  };
41
30
 
42
31
  if (!config.persist) {
43
32
  return create<Store>(stateCreator);
44
33
  }
45
34
 
46
- return create<Store>()(
47
- persist(stateCreator, {
48
- name: config.name,
49
- storage: createJSONStorage(() => storageService),
50
- version: config.version || 1,
51
- partialize: config.partialize
52
- ? (state) => config.partialize!(state) as Store
53
- : (state) => {
54
- // By default, exclude functions (actions) from persistence
55
- const persisted: Record<string, unknown> = {};
56
- for (const key of Object.keys(state)) {
57
- if (typeof state[key as keyof Store] !== 'function') {
58
- persisted[key] = state[key as keyof Store];
59
- }
35
+ const persistOptions: PersistOptions<Store, Partial<Store>> = {
36
+ name: config.name,
37
+ storage: createJSONStorage(() => storageService),
38
+ version: config.version || 1,
39
+ partialize: config.partialize
40
+ ? (state) => config.partialize!(state as TState) as Partial<Store>
41
+ : (state) => {
42
+ const persisted: Record<string, unknown> = {};
43
+ for (const key of Object.keys(state)) {
44
+ if (typeof state[key as keyof Store] !== 'function') {
45
+ persisted[key] = state[key as keyof Store];
60
46
  }
61
- return persisted as Store;
62
- },
63
- onRehydrateStorage: () => (state) => {
64
- if (state && config.onRehydrate) {
65
- config.onRehydrate(state);
66
- }
67
- },
68
- migrate: config.migrate as any,
69
- })
70
- );
47
+ }
48
+ return persisted as Partial<Store>;
49
+ },
50
+ onRehydrateStorage: () => (state) => {
51
+ if (state && config.onRehydrate) {
52
+ config.onRehydrate(state as TState);
53
+ }
54
+ },
55
+ migrate: config.migrate as PersistOptions<Store, Partial<Store>>['migrate'],
56
+ };
57
+
58
+ return create<Store>()(persist(stateCreator, persistOptions));
71
59
  }
package/src/index.ts CHANGED
@@ -102,6 +102,13 @@ export type {
102
102
 
103
103
  export { createStore } from './domain/factories/StoreFactory';
104
104
 
105
+ // =============================================================================
106
+ // ZUSTAND - Type Re-exports for Compatibility
107
+ // =============================================================================
108
+
109
+ export type { StoreApi, UseBoundStore } from 'zustand';
110
+ export type { StateCreator, StoreMutatorIdentifier } from 'zustand/vanilla';
111
+
105
112
  // =============================================================================
106
113
  // APPLICATION LAYER - Ports
107
114
  // =============================================================================