@storesjs/stores 0.9.0 → 0.11.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 (139) hide show
  1. package/README.md +55 -29
  2. package/dist/createBaseStore.d.ts +8 -8
  3. package/dist/createDerivedStore.d.ts +9 -17
  4. package/dist/createQueryStore.d.ts +11 -16
  5. package/dist/createVirtualStore.d.ts +1 -2
  6. package/dist/env.native.d.ts +0 -2
  7. package/dist/env.web.d.ts +0 -1
  8. package/dist/hooks/useListen.d.ts +2 -2
  9. package/dist/index.d.ts +1 -16
  10. package/dist/index.shared.d.ts +14 -0
  11. package/dist/index.vanilla.d.ts +2 -0
  12. package/dist/internal/baseStore.d.ts +2 -0
  13. package/dist/{config.d.ts → internal/config.d.ts} +5 -11
  14. package/dist/{utils → internal}/createStoreActions.d.ts +4 -5
  15. package/dist/{derivedStore → internal/derivedStore}/deriveProxy.d.ts +2 -2
  16. package/dist/{derivedStore → internal/derivedStore}/pathFinder.d.ts +1 -2
  17. package/dist/internal/derivedStore.d.ts +2 -0
  18. package/dist/{errors.d.ts → internal/errors.d.ts} +0 -4
  19. package/dist/{logger.d.ts → internal/logger.d.ts} +0 -2
  20. package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
  21. package/dist/internal/queryStore/queryParams.d.ts +18 -0
  22. package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
  23. package/dist/internal/queryStore.d.ts +2 -0
  24. package/dist/internal/runtime.d.ts +12 -0
  25. package/dist/internal/storage/storageCreators.d.ts +12 -0
  26. package/dist/{utils → internal}/storeUtils.d.ts +3 -21
  27. package/dist/internal/sync/browserSyncEngine.d.ts +3 -0
  28. package/dist/internal/sync/noopSyncEngine.d.ts +3 -0
  29. package/dist/internal/sync/syncEnhancer.d.ts +26 -0
  30. package/dist/{sync → internal/sync}/syncUtils.d.ts +1 -1
  31. package/dist/internal/types/internalSubscribeTypes.d.ts +16 -0
  32. package/dist/internal/utils/persistUtils.d.ts +9 -0
  33. package/dist/internal/virtualStore.d.ts +2 -0
  34. package/dist/native/index.js +1 -1
  35. package/dist/native/index.mjs +1 -1
  36. package/dist/queryStore/classes/SubscriptionManager.d.ts +3 -31
  37. package/dist/queryStore/queryKey.d.ts +10 -0
  38. package/dist/queryStore/queryParam.d.ts +37 -0
  39. package/dist/queryStore/types.d.ts +12 -53
  40. package/dist/store/attachStoreHook.react.d.ts +5 -0
  41. package/dist/store/attachStoreHook.vanilla.d.ts +6 -0
  42. package/dist/store/batchStoreNotifications.native.d.ts +3 -0
  43. package/dist/store/batchStoreNotifications.web.d.ts +2 -0
  44. package/dist/store/cascadeScheduler.d.ts +38 -0
  45. package/dist/store/createStore.d.ts +6 -0
  46. package/dist/store/persist.d.ts +14 -0
  47. package/dist/store/stateUpdate.d.ts +10 -0
  48. package/dist/store/types.d.ts +108 -0
  49. package/dist/types/setState.d.ts +22 -0
  50. package/dist/types/subscribe.d.ts +27 -0
  51. package/dist/types/useStoreCallSignatures.d.ts +2 -0
  52. package/dist/types/useStoreCallSignatures.react.d.ts +6 -0
  53. package/dist/types/useStoreCallSignatures.vanilla.d.ts +2 -0
  54. package/dist/types/utils.d.ts +4 -0
  55. package/dist/types.d.ts +46 -94
  56. package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
  57. package/dist/utils/time.d.ts +0 -7
  58. package/dist/vanilla/createBaseStore.d.ts +35 -0
  59. package/dist/vanilla/createDerivedStore.d.ts +62 -0
  60. package/dist/vanilla/createQueryStore.d.ts +110 -0
  61. package/dist/vanilla/createVirtualStore.d.ts +39 -0
  62. package/dist/vanilla/env.web.d.ts +6 -0
  63. package/dist/vanilla/index.d.ts +1 -0
  64. package/dist/vanilla/index.js +1 -0
  65. package/dist/vanilla/index.mjs +1 -0
  66. package/dist/vanilla/index.shared.d.ts +13 -0
  67. package/dist/vanilla/index.vanilla.d.ts +1 -0
  68. package/dist/vanilla/internal/baseStore.d.ts +1 -0
  69. package/dist/vanilla/internal/config.d.ts +63 -0
  70. package/dist/vanilla/internal/createStoreActions.d.ts +23 -0
  71. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +14 -0
  72. package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +25 -0
  73. package/dist/vanilla/internal/derivedStore.d.ts +1 -0
  74. package/dist/vanilla/internal/errors.d.ts +9 -0
  75. package/dist/vanilla/internal/logger.d.ts +9 -0
  76. package/dist/{middleware → vanilla/internal/middleware}/createHydrationGate.d.ts +1 -2
  77. package/dist/vanilla/internal/queryStore/queryParams.d.ts +17 -0
  78. package/dist/{queryStore → vanilla/internal/queryStore}/queryStoreDefaults.d.ts +1 -2
  79. package/dist/vanilla/internal/queryStore.d.ts +1 -0
  80. package/dist/vanilla/internal/runtime.d.ts +11 -0
  81. package/dist/vanilla/internal/storage/storageCreators.d.ts +11 -0
  82. package/dist/vanilla/internal/storeUtils.d.ts +45 -0
  83. package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +2 -0
  84. package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +2 -0
  85. package/dist/{sync → vanilla/internal/sync}/syncEnhancer.d.ts +2 -3
  86. package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
  87. package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +1 -2
  88. package/dist/vanilla/internal/virtualStore.d.ts +1 -0
  89. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +38 -0
  90. package/dist/vanilla/queryStore/queryKey.d.ts +9 -0
  91. package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
  92. package/dist/vanilla/queryStore/types.d.ts +360 -0
  93. package/dist/vanilla/storage/storageTypes.d.ts +12 -0
  94. package/dist/vanilla/store/attachStoreHook.d.ts +5 -0
  95. package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +5 -0
  96. package/dist/vanilla/store/batchStoreNotifications.web.d.ts +1 -0
  97. package/dist/{derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
  98. package/dist/vanilla/store/createStore.d.ts +5 -0
  99. package/dist/vanilla/store/persist.d.ts +13 -0
  100. package/dist/vanilla/store/stateUpdate.d.ts +9 -0
  101. package/dist/vanilla/store/types.d.ts +107 -0
  102. package/dist/vanilla/storesStorage.web.d.ts +2 -0
  103. package/dist/vanilla/sync/types.d.ts +114 -0
  104. package/dist/vanilla/types/functions.d.ts +23 -0
  105. package/dist/vanilla/types/objects.d.ts +10 -0
  106. package/dist/vanilla/types/setState.d.ts +21 -0
  107. package/dist/vanilla/types/subscribe.d.ts +26 -0
  108. package/dist/vanilla/types/useStoreCallSignatures.d.ts +1 -0
  109. package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +1 -0
  110. package/dist/vanilla/types/utils.d.ts +12 -0
  111. package/dist/vanilla/types.d.ts +287 -0
  112. package/dist/vanilla/utils/core.d.ts +25 -0
  113. package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +34 -0
  114. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +28 -0
  115. package/dist/vanilla/utils/debounce.d.ts +21 -0
  116. package/dist/vanilla/utils/equality.d.ts +37 -0
  117. package/dist/vanilla/utils/hydrationCoordinator.d.ts +12 -0
  118. package/dist/vanilla/utils/promiseUtils.d.ts +1 -0
  119. package/dist/vanilla/utils/serialization.d.ts +13 -0
  120. package/dist/vanilla/utils/stringUtils.d.ts +6 -0
  121. package/dist/vanilla/utils/time.d.ts +36 -0
  122. package/dist/web/chrome.js +1 -1
  123. package/dist/web/chrome.mjs +1 -1
  124. package/dist/web/chunk-FENSEQ3V.mjs +1 -0
  125. package/dist/web/chunk-FPYZVFBM.mjs +1 -0
  126. package/dist/web/chunk-PLDNKWGX.mjs +1 -0
  127. package/dist/web/index.js +1 -1
  128. package/dist/web/index.mjs +1 -1
  129. package/dist/web/internal/runtime.js +1 -0
  130. package/dist/web/internal/runtime.mjs +1 -0
  131. package/package.json +13 -11
  132. package/dist/createStoreWithEqualityFn.d.ts +0 -5
  133. package/dist/hooks/compareHooks.d.ts +0 -50
  134. package/dist/queryStore/signalTypes.d.ts +0 -13
  135. package/dist/signal.d.ts +0 -11
  136. package/dist/storage/storageCreators.d.ts +0 -22
  137. package/dist/sync/browserSyncEngine.d.ts +0 -3
  138. package/dist/sync/noopSyncEngine.d.ts +0 -3
  139. package/dist/web/chunk-3U5A7HQV.mjs +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stores
2
2
 
3
- Stores provides a minimal, reactive state layer built on top of Zustand.
3
+ Stores provides a minimal, reactive state layer that runs with or without React.
4
4
 
5
5
  It defines three types of runtime-evaluated stores—**base**, **derived**, and **query**—each representing a distinct state type: local, computed, or asynchronously fetched. Stores track dependencies at runtime, evaluate lazily, and clean up automatically when unused.
6
6
 
@@ -10,10 +10,32 @@ All stores expose a consistent interface and can be used both inside and outside
10
10
  - **Derived stores** compute values from other stores and re-run only when inputs change.
11
11
  - **Query stores** fetch and cache async data, refetching when reactive parameters change.
12
12
 
13
- All store types share a common interface: a React-compatible hook, a
14
- stable store object with `.getState()` and `.subscribe()`, and optional
15
- support for persistence. They compose naturally, interoperate cleanly,
16
- and scale as application complexity grows.
13
+ All store types expose a stable store object with `.getState()` and
14
+ `.subscribe()`, plus optional support for persistence. In the React build,
15
+ stores are also callable hooks. In the vanilla build, stores remain plain store
16
+ objects. They compose naturally, interoperate cleanly, and scale as application
17
+ complexity grows.
18
+
19
+ ## Runtime Modes
20
+
21
+ The root import is mode-aware:
22
+
23
+ - React web apps use `@storesjs/stores` by default.
24
+ - React Native apps use `@storesjs/stores`; the `react-native` package condition selects the native build.
25
+ - Vanilla apps use `@storesjs/stores` with the `vanilla` package condition enabled.
26
+
27
+ For TypeScript vanilla projects, use a condition-aware resolver and add the
28
+ same condition to `tsconfig.json`:
29
+
30
+ ```json
31
+ {
32
+ "compilerOptions": {
33
+ "module": "ESNext",
34
+ "moduleResolution": "bundler",
35
+ "customConditions": ["vanilla"]
36
+ }
37
+ }
38
+ ```
17
39
 
18
40
  ## Base Store
19
41
 
@@ -21,7 +43,7 @@ A base store defines local state along with an interface for reading and
21
43
  updating that state.
22
44
 
23
45
  ```ts
24
- export const useSettingsStore = createBaseStore<Settings>(set => ({
46
+ export const settingsStore = createBaseStore<Settings>(set => ({
25
47
  currency: 'USD',
26
48
  setCurrency: currency => set({ currency }),
27
49
  }));
@@ -30,14 +52,14 @@ export const useSettingsStore = createBaseStore<Settings>(set => ({
30
52
  In React, subscribe to values with selectors:
31
53
 
32
54
  ```ts
33
- const currency = useSettingsStore(s => s.currency);
55
+ const currency = settingsStore(s => s.currency);
34
56
  ```
35
57
 
36
58
  Outside React:
37
59
 
38
60
  ```ts
39
- useSettingsStore.getState().currency;
40
- useSettingsStore.subscribe(selector, listener, options);
61
+ settingsStore.getState().currency;
62
+ settingsStore.subscribe(selector, listener, options);
41
63
  ```
42
64
 
43
65
  Enable persistence per store:
@@ -52,7 +74,7 @@ createBaseStore<Settings>(set => ({ ... }), {
52
74
  You can also export actions as a stable object:
53
75
 
54
76
  ```ts
55
- export const settingsActions = createStoreActions(useSettingsStore);
77
+ export const settingsActions = createStoreActions(settingsStore);
56
78
  ```
57
79
 
58
80
  ## Derived Store
@@ -61,9 +83,9 @@ Derived stores compute values from other stores. The `$` accessor tracks
61
83
  dependencies at runtime:
62
84
 
63
85
  ```ts
64
- export const useTotal = createDerivedStore($ => {
65
- const { currency } = $(useSettingsStore);
66
- const { subtotal, tax } = $(useCartStore);
86
+ export const totalStore = createDerivedStore($ => {
87
+ const { currency } = $(settingsStore);
88
+ const { subtotal, tax } = $(cartStore);
67
89
  return formatTotal(currency, subtotal, tax);
68
90
  });
69
91
  ```
@@ -78,10 +100,10 @@ Query stores manage remote data. They fetch, cache, and revalidate based
78
100
  on reactive parameters:
79
101
 
80
102
  ```ts
81
- export const useAccountStore = createQueryStore<Account, Params>({
103
+ export const accountStore = createQueryStore<Account, Params>({
82
104
  fetcher: fetchAccount,
83
105
  params: {
84
- userId: $ => $(useAuthStore).userId,
106
+ userId: $ => $(authStore).userId,
85
107
  },
86
108
  staleTime: time.minutes(10),
87
109
  });
@@ -93,13 +115,13 @@ idle.
93
115
  Use it in React:
94
116
 
95
117
  ```ts
96
- const account = useAccountStore(s => s.getData());
118
+ const account = accountStore(s => s.getData());
97
119
  ```
98
120
 
99
121
  Or imperatively:
100
122
 
101
123
  ```ts
102
- useAccountStore.getState().fetch();
124
+ accountStore.getState().fetch();
103
125
  ```
104
126
 
105
127
  Query stores support full customization: extended local state, manual cache control, configurable staleness and retry behavior, and optional persistence.
@@ -108,22 +130,26 @@ They deduplicate fetches across consumers and compute stable query keys automati
108
130
 
109
131
  ## Store Interface
110
132
 
111
- All stores implement the same API:
133
+ All stores implement the same store-object API:
112
134
 
113
135
  ```ts
114
- useStore()
115
- useStore(selector, equalityFn?)
136
+ store.getState()
137
+ store.setState() // Except for derived stores
138
+ store.subscribe(selector, listener, options?)
139
+ ```
116
140
 
117
- useStore.getState()
118
- useStore.setState() // Except for derived stores
119
- useStore.subscribe(selector, listener, options?)
141
+ In the React build, stores are also callable hooks:
142
+
143
+ ```ts
144
+ store()
145
+ store(selector, equalityFn?)
120
146
  ```
121
147
 
122
148
  ## Composed Example
123
149
 
124
150
  ```ts
125
- export const useCurrencyFormatter = createDerivedStore($ => {
126
- const { currency, locale } = $(useSettingsStore);
151
+ export const currencyFormatterStore = createDerivedStore($ => {
152
+ const { currency, locale } = $(settingsStore);
127
153
  return new Intl.NumberFormat(locale, {
128
154
  currency,
129
155
  style: 'currency',
@@ -132,16 +158,16 @@ export const useCurrencyFormatter = createDerivedStore($ => {
132
158
  ```
133
159
 
134
160
  ```ts
135
- export const useAccountBalance = createDerivedStore($ => {
136
- const balance = $(useAccountStore).getData()?.balance ?? 0;
137
- const formatter = $(useCurrencyFormatter);
161
+ export const accountBalanceStore = createDerivedStore($ => {
162
+ const balance = $(accountStore).getData()?.balance ?? 0;
163
+ const formatter = $(currencyFormatterStore);
138
164
  return formatter.format(balance);
139
165
  });
140
166
  ```
141
167
 
142
168
  ```ts
143
169
  function AccountSummary() {
144
- const balance = useAccountBalance();
170
+ const balance = accountBalanceStore();
145
171
  return <Text>Balance: {balance}</Text>;
146
172
  }
147
173
  ```
@@ -1,36 +1,36 @@
1
- import { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
1
+ import type { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
2
2
  /**
3
3
  * Creates a base store without persistence.
4
4
  * @param createState - The state creator function for the base store.
5
- * @returns A Zustand store with the specified state.
5
+ * @returns A store with the specified state.
6
6
  */
7
7
  export declare function createBaseStore<S>(createState: StateCreator<S>): Store<S>;
8
8
  /**
9
9
  * Creates a base store with persistence.
10
10
  * @param createState - The state creator function for the base store.
11
11
  * @param options - The configuration options for persistence and sync.
12
- * @returns A Zustand store with the specified state and persistence.
12
+ * @returns A store with the specified state and persistence.
13
13
  */
14
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
14
+ export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
15
15
  /**
16
16
  * Creates a base store with async persistence.
17
17
  * @param createState - The state creator function for the base store.
18
18
  * @param options - The configuration options for persistence and sync.
19
- * @returns A Zustand store with the specified state and persistence.
19
+ * @returns A store with the specified state and persistence.
20
20
  */
21
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
21
+ export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
22
22
  /**
23
23
  * Creates a base store with optional persistence.
24
24
  * @param createState - The state creator function for the base store.
25
25
  * @param options - The configuration options for persistence and sync.
26
- * @returns A Zustand store with the specified state and optional persistence.
26
+ * @returns A store with the specified state and optional persistence.
27
27
  */
28
28
  export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
29
29
  /**
30
30
  * Creates a base store with optional async persistence.
31
31
  * @param createState - The state creator function for the base store.
32
32
  * @param options - The configuration options for persistence and sync.
33
- * @returns A Zustand store with the specified state and optional persistence.
33
+ * @returns A store with the specified state and optional persistence.
34
34
  */
35
35
  export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
36
36
  //# sourceMappingURL=createBaseStore.d.ts.map
@@ -1,8 +1,8 @@
1
- import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreState } from './types';
1
+ import type { DeriveGetter, DeriveOptions, DerivedStore } from './types';
2
2
  /**
3
3
  * ### `createDerivedStore`
4
4
  *
5
- * Creates a **read-only** store derived from one or more underlying Zustand stores.
5
+ * Creates a **read-only** store derived from one or more source stores.
6
6
  *
7
7
  * ---
8
8
  * The `deriveFunction` is called whenever its dependencies change, producing a new derived state.
@@ -28,10 +28,10 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
28
28
  *
29
29
  * ---
30
30
  * Derived stores automatically unsubscribe from all dependencies when no consumers remain, and
31
- * resubscribe when new consumers appear. The returned function doubles as:
31
+ * resubscribe when new consumers appear. The returned store exposes:
32
32
  *
33
- * - A **React hook** (`const state = useDerivedStore(selector, equalityFn?)`)
34
33
  * - A **store object** with `getState()`, `subscribe()`, and `destroy()`
34
+ * - In the React build, a **React hook** (`const state = derivedStore(selector, equalityFn?)`)
35
35
  *
36
36
  * ---
37
37
  * You can optionally pass a second parameter (either an equality function or a config object)
@@ -44,28 +44,20 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
44
44
  * @example
45
45
  * ```ts
46
46
  * // Create a derived store
47
- * const useSearchResults = createDerivedStore($ => {
48
- * const query = $(useSearchStore).query.trim().toLowerCase();
49
- * const items = $(useItemsStore).items;
47
+ * const searchResultsStore = createDerivedStore($ => {
48
+ * const query = $(searchStore).query.trim().toLowerCase();
49
+ * const items = $(itemsStore).items;
50
50
  * return findResults(query, items);
51
51
  * }, shallowEqual);
52
52
  *
53
- * function SearchResults() {
54
- * // Consume the derived state
55
- * const results = useSearchResults(); // Or (selector, equalityFn?)
56
- * return <ResultsList items={results} />;
57
- * }
53
+ * const results = searchResultsStore.getState();
58
54
  * ```
59
55
  *
60
56
  * ---
61
57
  * @param deriveFunction - Function that reads from other stores via `$` to produce derived state.
62
58
  * @param optionsOrEqualityFn - Either an equality function or a config object (see `DeriveOptions`).
63
59
  *
64
- * @returns A read-only derived store (usable as a hook or standard store object).
60
+ * @returns A read-only derived store. In the React build, it is also callable as a hook.
65
61
  */
66
62
  export declare function createDerivedStore<Derived>(deriveFunction: ($: DeriveGetter) => Derived, optionsOrEqualityFn?: DeriveOptions<Derived>): DerivedStore<Derived>;
67
- export type DeriveGetter = {
68
- <S extends Store<unknown>>(store: S): InferStoreState<S>;
69
- <S extends Store<unknown>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
70
- };
71
63
  //# sourceMappingURL=createDerivedStore.d.ts.map
@@ -1,6 +1,10 @@
1
- export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
2
- import { QueryStoreConfig, QueryStoreState } from './queryStore/types';
3
- import { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
1
+ import { defaultRetryDelay } from './internal/runtime';
2
+ import type { QueryStoreConfig, QueryStoreState } from './queryStore/types';
3
+ import type { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
4
+ export { defaultRetryDelay };
5
+ export { getQueryKey, parseQueryKey } from './queryStore/queryKey';
6
+ export { queryParam } from './queryStore/queryParam';
7
+ export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryStore/queryParam';
4
8
  /**
5
9
  * Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
6
10
  *
@@ -9,7 +13,7 @@ import { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreato
9
13
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
10
14
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
11
15
  */
12
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn, false>;
16
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
13
17
  /**
14
18
  * Creates a persisted, query-enabled store with data fetching capabilities (async storage).
15
19
  *
@@ -18,7 +22,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
18
22
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
19
23
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
20
24
  */
21
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn, false>;
25
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
22
26
  /**
23
27
  * Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
24
28
  *
@@ -28,7 +32,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
28
32
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
29
33
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
30
34
  */
31
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn, false>;
35
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
32
36
  /**
33
37
  * Creates a persisted, query-enabled store with data fetching capabilities (async storage).
34
38
  *
@@ -38,7 +42,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
38
42
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
39
43
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
40
44
  */
41
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn, false>;
45
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
42
46
  /**
43
47
  * Creates a query-enabled store with data fetching capabilities.
44
48
  *
@@ -104,13 +108,4 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
104
108
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
105
109
  */
106
110
  export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
107
- /**
108
- * Generates a deterministic query store `queryKey` from the given parameters,
109
- * consistent with internally generated keys.
110
- */
111
- export declare function getQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
112
- /**
113
- * Parses a query store `queryKey` into the corresponding parameters.
114
- */
115
- export declare function parseQueryKey<TParams extends Record<string, unknown>>(queryKey: string): TParams;
116
111
  //# sourceMappingURL=createQueryStore.d.ts.map
@@ -1,5 +1,4 @@
1
- import { DeriveGetter } from './createDerivedStore';
2
- import { BaseStore, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
1
+ import type { BaseStore, DeriveGetter, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
3
2
  type MethodOverrides<Store extends BaseStore<unknown>> = Partial<Pick<Store, 'getState' | 'setState'>>;
4
3
  type VirtualStore<Store extends BaseStore<unknown>> = OptionallyPersistedStore<InferStoreState<Store>, InferPersistedState<Store>, InferSetStateReturn<Store>>;
5
4
  type VirtualStoreOptions = {
@@ -1,9 +1,7 @@
1
- import { unstable_batchedUpdates } from 'react-native';
2
1
  export declare const IS_REACT_NATIVE = true;
3
2
  export declare const IS_BROWSER = false;
4
3
  export declare const IS_IOS: boolean;
5
4
  export declare const IS_ANDROID: boolean;
6
5
  export declare const IS_DEV: boolean;
7
6
  export declare const IS_TEST: boolean;
8
- export { unstable_batchedUpdates };
9
7
  //# sourceMappingURL=env.native.d.ts.map
package/dist/env.web.d.ts CHANGED
@@ -4,5 +4,4 @@ export declare const IS_IOS = false;
4
4
  export declare const IS_ANDROID = false;
5
5
  export declare const IS_DEV: boolean;
6
6
  export declare const IS_TEST: boolean;
7
- export declare const unstable_batchedUpdates: <T>(callback: () => T) => T;
8
7
  //# sourceMappingURL=env.web.d.ts.map
@@ -61,7 +61,7 @@ export type UseListenOptions<Selected> = {
61
61
  /**
62
62
  * ### `useListen`
63
63
  *
64
- * Subscribes to a slice of a Zustand store and runs a callback whenever that slice changes,
64
+ * Subscribes to a slice of a store and runs a callback whenever that slice changes,
65
65
  * **without triggering re-renders**.
66
66
  *
67
67
  * Useful for forwarding updates to non-React state (e.g. Reanimated shared values), scoped side
@@ -75,7 +75,7 @@ export type UseListenOptions<Selected> = {
75
75
  * They take effect only if a resubscription occurs.
76
76
  *
77
77
  * ---
78
- * @param store - Zustand store to listen to. Should be a stable reference.
78
+ * @param store - Store to listen to. Should be a stable reference.
79
79
  * @param selector - Selects the slice of the store state to listen to.
80
80
  * @param react - Triggered when the selected slice changes. Receives `(current, previous, unsubscribe)`.
81
81
  * @param optionsOrEqualityFn - Optional `equalityFn`, `fireImmediately` settings, forwarded to `store.subscribe`.
package/dist/index.d.ts CHANGED
@@ -1,19 +1,4 @@
1
- export { configureStores } from './config';
2
- export { createBaseStore } from './createBaseStore';
3
- export * from './createDerivedStore';
4
- export * from './createQueryStore';
5
- export * from './createVirtualStore';
6
- export { StoresError } from './errors';
7
- export { replacer, reviver } from './utils/serialization';
8
- export { applyStateUpdate, destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './utils/storeUtils';
1
+ export * from './index.shared';
9
2
  export * from './hooks/useListen';
10
3
  export * from './hooks/useStableValue';
11
- export * from './sync/types';
12
- export * from './queryStore/types';
13
- export * from './storage/storageTypes';
14
- export * from './types';
15
- export { identity, nullObject } from './utils/core';
16
- export * from './utils/createStoreActions';
17
- export { deepEqual, shallowEqual } from './utils/equality';
18
- export { time } from './utils/time';
19
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,14 @@
1
+ export * from './createBaseStore';
2
+ export * from './createDerivedStore';
3
+ export * from './createQueryStore';
4
+ export * from './createVirtualStore';
5
+ export { configureStores, StoresError } from './internal/runtime';
6
+ export { applyStateUpdate, replacer, reviver } from './internal/runtime';
7
+ export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './internal/runtime';
8
+ export type * from './sync/types';
9
+ export { QueryStatuses } from './internal/runtime';
10
+ export type * from './queryStore/types';
11
+ export type * from './storage/storageTypes';
12
+ export type * from './types';
13
+ export { createStoreActions, deepEqual, identity, nullObject, shallowEqual, time } from './internal/runtime';
14
+ //# sourceMappingURL=index.shared.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './index.shared';
2
+ //# sourceMappingURL=index.vanilla.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=baseStore.d.ts.map
@@ -1,9 +1,9 @@
1
+ import { QueryStoreConfig } from '../queryStore/types';
2
+ import { SyncEngine } from '../sync/types';
3
+ import { AsyncStorageInterface, SyncStorageInterface } from '../types';
4
+ import { NonFunction } from '../types/functions';
5
+ import { Prettify } from '../types/objects';
1
6
  import { Logger } from './logger';
2
- import { QueryStoreConfig } from './queryStore/types';
3
- import { SyncEngine } from './sync/types';
4
- import { AsyncStorageInterface, SyncStorageInterface } from './types';
5
- import { NonFunction } from './types/functions';
6
- import { Prettify } from './types/objects';
7
7
  /**
8
8
  * Global configuration for all stores.
9
9
  */
@@ -44,9 +44,6 @@ export type QueryStoreDefaults = Prettify<ConfigDefaults<QueryStoreConfig<unknow
44
44
  type ConfigDefaults<C, Excluded extends keyof C = never, AllowedFunctions extends keyof C = never> = Omit<{
45
45
  [K in keyof C as K extends AllowedFunctions ? K : NonFunction<C[K]> extends undefined ? never : K]?: K extends AllowedFunctions ? C[K] : NonFunction<C[K]>;
46
46
  }, Excluded>;
47
- type Options = Pick<StoresConfig, 'queryStoreDefaults'>;
48
- type StorageConfig = Pick<StoresConfig, 'storage' | 'syncEngine'>;
49
- export declare const DEFAULT_STORAGE_KEY_PREFIX = "stores:";
50
47
  /**
51
48
  * Configures global defaults for all stores.
52
49
  *
@@ -63,8 +60,5 @@ export declare const DEFAULT_STORAGE_KEY_PREFIX = "stores:";
63
60
  * ```
64
61
  */
65
62
  export declare function configureStores(config: Partial<StoresConfig>): void;
66
- export declare function getOptions(): Options | undefined;
67
- export declare function getStorageConfig(): StorageConfig;
68
- export declare function markStoreCreated(): void;
69
63
  export {};
70
64
  //# sourceMappingURL=config.d.ts.map
@@ -1,8 +1,7 @@
1
- import { StoreApi } from 'zustand';
2
- import { InferStoreState } from '../types';
3
- import { NoOverlap } from '../types/objects';
4
- import { FunctionKeys, FunctionRecord } from '../types/functions';
5
- export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState<Store>, FunctionKeys<InferStoreState<Store>>>;
1
+ import type { StoreApi } from '../store/types';
2
+ import type { InferStoreState, StoreActions } from '../types';
3
+ import type { FunctionRecord } from '../types/functions';
4
+ import type { NoOverlap } from '../types/objects';
6
5
  /**
7
6
  * Given a store instance, produces a new object containing only its actions.
8
7
  *
@@ -1,11 +1,11 @@
1
- import { BaseStore } from '../types';
1
+ import type { StoreApi } from '../../store/types';
2
2
  import { TrackPathFn } from './pathFinder';
3
3
  /**
4
4
  * Gets or creates a lightweight tracking proxy that records path access and store
5
5
  * method invocations via proxy traps. Used to auto-generate selectors that point
6
6
  * to either the accessed path or the value returned by an invoked store method.
7
7
  */
8
- export declare function getOrCreateProxy<S>(store: BaseStore<S>, rootProxyCache: WeakMap<BaseStore<unknown>, unknown>, trackPath: TrackPathFn): S;
8
+ export declare function getOrCreateProxy<S>(store: StoreApi<S>, rootProxyCache: WeakMap<object, unknown>, trackPath: TrackPathFn): S;
9
9
  /**
10
10
  * Strips tracking proxies from published values to ensure
11
11
  * proxies remain confined to internal tracking contexts.
@@ -1,7 +1,6 @@
1
- import { Selector, SubscribableStore } from '../types';
1
+ import { Selector, SubscribableStore } from '../../types';
2
2
  type TrackedInvocation = {
3
3
  args: unknown[] | undefined;
4
- method: string;
5
4
  };
6
5
  type PathEntry = {
7
6
  path: string[];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=derivedStore.d.ts.map
@@ -7,8 +7,4 @@ export declare class StoresError extends Error {
7
7
  cause?: unknown;
8
8
  constructor(message: string, cause?: unknown);
9
9
  }
10
- /**
11
- * Normalizes unknown thrown values for store state and promise rejection paths.
12
- */
13
- export declare function ensureError(error: unknown): Error;
14
10
  //# sourceMappingURL=errors.d.ts.map
@@ -7,6 +7,4 @@ export interface Logger {
7
7
  info: (message: string, context?: Record<string, unknown>) => void;
8
8
  warn: (message: string, context?: Record<string, unknown>) => void;
9
9
  }
10
- export declare let logger: Logger;
11
- export declare function setLogger(customLogger: Logger): void;
12
10
  //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { StateCreator } from '../../types';
2
+ import { SyncContext } from '../sync/syncEnhancer';
3
+ type WrappedOnRehydrateStorage<S> = (userCallback: ((state: S) => ((finalState?: S, error?: unknown) => void) | void) | undefined, syncContext: SyncContext | undefined) => (state: S) => (finalState?: S, error?: unknown) => void;
4
+ /**
5
+ * Creates hydration-gating middleware that queues state updates until rehydration completes.
6
+ *
7
+ * **Before hydration**: Queues all `set()` calls and flushes them sequentially after rehydration.
8
+ *
9
+ * **After hydration**: Passes `set()` calls through synchronously without batching.
10
+ *
11
+ * This ensures persistence sees a fully rehydrated base state before applying queued updates,
12
+ * while keeping in-memory state changes synchronous post-hydration.
13
+ */
14
+ export declare function createHydrationGate<S>(stateCreator: StateCreator<S>): {
15
+ hydrationPromise: () => Promise<void>;
16
+ stateCreator: StateCreator<S>;
17
+ wrapOnRehydrateStorage: WrappedOnRehydrateStorage<S>;
18
+ };
19
+ export {};
20
+ //# sourceMappingURL=createHydrationGate.d.ts.map
@@ -0,0 +1,18 @@
1
+ import type { QueryParam, ReactiveParam } from '../../queryStore/queryParam';
2
+ import type { StoreApi } from '../../store/types';
3
+ import type { InternalUnsubscribeFn } from '../types/internalSubscribeTypes';
4
+ export type TrackedValue<T> = {
5
+ readonly initialValue: T;
6
+ subscribe(listener: (value: T) => void): InternalUnsubscribeFn;
7
+ };
8
+ export type QueryParams<TParams extends Record<string, unknown>> = {
9
+ buildKey(params?: TParams): string;
10
+ complete(params: Partial<TParams> | undefined): TParams;
11
+ get(): TParams;
12
+ subscribe(onChange: (key: keyof TParams, oldValue: unknown, newValue: unknown) => void): InternalUnsubscribeFn;
13
+ };
14
+ export declare function createQueryParams<TParams extends Record<string, unknown>, State>(params: {
15
+ [K in keyof TParams]: QueryParam<TParams[K], State>;
16
+ } | undefined, store: StoreApi<State>, requiredKeys: (keyof TParams)[]): QueryParams<TParams>;
17
+ export declare function trackQueryValue<T, State>(getValue: ReactiveParam<T, State>, ownerStore: StoreApi<State>): TrackedValue<T>;
18
+ //# sourceMappingURL=queryParams.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { Prettify } from '../../types/objects';
2
+ import { QueryStoreDefaults } from '../config';
3
+ export declare function getQueryStoreDefaults(): Prettify<Required<QueryStoreDefaults>>;
4
+ /**
5
+ * Exponential backoff: starts at `baseDelay` (5s), doubles each retry, capped at `maxDelay` (5m).
6
+ */
7
+ export declare function defaultRetryDelay(retryCount: number): number;
8
+ //# sourceMappingURL=queryStoreDefaults.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queryStore.d.ts.map
@@ -0,0 +1,12 @@
1
+ export { configureStores } from './config';
2
+ export { StoresError } from './errors';
3
+ export { QueryStatuses } from '../queryStore/types';
4
+ export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
5
+ export { applyStateUpdate } from '../store/stateUpdate';
6
+ export { replacer, reviver } from '../utils/serialization';
7
+ export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './storeUtils';
8
+ export { identity, nullObject } from '../utils/core';
9
+ export { createStoreActions } from './createStoreActions';
10
+ export { deepEqual, shallowEqual } from '../utils/equality';
11
+ export { time } from '../utils/time';
12
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { AsyncPersistStorage, PersistStorageConfig } from '../../store/types';
2
+ import type { AsyncStorageInterface, BaseStoreOptions, EnforceStorageKey, SyncStorageInterface } from '../../types';
3
+ import type { SyncContext } from '../sync/syncEnhancer';
4
+ /**
5
+ * Creates a persist storage object for the base store.
6
+ */
7
+ export declare function createPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, storage: AsyncStorageInterface | SyncStorageInterface | undefined, syncContext: SyncContext | undefined): PersistStorageConfig<S, PersistedState>;
8
+ /**
9
+ * Creates an asynchronous persist storage adapter.
10
+ */
11
+ export declare function createAsyncPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(storage: AsyncStorageInterface, options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, persistThrottleMs: number | undefined, syncContext?: SyncContext): AsyncPersistStorage<S, PersistedState>;
12
+ //# sourceMappingURL=storageCreators.d.ts.map